Class: Encosion::Video
Constant Summary collapse
- ENUMS =
{ :economics => { :free => 'FREE', :ad_supported => 'AD_SUPPORTED'}}
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#creation_date ⇒ Object
readonly
Returns the value of attribute creation_date.
-
#economics ⇒ Object
Returns the value of attribute economics.
-
#file ⇒ Object
Returns the value of attribute file.
-
#flv_url ⇒ Object
readonly
Returns the value of attribute flv_url.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_modified_date ⇒ Object
readonly
Returns the value of attribute last_modified_date.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#link_text ⇒ Object
Returns the value of attribute link_text.
-
#link_url ⇒ Object
Returns the value of attribute link_url.
-
#long_description ⇒ Object
Returns the value of attribute long_description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#plays_total ⇒ Object
readonly
Returns the value of attribute plays_total.
-
#plays_trailing_week ⇒ Object
readonly
Returns the value of attribute plays_trailing_week.
-
#published_date ⇒ Object
readonly
Returns the value of attribute published_date.
-
#reference_id ⇒ Object
Returns the value of attribute reference_id.
-
#short_description ⇒ Object
Returns the value of attribute short_description.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#thumbnail_url ⇒ Object
readonly
Returns the value of attribute thumbnail_url.
-
#video_still_url ⇒ Object
readonly
Returns the value of attribute video_still_url.
Attributes inherited from Base
Class Method Summary collapse
-
.find_by_reference_id(*args) ⇒ Object
Find a video by reference_id.
-
.find_by_tags(*args) ⇒ Object
Find a video by tag search.
-
.find_by_text(*args) ⇒ Object
Find a video by text search.
-
.find_related(*args) ⇒ Object
Find videos related to the given video_id.
-
.read(method, options) ⇒ Object
the actual method that calls a get (user can use this directly if they want to call a method that’s not included here).
-
.status(*args) ⇒ Object
Returns the status of a video upload (returns one of :uploading | :processing | :complete | :error ) Takes either Brightcove’s video_id or your own reference_id.
-
.write(method, options) ⇒ Object
the actual method that calls a post (user can use this directly if they want to call a method that’s not included here).
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Video
constructor
Instance methods.
-
#save(args = {}) ⇒ Object
Saves a video to Brightcove.
-
#to_brightcove ⇒ Object
Outputs the video object into Brightcove’s expected format.
-
#to_json ⇒ Object
Output the video as JSON.
Methods inherited from Base
all, error_check, find, get, post
Constructor Details
#initialize(args = {}) ⇒ Video
Instance methods
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/encosion/video.rb', line 216 def initialize(args={}) @id = args[:id] @name = args[:name] @short_description = args[:short_description] @long_description = args[:long_description] @creation_date = args[:creation_date] @published_date = args[:published_date] @last_modified_date = args[:last_modified_date] @link_url = args[:link_url] @link_text = args[:link_text] @tags = args[:tags] @video_still_url = args[:video_still_url] @thumbnail_url = args[:thumbnail_url] @reference_id = args[:reference_id] @length = args[:length] @economics = self.economics = args[:economics] @plays_total = args[:plays_total] @plays_trailing_week = args[:plays_trailing_week] @file = args[:file] end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def account_id @account_id end |
#creation_date ⇒ Object (readonly)
Returns the value of attribute creation_date.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def creation_date @creation_date end |
#economics ⇒ Object
Returns the value of attribute economics.
10 11 12 |
# File 'lib/encosion/video.rb', line 10 def economics @economics end |
#file ⇒ Object
Returns the value of attribute file.
10 11 12 |
# File 'lib/encosion/video.rb', line 10 def file @file end |
#flv_url ⇒ Object (readonly)
Returns the value of attribute flv_url.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def flv_url @flv_url end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def id @id end |
#last_modified_date ⇒ Object (readonly)
Returns the value of attribute last_modified_date.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def last_modified_date @last_modified_date end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def length @length end |
#link_text ⇒ Object
Returns the value of attribute link_text.
10 11 12 |
# File 'lib/encosion/video.rb', line 10 def link_text @link_text end |
#link_url ⇒ Object
Returns the value of attribute link_url.
10 11 12 |
# File 'lib/encosion/video.rb', line 10 def link_url @link_url end |
#long_description ⇒ Object
Returns the value of attribute long_description.
10 11 12 |
# File 'lib/encosion/video.rb', line 10 def long_description @long_description end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/encosion/video.rb', line 10 def name @name end |
#plays_total ⇒ Object (readonly)
Returns the value of attribute plays_total.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def plays_total @plays_total end |
#plays_trailing_week ⇒ Object (readonly)
Returns the value of attribute plays_trailing_week.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def plays_trailing_week @plays_trailing_week end |
#published_date ⇒ Object (readonly)
Returns the value of attribute published_date.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def published_date @published_date end |
#reference_id ⇒ Object
Returns the value of attribute reference_id.
10 11 12 |
# File 'lib/encosion/video.rb', line 10 def reference_id @reference_id end |
#short_description ⇒ Object
Returns the value of attribute short_description.
10 11 12 |
# File 'lib/encosion/video.rb', line 10 def short_description @short_description end |
#tags ⇒ Object
Returns the value of attribute tags.
10 11 12 |
# File 'lib/encosion/video.rb', line 10 def @tags end |
#thumbnail_url ⇒ Object (readonly)
Returns the value of attribute thumbnail_url.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def thumbnail_url @thumbnail_url end |
#video_still_url ⇒ Object (readonly)
Returns the value of attribute video_still_url.
19 20 21 |
# File 'lib/encosion/video.rb', line 19 def video_still_url @video_still_url end |
Class Method Details
.find_by_reference_id(*args) ⇒ Object
Find a video by reference_id. Invokes Brightcove Media API command ‘find_video_by_reference_id’ or ‘find_videos_by_reference_ids’ depending on whether you call one or multiple ids
Encosion::Video.find_by_reference_id('mycompany_1')
Encosion::Video.find_by_reference_id('mycompany_1','mycompany_2','mycompany_3')
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/encosion/video.rb', line 41 def find_by_reference_id(*args) = (args) ids = args.flatten.compact.uniq case ids.size when 0 raise AssetNotFound, "Couldn't find #{self.class} without a reference ID" when 1 .merge!({:reference_id => ids.first}) response = read('find_video_by_reference_id',) return self.parse(response) else .merge!({:reference_ids => ids.join(',')}) response = read('find_videos_by_reference_ids',) return response['items'].collect { |item| self.parse(item) } end end |
.find_by_tags(*args) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/encosion/video.rb', line 92 def (*args) = (args) = args.flatten.compact.uniq case .size when 0 raise AssetNotFound, "Couldn't find #{self.class} without tags" else .merge!({:and_tags => .join(',')}) if response = read('find_videos_by_tags',) return response['items'].collect { |item| self.parse(item) } else return nil end end end |
.find_by_text(*args) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/encosion/video.rb', line 62 def find_by_text(*args) = (args) text = args.flatten.compact.uniq raise AssetNotFound, "Couldn't find #{self.class} without text" if text == '' .merge!({:text => text.first}) if response = read('find_videos_by_text',) return response['items'].collect { |item| self.parse(item) } else nil end end |
.find_related(*args) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/encosion/video.rb', line 78 def (*args) = (args) raise AssetNotFound, "Cannot find related #{self.class}s without a video_id or reference_id" if [:video_id].nil? && [:reference_id].nil? if response = read('find_related_videos',) return response['items'].collect { |item| self.parse(item) } else return nil end end |
.read(method, options) ⇒ Object
the actual method that calls a get (user can use this directly if they want to call a method that’s not included here)
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/encosion/video.rb', line 134 def read(method,) # options.merge!(Encosion.options) .merge!({:token => Encosion.[:read_token]}) unless [:token] get( Encosion.[:server], Encosion.[:port], Encosion.[:secure], Encosion.[:read_path], Encosion.[:read_timeout], method, ) end |
.status(*args) ⇒ Object
Returns the status of a video upload (returns one of :uploading | :processing | :complete | :error ) Takes either Brightcove’s video_id or your own reference_id. If you pass an integer it’s assumed to be a video_id, if you pass a string it’s assumed to be a reference_id.
Encosion::Video.status(12345)
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/encosion/video.rb', line 115 def status(*args) = (args) id = args.flatten.compact.uniq.first if id.class == String .merge!({:reference_id => id}) else .merge!({:video_id => id}) end if response = write('get_upload_status',) return response['result'].downcase.to_sym else return nil end end |
.write(method, options) ⇒ Object
the actual method that calls a post (user can use this directly if they want to call a method that’s not included here)
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/encosion/video.rb', line 148 def write(method,) # options.merge!(Encosion.options) .merge!({:token => Encosion.[:write_token]}) unless [:token] Video.post( Encosion.[:server], Encosion.[:port], Encosion.[:secure], Encosion.[:write_path], Encosion.[:send_timeout], method, , self) end |
Instance Method Details
#save(args = {}) ⇒ Object
Saves a video to Brightcove. Returns the Brightcove ID for the video that was just uploaded.
new_video = Encosion::Video.new(:file => File.new('/path/to/file'), :name => "My Awesome Video", :short_description => "A video of some awesome happenings", :tags => ['awesome','sweet'])
brightcove_id = new_video.save(:token => '123abc')
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/encosion/video.rb', line 242 def save(args={}) # check to make sure we have everything needed for a create_video call raise NoFile, "You need to attach a file to this video before you can upload it: Video.file = File.new('/path/to/file')" if @file.nil? = args.merge({ 'video' => self.to_brightcove }) # take the parameters of this video and make them a valid video object for upload .merge!({:token => Encosion.[:write_token]}) unless [:token] response = Video.post(Encosion.[:server], Encosion.[:port], Encosion.[:secure], Encosion.[:write_path], Encosion.[:send_timeout], 'create_video', , self) return response['result'] # returns the Brightcove ID of the video that was just uploaded end |
#to_brightcove ⇒ Object
Outputs the video object into Brightcove’s expected format
282 283 284 285 286 287 288 289 290 291 |
# File 'lib/encosion/video.rb', line 282 def to_brightcove { 'name' => @name, 'shortDescription' => @short_description, 'longDescription' => @long_description, 'linkURL' => @link_url, 'linkText' => @link_text, 'tags' => @tags, 'referenceId' => @reference_id, 'economics' => ENUMS[:economics][@economics] } end |
#to_json ⇒ Object
Output the video as JSON
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/encosion/video.rb', line 260 def to_json { :id => @id, :name => @name, :short_description => @short_description, :long_description => @long_description, :creation_date => @creation_date, :published_date => @published_date, :last_modified_date => @last_modified_date, :link_url => @link_url, :link_text => @link_text, :tags => @tags, :video_still_url => @video_still_url, :thumbnail_url => @thumbnail_url, :reference_id => @reference_id, :length => @length, :economics => @economics, :plays_total => @plays_total, :plays_trailing_week => @plays_trailing_week }.to_json end |