Class: MoovAtom::MoovEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/moovatom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vattrs = {}, pattrs = {}) {|_self| ... } ⇒ MoovEngine

The initializer populates the class’ instance variables to hold all the specifics about the video you’re accessing or starting to encode, as well as the player control attributes.

There are three ways to instantiate a new MoovEngine object:

  1. Create a blank object and set each variable using ‘dot’ notation

  2. Supply video and/or player attributes in hashes

  3. Use a block to set attributes

See the README for specific examples

video player. All variables with the exception of @response and @action are writable. @response is readable because it contains the response from MoovAtom’s servers. @action gets set in each of the request methods below to correctly correspond with the actions you’re asking MoovAtom to perform. @format allows you to get xml or json in your responses, it’s set to json by default. @content_type will default to ‘video’.

Yields:

  • (_self)

Yield Parameters:



46
47
48
49
50
51
52
# File 'lib/moovatom.rb', line 46

def initialize(vattrs={}, pattrs={}, &block)
  @player = OpenStruct.new pattrs
  vattrs.each {|k,v| instance_variable_set "@#{k}", v}
  yield self if block_given?
  @content_type = 'video' if @content_type.nil?
  @format = 'json' if @format.nil?
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



21
22
23
# File 'lib/moovatom.rb', line 21

def action
  @action
end

#blurbObject

Returns the value of attribute blurb.



22
23
24
# File 'lib/moovatom.rb', line 22

def blurb
  @blurb
end

#callbackurlObject

Returns the value of attribute callbackurl.



22
23
24
# File 'lib/moovatom.rb', line 22

def callbackurl
  @callbackurl
end

#content_typeObject

Returns the value of attribute content_type.



22
23
24
# File 'lib/moovatom.rb', line 22

def content_type
  @content_type
end

#formatObject

Returns the value of attribute format.



22
23
24
# File 'lib/moovatom.rb', line 22

def format
  @format
end

#playerObject

Returns the value of attribute player.



22
23
24
# File 'lib/moovatom.rb', line 22

def player
  @player
end

#responseObject (readonly)

Returns the value of attribute response.



21
22
23
# File 'lib/moovatom.rb', line 21

def response
  @response
end

#search_termObject

Returns the value of attribute search_term.



22
23
24
# File 'lib/moovatom.rb', line 22

def search_term
  @search_term
end

#sourcefileObject

Returns the value of attribute sourcefile.



22
23
24
# File 'lib/moovatom.rb', line 22

def sourcefile
  @sourcefile
end

#titleObject

Returns the value of attribute title.



22
23
24
# File 'lib/moovatom.rb', line 22

def title
  @title
end

#userkeyObject

Returns the value of attribute userkey.



22
23
24
# File 'lib/moovatom.rb', line 22

def userkey
  @userkey
end

#usernameObject

Returns the value of attribute username.



22
23
24
# File 'lib/moovatom.rb', line 22

def username
  @username
end

#uuidObject

Returns the value of attribute uuid.



22
23
24
# File 'lib/moovatom.rb', line 22

def uuid
  @uuid
end

Instance Method Details

#cancel(attrs = {}) {|_self| ... } ⇒ Object

The cancel() method allows you to cancel a video currently being encoded by the Moovatom servers. It is almost identical to the get_details() and get_status() methods. You can pass the same type/combination of arguments and it also sets the @action instance variable to ‘cancel’ for you.

See README for specific examples

Yields:

  • (_self)

Yield Parameters:



120
121
122
123
124
125
# File 'lib/moovatom.rb', line 120

def cancel(attrs={}, &block)
  @action = 'cancel'
  attrs.each {|k,v| instance_variable_set "@#{k}", v}
  yield self if block_given?
  send_request
end

#delete(attrs = {}) {|_self| ... } ⇒ Object

The delete() method allows you to delete a video that’s finished encoding on the Moovatom servers. It is almost identical to the get_details() and get_status() methods. You can pass the same type/combination of arguments and it also sets the @action instance variable to ‘delete’ for you.

See README for specific examples

Yields:

  • (_self)

Yield Parameters:



151
152
153
154
155
156
# File 'lib/moovatom.rb', line 151

def delete(attrs={}, &block)
  @action = 'delete'
  attrs.each {|k,v| instance_variable_set "@#{k}", v}
  yield self if block_given?
  send_request
end

#edit_player(attrs = {}) {|_self| ... } ⇒ Object

The edit_player() method allows you to change the player attributes for your videos on moovatom’s servers. It accepts a hash of player attributes and/or a block to merge/update the @player instance variable created during initialization. It POSTs this (and all other instance variables) to moovatom through the send_request() method.

See README for specific examples

Yields:

  • (_self)

Yield Parameters:



136
137
138
139
140
141
# File 'lib/moovatom.rb', line 136

def edit_player(attrs={}, &block)
  @action = 'edit_player'
  @player.instance_variable_get("@table").merge! attrs
  yield self if block_given?
  send_request
end

#encode(attrs = {}) {|_self| ... } ⇒ Object

The encode() method allows you to start a new encoding on Moovatom’s servers. It is almost identical to the get_details() and get_status() methods. You can pass the same type/combination of arguments and it also sets the @action instance variable to ‘encode’ for you. After a successful response this method will set the @uuid instance variable to the value returned from Moovatom.

See README for specific examples

Yields:

  • (_self)

Yield Parameters:



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/moovatom.rb', line 98

def encode(attrs={}, &block)
  @action = 'encode'
  attrs.each {|k,v| instance_variable_set "@#{k}", v}
  yield self if block_given?
  send_request

  case @response
  when Hash
    @uuid = @response["uuid"]
  when REXML::Document
    @uuid = @response.root.elements["uuid"].text
  end
end

#get_details(attrs = {}) {|_self| ... } ⇒ Object

The get_details() method is responsible for communicating the details about a video that has completed encoding on Moovatom’s servers. You can pass a hash of attributes and/or supply a block to update the internal state of the MoovEngine object prior to requesting the details of an existing video. This method sets the instance variable @action to ‘detail’ for you. It uses the send_request() method to assign the response from the Moovatom servers to the @response instance variable.

See README for specific examples

Yields:

  • (_self)

Yield Parameters:



65
66
67
68
69
70
# File 'lib/moovatom.rb', line 65

def get_details(attrs={}, &block)
  @action = 'detail'
  attrs.each {|k,v| instance_variable_set "@#{k}", v}
  yield self if block_given?
  send_request
end

#get_status(attrs = {}) {|_self| ... } ⇒ Object

The get_status() method is almost identical to the get_details() method. It also accepts the same type/combination of arguments and sets the that you will receive either a success or error status response from Moovatom’s servers corresponding to the video of the uuid provided.

See README for specific examples

Yields:

  • (_self)

Yield Parameters:



81
82
83
84
85
86
# File 'lib/moovatom.rb', line 81

def get_status(attrs={}, &block)
  @action = 'status'
  attrs.each {|k,v| instance_variable_set "@#{k}", v}
  yield self if block_given?
  send_request
end

#media_search(attrs = {}) {|_self| ... } ⇒ Object

The media_search() method allows you to search for a video on the Moovatom servers. It is almost identical to the get_details() and get_status() methods. You can pass the same type/combination of arguments and it also sets the @action instance variable to ‘media_search’ for you.

See README for specific examples

Yields:

  • (_self)

Yield Parameters:



166
167
168
169
170
171
# File 'lib/moovatom.rb', line 166

def media_search(attrs={}, &block)
  @action = 'media_search'
  attrs.each {|k,v| instance_variable_set "@#{k}", v}
  yield self if block_given?
  send_request
end