Class: Mira::ViddlerClient
- Inherits:
-
Object
- Object
- Mira::ViddlerClient
- Defined in:
- lib/mira/upload.rb
Instance Method Summary collapse
- #auth ⇒ Object
- #get(api_method, params = {}) ⇒ Object
-
#initialize(credentials) ⇒ ViddlerClient
constructor
A new instance of ViddlerClient.
-
#upload(file, params = {}) ⇒ Object
Upload a video to the Viddler API.
- #upload_params(file, params = {}) ⇒ Object
Constructor Details
#initialize(credentials) ⇒ ViddlerClient
Returns a new instance of ViddlerClient.
58 59 60 61 62 |
# File 'lib/mira/upload.rb', line 58 def initialize(credentials) @username = credentials[:username] @password = credentials[:password] @api_key = credentials[:api_key] end |
Instance Method Details
#auth ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/mira/upload.rb', line 48 def auth return @session_id if @session_id session_request = RestClient.get('http://api.viddler.com/api/v2/viddler.users.auth.json', :params => {:user => @username, :password => @password, :api_key => @api_key}) @session_id = JSON.parse(session_request)["auth"]["sessionid"] end |
#get(api_method, params = {}) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/mira/upload.rb', line 40 def get(api_method, params = {}) url = 'http://api.viddler.com/api/v2/' + api_method + '.json' JSON.parse RestClient.get(url, :params => params.merge!(:sessionid => auth, :method => api_method, :api_key => @api_key)) end |
#upload(file, params = {}) ⇒ Object
Upload a video to the Viddler API.
file - The File you are uploading arguments - The Hash of arguments for the video :title - The String title of the video :tags - The String of tags for the video :description - The String description of the video :make_public - The Boolean to make the video public on upload. Please note that if set to false, it will not make your video private.
Examples
viddler.upload File.open('myvideo.avi'), :title => "My Video",
:tags => "viddler, ruby",
:description => "This is cool"
Returns a Hash containing the API response.
30 31 32 33 34 35 36 37 38 |
# File 'lib/mira/upload.rb', line 30 def upload(file, params = {}) json = self.get('viddler.videos.prepareUpload') endpoint = json["upload"]["endpoint"] token = json["upload"]["token"] uploaded = RestClient.post(endpoint, upload_params(file, params.merge!(:token => token))) JSON.parse uploaded end |
#upload_params(file, params = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mira/upload.rb', line 64 def upload_params(file, params = {}) raise "file argument must be a File" unless file.is_a? File ordered_arguments = ActiveSupport::OrderedHash.new params.each {|k,v| ordered_arguments[k] = v} ordered_arguments[:api_key] = @api_key ordered_arguments[:sessionid] = auth ordered_arguments[:file] = file ordered_arguments end |