Class: Encosion::Image
Constant Summary collapse
- ENUMS =
{ :image_type => { :thumbnail => "THUMBNAIL", :video_still => "VIDEO_STILL"}}
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#reference_id ⇒ Object
Returns the value of attribute reference_id.
-
#remote_url ⇒ Object
Returns the value of attribute remote_url.
-
#type ⇒ Object
Returns the value of attribute type.
-
#video_id ⇒ Object
Returns the value of attribute video_id.
Attributes inherited from Base
Class Method Summary collapse
-
.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 = {}) ⇒ Image
constructor
Instance methods.
-
#save(args = {}) ⇒ Object
Saves an image to Brightcove.
-
#to_brightcove ⇒ Object
Outputs the image object into Brightcove’s expected format.
-
#to_json ⇒ Object
Output the image as JSON.
Methods inherited from Base
all, error_check, find, get, post
Constructor Details
#initialize(args = {}) ⇒ Image
Instance methods
38 39 40 41 42 43 44 |
# File 'lib/encosion/image.rb', line 38 def initialize(args={}) @video_id = args[:video_id] @name = args[:name] @reference_id = args[:reference_id] @remote_url = args[:remote_url] @type = args[:type] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/encosion/image.rb', line 6 def name @name end |
#reference_id ⇒ Object
Returns the value of attribute reference_id.
6 7 8 |
# File 'lib/encosion/image.rb', line 6 def reference_id @reference_id end |
#remote_url ⇒ Object
Returns the value of attribute remote_url.
6 7 8 |
# File 'lib/encosion/image.rb', line 6 def remote_url @remote_url end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/encosion/image.rb', line 6 def type @type end |
#video_id ⇒ Object
Returns the value of attribute video_id.
6 7 8 |
# File 'lib/encosion/image.rb', line 6 def video_id @video_id end |
Class Method Details
.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)
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/encosion/image.rb', line 20 def write(method, ) # options.merge!(Encosion.options) .merge!({:token => Encosion.[:write_token]}) unless [:token] Image.post( Encosion.[:server], Encosion.[:port], Encosion.[:secure], Encosion.[:write_path], method, , self) end |
Instance Method Details
#save(args = {}) ⇒ Object
Saves an image to Brightcove. Returns the Brightcove ID for the image that was just uploaded.
new_image = Encosion::Image.new(:remote_file => "http://example.com/image.jpg", :display_name => "My Awesome Image", :type => "VIDEO_STILL", :video_id = > "brightcove_video_id")
brightcove_id = new_image.save(:token => '123abc')
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/encosion/image.rb', line 51 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({ 'image' => self.to_brightcove, :video_id => self.video_id }) # take the parameters of this video and make them a valid video object for upload .merge!({:token => Encosion.[:write_token]}) unless [:token] response = Image.post(Encosion.[:server], Encosion.[:port], Encosion.[:secure], Encosion.[:write_path], 'add_image', , self) return response['result'] # returns the Brightcove ID of the video that was just uploaded end |
#to_brightcove ⇒ Object
Outputs the image object into Brightcove’s expected format
79 80 81 82 83 84 85 86 |
# File 'lib/encosion/image.rb', line 79 def to_brightcove { 'displayName' => @name, 'remoteUrl' => @remote_url, 'type' => ENUMS[:image_type][@type], 'referenceId' => @reference_id } end |
#to_json ⇒ Object
Output the image as JSON
68 69 70 71 72 73 74 75 |
# File 'lib/encosion/image.rb', line 68 def to_json { :name => @name, :remote_url => @remote_url, :type => ENUMS[:image_type][@type], :reference_id => @reference_id }.to_json end |