Class: BlipTV::Base
- Inherits:
-
Object
- Object
- BlipTV::Base
- Defined in:
- lib/bliptv/base.rb
Overview
This is the class that should be instantiated for basic communication with the Blip.tv API
Instance Method Summary collapse
-
#find_all_videos_by_user(username, options = {}) ⇒ Object
Looks up all videos on Blip.tv with a given
username
. -
#initialize ⇒ Base
constructor
TODO allow user to specify userlogin and password on intialize.
-
#search_videos(search_string) ⇒ Object
Searches through and returns videos based on the
search_string
. -
#upload_video(new_attributes = {}) ⇒ Object
Implements the Blip.tv REST Upload API.
Constructor Details
#initialize ⇒ Base
TODO allow user to specify userlogin and password on intialize
27 28 |
# File 'lib/bliptv/base.rb', line 27 def initialize end |
Instance Method Details
#find_all_videos_by_user(username, options = {}) ⇒ Object
Looks up all videos on Blip.tv with a given username
Options hash could contain next values:
-
page
: The “page number” of results to retrieve (e.g. 1, 2, 3); if not specified, the default value equals 1. -
pagelen
: The number of results to retrieve per page (maximum 100). If not specified, the default value equals 20.
Example:
bliptv.find_all_videos_by_user("username")
or
bliptv.find_all_videos_by_user("username", {:page => 1, :pagelen => 20})
Returns array of BlipTV::Video objects.
88 89 90 91 92 93 94 |
# File 'lib/bliptv/base.rb', line 88 def find_all_videos_by_user(username, ={}) [:page] ||= 1; [:pagelen] ||= 20 url, path = "#{username}.blip.tv", "/posts/?skin=api&page=#{[:page]}&pagelen=#{[:pagelen]}" request = Net::HTTP.get(url, path) hash = Hash.from_xml(request) hash == nil ? [] : parse_videos_list(hash) end |
#search_videos(search_string) ⇒ Object
Searches through and returns videos based on the search_string
.
This method is a direct call of Blip.tv’s search method. You get what you get. No guarantees are made.
Example:
bliptv.search_videos("cool stuff")
Returns an array of BlipTV::Video objects
107 108 109 110 111 |
# File 'lib/bliptv/base.rb', line 107 def search_videos(search_string) request = Net::HTTP.get(URI.parse("http://www.blip.tv/search/?search=#{search_string}&skin=api")) hash = Hash.from_xml(request) parse_videos_list(hash) end |
#upload_video(new_attributes = {}) ⇒ Object
Implements the Blip.tv REST Upload API
new_attributes
hash should contain next required keys:
-
title:
The video title; -
file:
The video file;
and optionally:
-
thumbnail:
A thumbnail file; -
nsfw:
true if explicit, false otherwise. Defaults to false; -
description:
A description of the video -
username:
Username -
password:
Password -
keywords:
A comma-separated string of keywords # TODO this should be nice and also accept Arrays -
categories:
A Hash of categories -
license:
A license for the video -
interactive_post:
Specify whether or not a post is interactive. More here
Example:
bliptv.upload_video(:title => 'Check out this guy getting kicked in the nuts!', :file => File.open('/movies/nuts.mov'))
Returns BlipTV::Video instance.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bliptv/base.rb', line 53 def upload_video(new_attributes={}) BlipTV::ApiSpec.check_attributes('videos.upload', new_attributes) new_attributes = { :post => "1", :item_type => "file", :skin => "xmlhttprequest", :file_role => "Web" }.merge(new_attributes) # blip.tv requires the "post" param to be set to 1 request = BlipTV::Request.new(:post, 'videos.upload') request.run do |p| for param, value in new_attributes p.send("#{param}=", value) end end BlipTV::Video.new(request.response['post_url'].to_s) end |