Class: Encosion::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/encosion/image.rb

Constant Summary collapse

ENUMS =
{ :image_type => { :thumbnail => "THUMBNAIL", :video_still => "VIDEO_STILL"}}

Instance Attribute Summary collapse

Attributes inherited from Base

#read_token, #write_token

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/encosion/image.rb', line 6

def name
  @name
end

#reference_idObject

Returns the value of attribute reference_id.



6
7
8
# File 'lib/encosion/image.rb', line 6

def reference_id
  @reference_id
end

#remote_urlObject

Returns the value of attribute remote_url.



6
7
8
# File 'lib/encosion/image.rb', line 6

def remote_url
  @remote_url
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/encosion/image.rb', line 6

def type
  @type
end

#video_idObject

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)
  # options.merge!(Encosion.options)
  options.merge!({:token => Encosion.options[:write_token]}) unless options[:token]

  Image.post( Encosion.options[:server],
              Encosion.options[:port],
              Encosion.options[:secure],
              Encosion.options[:write_path],
              method,
              options,
              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?
  options = 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
  options.merge!({:token => Encosion.options[:write_token]}) unless options[:token]
  response = Image.post(Encosion.options[:server],
                        Encosion.options[:port],
                        Encosion.options[:secure],
                        Encosion.options[:write_path],
                        'add_image',
                        options,
                        self)
  return response['result'] # returns the Brightcove ID of the video that was just uploaded
end

#to_brightcoveObject

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_jsonObject

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