Class: Vimeo::Easy
- Inherits:
-
Object
- Object
- Vimeo::Easy
- Defined in:
- lib/easy-vimeo.rb
Constant Summary collapse
- UPLOAD_URL =
"http://vimeo.com/services/upload"
- PRIVACY_MODES =
[:anybody, :contacts, :nobody, :users]
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#description ⇒ Object
Returns the value of attribute description.
-
#file ⇒ Object
Returns the value of attribute file.
-
#privacy ⇒ Object
Returns the value of attribute privacy.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#thumbnail ⇒ Object
readonly
Returns the value of attribute thumbnail.
-
#title ⇒ Object
Returns the value of attribute title.
-
#video_id ⇒ Object
Returns the value of attribute video_id.
-
#vimeo_upload ⇒ Object
Returns the value of attribute vimeo_upload.
-
#vimeo_video ⇒ Object
Returns the value of attribute vimeo_video.
Class Method Summary collapse
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#destroy ⇒ Object
This method destroys the Vimeo Video.
-
#initialize(options = {}) ⇒ Easy
constructor
This method initializes a new instance.
- #new_record? ⇒ Boolean
- #reload ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Easy
This method initializes a new instance. You should pass an options Hash containing : :api_key # The API key of your account :secret_key # The secret key :auth_token # (optional) The authorization token, needed to upload a video :video_id # (optional) The ID of the video, if it is already uploaded
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/easy-vimeo.rb', line 23 def initialize( = {}) raise "You must pass :api_key and :secret_key at least to initialize the class." unless [:api_key] && [:secret_key] self.api_key = [:api_key] self.auth_token = [:auth_token] self.video_id = [:video_id] self.vimeo_upload = Vimeo::Advanced::Upload.new(self.api_key, [:secret_key]) self.vimeo_video = Vimeo::Advanced::Video.new(self.api_key, [:secret_key]) self.privacy = :anybody @new_record = true if self.video_id self.reload end end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
13 14 15 |
# File 'lib/easy-vimeo.rb', line 13 def api_key @api_key end |
#auth_token ⇒ Object
Returns the value of attribute auth_token.
13 14 15 |
# File 'lib/easy-vimeo.rb', line 13 def auth_token @auth_token end |
#description ⇒ Object
Returns the value of attribute description.
13 14 15 |
# File 'lib/easy-vimeo.rb', line 13 def description @description end |
#file ⇒ Object
Returns the value of attribute file.
13 14 15 |
# File 'lib/easy-vimeo.rb', line 13 def file @file end |
#privacy ⇒ Object
Returns the value of attribute privacy.
14 15 16 |
# File 'lib/easy-vimeo.rb', line 14 def privacy @privacy end |
#tags ⇒ Object
Returns the value of attribute tags.
14 15 16 |
# File 'lib/easy-vimeo.rb', line 14 def @tags end |
#thumbnail ⇒ Object
Returns the value of attribute thumbnail.
14 15 16 |
# File 'lib/easy-vimeo.rb', line 14 def thumbnail @thumbnail end |
#title ⇒ Object
Returns the value of attribute title.
13 14 15 |
# File 'lib/easy-vimeo.rb', line 13 def title @title end |
#video_id ⇒ Object
Returns the value of attribute video_id.
13 14 15 |
# File 'lib/easy-vimeo.rb', line 13 def video_id @video_id end |
#vimeo_upload ⇒ Object
Returns the value of attribute vimeo_upload.
13 14 15 |
# File 'lib/easy-vimeo.rb', line 13 def vimeo_upload @vimeo_upload end |
#vimeo_video ⇒ Object
Returns the value of attribute vimeo_video.
13 14 15 |
# File 'lib/easy-vimeo.rb', line 13 def vimeo_video @vimeo_video end |
Class Method Details
.find(video_id, options = {}) ⇒ Object
38 39 40 |
# File 'lib/easy-vimeo.rb', line 38 def self.find(video_id, = {}) self.new(.merge(:video_id => video_id)) end |
Instance Method Details
#available? ⇒ Boolean
67 68 69 |
# File 'lib/easy-vimeo.rb', line 67 def available? !!@availability end |
#destroy ⇒ Object
This method destroys the Vimeo Video
58 59 60 61 62 63 64 65 |
# File 'lib/easy-vimeo.rb', line 58 def destroy check_presence_of :video_id, :auth_token self.vimeo_video.delete(self.auth_token, self.video_id) true rescue false end |
#new_record? ⇒ Boolean
42 43 44 |
# File 'lib/easy-vimeo.rb', line 42 def new_record? @new_record end |
#reload ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/easy-vimeo.rb', line 71 def reload check_presence_of :video_id begin video_response = self.vimeo_video.get_info(self.video_id)['video'][0] self.title = video_response['title'] self.description = video_response['description'] self.privacy = video_response['privacy'].to_sym self.thumbnail = (video_response['thumbnails']['thumbnail'].first rescue nil) @tags = (video_response['tags']['tag'].join(', ') rescue nil) @availability = video_response['is_transcoding'].to_i.zero? && video_response['is_uploading'].to_i.zero? @new_record = false true rescue false end end |
#save ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/easy-vimeo.rb', line 90 def save if self.file raise "Cannot upload a video file on an existing video! Create a new instance instead." unless new_record? post_video! end check_presence_of :video_id, :auth_token begin self.vimeo_video.set_privacy(self.auth_token, self.video_id, self.privacy.to_s) self.vimeo_video.set_description(self.auth_token, self.video_id, self.description) if self.description self.vimeo_video.set_title(self.auth_token, self.video_id, self.title) if self.title if @new_tags self.vimeo_video.(self.auth_token, self.video_id) self.vimeo_video.(self.auth_token, self.video_id, self.) @new_tags = nil end rescue return false end @new_record = false @file = nil true end |