moovatom 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/README.md +342 -177
- data/Rakefile +9 -0
- data/lib/moovatom/version.rb +1 -1
- data/lib/moovatom.rb +198 -116
- data/moovatom.gemspec +2 -2
- data/spec/cancel_spec.rb +106 -0
- data/spec/details_spec.rb +103 -0
- data/spec/encode_spec.rb +103 -0
- data/spec/fixtures/cancel.json +4 -0
- data/spec/fixtures/cancel.xml +1 -1
- data/spec/fixtures/detail.json +69 -0
- data/spec/fixtures/detail.xml +1 -1
- data/spec/fixtures/encode.json +4 -0
- data/spec/fixtures/encode.xml +1 -1
- data/spec/fixtures/player_error.json +4 -0
- data/spec/fixtures/player_error.xml +5 -0
- data/spec/fixtures/player_success.json +5 -0
- data/spec/fixtures/player_success.xml +6 -0
- data/spec/fixtures/status_error.json +7 -0
- data/spec/fixtures/status_error.xml +1 -1
- data/spec/fixtures/status_success.json +7 -0
- data/spec/fixtures/status_success.xml +1 -1
- data/spec/init_spec.rb +79 -0
- data/spec/player_spec.rb +156 -0
- data/spec/status_spec.rb +107 -0
- metadata +41 -13
- data/spec/request_spec.rb +0 -73
data/lib/moovatom.rb
CHANGED
@@ -1,149 +1,231 @@
|
|
1
1
|
# :title: MoovAtom API Documentation
|
2
|
-
# The MoovEngine API provides the RESTful interface for encoding, canceling
|
3
|
-
# your videos on the MoovAtom servers. This library defines the
|
4
|
-
# necessary for your app to communicate with that
|
2
|
+
# The MoovEngine API provides the RESTful interface for encoding, canceling
|
3
|
+
# and querying, your videos on the MoovAtom servers. This library defines the
|
4
|
+
# methods and functionality necessary for your app to communicate with that
|
5
|
+
# interface.
|
5
6
|
#
|
6
|
-
# See README file for installation details and
|
7
|
+
# See README file for installation details and specific usage information.
|
7
8
|
#
|
8
9
|
# Author:: Dominic Giglio <mailto:humanshell@gmail.com>
|
9
|
-
# Copyright:: Copyright (c)
|
10
|
+
# Copyright:: Copyright (c) 2012 Dominic Giglio - All Rights Reserved
|
10
11
|
# License:: MIT
|
11
12
|
|
12
13
|
#-- required gems/libraries
|
13
|
-
%w[net/
|
14
|
+
%w[net/http uri rexml/document ostruct json].each { |lib| require lib }
|
14
15
|
|
15
16
|
#-- wrap the whole library in a module to enforce namespace
|
16
17
|
module MoovAtom
|
17
|
-
|
18
|
-
#-- MoovAtom module constants
|
19
|
-
API_URL = 'https://moovatom.com/api/api_request'
|
18
|
+
API_URL = 'https://www.moovatom.com/api/v2'
|
20
19
|
|
21
20
|
class MoovEngine
|
21
|
+
attr_reader :response, :action
|
22
|
+
attr_accessor :uuid, :username, :userkey, :content_type, :title, :blurb,
|
23
|
+
:sourcefile, :callbackurl, :format, :player
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# The initializer creates a set of instance variables to hold all the specifics about
|
28
|
-
# the video you're accessing. You can define these variables when instantiating a new
|
29
|
-
# MoovEngine object or after a blank object has been created. All variables with the
|
30
|
-
# exception of @xml_response and @action are writable. @xml_response is only readable
|
31
|
-
# because it contains the respnse from MoovAtom's servers. @action gets set in each of
|
32
|
-
# the methods below to correctly correspond with the associated request.
|
25
|
+
##
|
26
|
+
# The initializer populates the class' instance variables to hold all the
|
27
|
+
# specifics about the video you're accessing or starting to encode, as well
|
28
|
+
# as the player control attributes.
|
33
29
|
#
|
34
|
-
#
|
35
|
-
# * moov_engine = MoovAtom::MoovEngine.new
|
36
|
-
# * moov_engine.username = 'YOUR_USERNAME'
|
37
|
-
# * moov_engine.userkey = 'YOUR_USERKEY'
|
38
|
-
# * etc...
|
30
|
+
# There are three ways to instantiate a new MoovEngine object:
|
39
31
|
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
def initialize(args={})
|
44
|
-
@guid = args[:guid]
|
45
|
-
@username = args[:username]
|
46
|
-
@userkey = args[:userkey]
|
47
|
-
@content_type = args[:content_type] || "video"
|
48
|
-
@title = args[:title]
|
49
|
-
@blurb = args[:blurb]
|
50
|
-
@sourcefile = args[:sourcefile]
|
51
|
-
@callbackurl = args[:callbackurl]
|
52
|
-
end #-- end initialize method
|
53
|
-
|
54
|
-
# Use this method to get the details about a video that's finished encoding.
|
55
|
-
# This method requires @username, @userkey and @guid to be set.
|
32
|
+
# 1. Create a blank object and set each variable using 'dot' notation
|
33
|
+
# 2. Supply video and/or player attributes in hashes
|
34
|
+
# 3. Use a block to set attributes
|
56
35
|
#
|
57
|
-
#
|
36
|
+
# See the README for specific examples
|
58
37
|
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end #-- end details method
|
38
|
+
# @player is a struct (OpenStruct) that holds all the attributes for your
|
39
|
+
# video player. All variables with the exception of @response and @action
|
40
|
+
# are writable. @response is readable because it contains the response from
|
41
|
+
# MoovAtom's servers. @action gets set in each of the request methods below
|
42
|
+
# to correctly correspond with the actions you're asking MoovAtom to
|
43
|
+
# perform. @format allows you to get xml or json in your responses, it's set
|
44
|
+
# to json by default. @content_type will default to 'video'.
|
67
45
|
|
68
|
-
|
69
|
-
|
46
|
+
def initialize(vattrs={}, pattrs={}, &block)
|
47
|
+
@player = OpenStruct.new pattrs
|
48
|
+
vattrs.each {|k,v| instance_variable_set "@#{k}", v}
|
49
|
+
yield self if block_given?
|
50
|
+
@content_type = 'video' if @content_type.nil?
|
51
|
+
@format = 'json' if @format.nil?
|
52
|
+
end #-- initialize method
|
53
|
+
|
54
|
+
##
|
55
|
+
# The get_details() method is responsible for communicating the details
|
56
|
+
# about a video that has completed encoding on Moovatom's servers. You can
|
57
|
+
# pass a hash of attributes and/or supply a block to update the internal
|
58
|
+
# state of the MoovEngine object prior to requesting the details of an
|
59
|
+
# existing video. This method sets the instance variable @action to 'detail'
|
60
|
+
# for you. It uses the send_request() method to assign the response from the
|
61
|
+
# Moovatom servers to the @response instance variable.
|
70
62
|
#
|
71
|
-
#
|
63
|
+
# See README for specific examples
|
64
|
+
|
65
|
+
def get_details(attrs={}, &block)
|
66
|
+
@action = 'detail'
|
67
|
+
attrs.each {|k,v| instance_variable_set "@#{k}", v}
|
68
|
+
yield self if block_given?
|
69
|
+
send_request
|
70
|
+
end #-- get_details method
|
71
|
+
|
72
|
+
##
|
73
|
+
# The get_status() method is almost identical to the get_details() method.
|
74
|
+
# It also accepts the same type/combination of arguments and sets the
|
75
|
+
# @action instance variable to 'status' for you. The main difference is
|
76
|
+
# that you will receive either a success or error status response from
|
77
|
+
# Moovatom's servers corresponding to the video of the uuid provided.
|
72
78
|
#
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
def status(guid = "")
|
77
|
-
@guid = guid if @guid.nil?
|
79
|
+
# See README for specific examples
|
80
|
+
|
81
|
+
def get_status(attrs={}, &block)
|
78
82
|
@action = 'status'
|
79
|
-
|
80
|
-
|
83
|
+
attrs.each {|k,v| instance_variable_set "@#{k}", v}
|
84
|
+
yield self if block_given?
|
85
|
+
send_request
|
86
|
+
end #-- end get_status method
|
81
87
|
|
82
|
-
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
# * @sourcefile
|
90
|
-
# * @callbackurl
|
88
|
+
##
|
89
|
+
# The encode() method allows you to start a new encoding on Moovatom's
|
90
|
+
# servers. It is almost identical to the get_details() and get_status()
|
91
|
+
# methods. You can pass the same type/combination of arguments and it also
|
92
|
+
# sets the @action instance variable to 'encode' for you. After a
|
93
|
+
# successful response this method will set the @uuid instance variable to
|
94
|
+
# the value returned from Moovatom.
|
91
95
|
#
|
92
|
-
#
|
93
|
-
|
94
|
-
def encode
|
96
|
+
# See README for specific examples
|
97
|
+
|
98
|
+
def encode(attrs={}, &block)
|
95
99
|
@action = 'encode'
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
100
|
+
attrs.each {|k,v| instance_variable_set "@#{k}", v}
|
101
|
+
yield self if block_given?
|
102
|
+
send_request
|
103
|
+
|
104
|
+
case @response
|
105
|
+
when Hash
|
106
|
+
@uuid = @response["uuid"]
|
107
|
+
when REXML::Document
|
108
|
+
@uuid = @response.root.elements["uuid"].text
|
101
109
|
end
|
102
|
-
end #--
|
110
|
+
end #-- encode method
|
103
111
|
|
104
|
-
|
105
|
-
#
|
112
|
+
##
|
113
|
+
# The cancel() method allows you to cancel a video currently being encoded
|
114
|
+
# by the Moovatom servers. It is almost identical to the get_details() and
|
115
|
+
# get_status() methods. You can pass the same type/combination of arguments
|
116
|
+
# and it also sets the @action instance variable to 'cancel' for you.
|
106
117
|
#
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
# * moov_engine.cancel
|
111
|
-
# * moov_engine.cancel 'GUID_OF_VIDEO'
|
112
|
-
def cancel(guid = "")
|
113
|
-
@guid = guid if @guid.nil?
|
118
|
+
# See README for specific examples
|
119
|
+
|
120
|
+
def cancel(attrs={}, &block)
|
114
121
|
@action = 'cancel'
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
#--
|
122
|
+
attrs.each {|k,v| instance_variable_set "@#{k}", v}
|
123
|
+
yield self if block_given?
|
124
|
+
send_request
|
125
|
+
end #-- cancel method
|
126
|
+
|
127
|
+
##
|
128
|
+
# The edit_player() method allows you to change the player attributes for
|
129
|
+
# your videos on moovatom's servers. It accepts a hash of player attributes
|
130
|
+
# and/or a block to merge/update the @player instance variable created
|
131
|
+
# during initialization. It POSTs this (and all other instance variables) to
|
132
|
+
# moovatom through the send_request() method.
|
133
|
+
#
|
134
|
+
# See README for specific examples
|
135
|
+
|
136
|
+
def edit_player(attrs={}, &block)
|
137
|
+
@action = 'edit_player'
|
138
|
+
@player.instance_variable_get("@table").merge! attrs
|
139
|
+
yield self if block_given?
|
140
|
+
send_request
|
141
|
+
end #-- edit method
|
142
|
+
|
119
143
|
private
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
r.blurb(@blurb)
|
133
|
-
r.sourcefile(@sourcefile)
|
134
|
-
r.callbackurl(@callbackurl)
|
135
|
-
end
|
136
|
-
end #-- end build_xml_request method
|
137
|
-
|
138
|
-
# Sends the XML object to the MoovAtom servers
|
139
|
-
def send_xml_request(xml)
|
140
|
-
uri = URI.parse(MoovAtom::API_URL)
|
141
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
144
|
+
|
145
|
+
##
|
146
|
+
# The send_request() method is responsible for POSTing the values stored in
|
147
|
+
# your object's instance variables to Moovatom. The response from Moovatom
|
148
|
+
# is returned when the method finishes. If the response was a success it
|
149
|
+
# will be parsed according to the value of @format.
|
150
|
+
|
151
|
+
def send_request
|
152
|
+
|
153
|
+
# create the connection object
|
154
|
+
uri = URI.parse "#{MoovAtom::API_URL}/#{@action}.#{@format}"
|
155
|
+
http = Net::HTTP.new uri.host, uri.port
|
142
156
|
http.use_ssl = true
|
143
157
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
144
|
-
|
145
|
-
|
158
|
+
|
159
|
+
# open the connection and send request
|
160
|
+
http.start do |http|
|
161
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
162
|
+
req.set_form_data(all_attributes, '&')
|
163
|
+
@response = http.request(req)
|
164
|
+
end
|
165
|
+
|
166
|
+
# parse the response if request was successful
|
167
|
+
if @response.code == "200"
|
168
|
+
case @format
|
169
|
+
when "json"
|
170
|
+
@response = JSON.parse @response.body
|
171
|
+
when "xml"
|
172
|
+
@response = REXML::Document.new @response.body
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
end #-- send_request method
|
177
|
+
|
178
|
+
##
|
179
|
+
# This method assembles all video and player attributes so they can be
|
180
|
+
# easily added to the request that's POST'd to the Moovatom servers
|
181
|
+
|
182
|
+
def all_attributes
|
183
|
+
|
184
|
+
# get all the video instance variables
|
185
|
+
vattrs = Hash[
|
186
|
+
instance_variables.map do |iv|
|
187
|
+
[iv.to_s.gsub!(/@/, ""), instance_variable_get(iv)] unless iv == :@player
|
188
|
+
end
|
189
|
+
]
|
190
|
+
|
191
|
+
# get all the player instance variables
|
192
|
+
pattrs = Hash[
|
193
|
+
@player.instance_variable_get("@table").keys.map do |iv|
|
194
|
+
[iv.to_s, @player.instance_variable_get("@table")[iv].to_s]
|
195
|
+
end
|
196
|
+
]
|
197
|
+
|
198
|
+
# merge them and return as a single hash of attributes
|
199
|
+
vattrs.merge! pattrs
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
##
|
204
|
+
# Custom to_s method for pretty printing in the console
|
205
|
+
|
206
|
+
def to_s
|
207
|
+
puts
|
208
|
+
35.times { print "*" }
|
209
|
+
puts
|
210
|
+
puts "Object ID: #{self.object_id}"
|
211
|
+
puts "UUID: #{@uuid}"
|
212
|
+
puts "Username: #{@username}"
|
213
|
+
puts "Userkey: #{@userkey}"
|
214
|
+
puts "Content Type: #{@content_type}"
|
215
|
+
puts "Title: #{@title}"
|
216
|
+
puts "Blurb: #{@blurb}"
|
217
|
+
puts "Source File: #{@sourcefile}"
|
218
|
+
puts "Callback URL: #{@callbackurl}"
|
219
|
+
puts "Action: #{@action}"
|
220
|
+
puts "Format: #{@format}"
|
221
|
+
puts "Response: #{@response.class}"
|
222
|
+
puts "Player: #{@player.instance_variable_get("@table").length} attribute(s)"
|
223
|
+
35.times { print "*" }
|
224
|
+
puts
|
225
|
+
puts
|
226
|
+
end
|
146
227
|
|
147
|
-
end #--
|
228
|
+
end #-- MoovEngine class
|
148
229
|
|
149
|
-
end #--
|
230
|
+
end #-- MoovAtom module
|
231
|
+
|
data/moovatom.gemspec
CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ["lib"]
|
22
|
-
|
22
|
+
|
23
23
|
#-- release dependencies
|
24
|
-
s.add_dependency('
|
24
|
+
s.add_dependency('json')
|
25
25
|
|
26
26
|
#-- development dependencies
|
27
27
|
s.add_development_dependency('minitest')
|
data/spec/cancel_spec.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# this file contains all the tests associated with cancelling the encoding of
|
4
|
+
# a video on Moovatom's servers.
|
5
|
+
|
6
|
+
describe MoovAtom::MoovEngine, "Cancel Request Unit Tests" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@vars1 = {
|
10
|
+
uuid: '123',
|
11
|
+
username: 'jsmith',
|
12
|
+
userkey: '987654321',
|
13
|
+
title: 'My Greatest Movie',
|
14
|
+
blurb: 'The greatest movie ever made',
|
15
|
+
sourcefile: 'http://example.com/greatest.mp4',
|
16
|
+
callbackurl: 'http://example.com/callback'
|
17
|
+
}
|
18
|
+
|
19
|
+
@vars2 = {
|
20
|
+
uuid: '321',
|
21
|
+
username: 'asmith',
|
22
|
+
userkey: '123456789',
|
23
|
+
title: 'My Best Movie',
|
24
|
+
blurb: 'The bestest movie ever made',
|
25
|
+
sourcefile: 'http://example.com/best.mp4',
|
26
|
+
callbackurl: 'http://example.com/callback_url'
|
27
|
+
}
|
28
|
+
|
29
|
+
# mock up the connection to moovatom.com
|
30
|
+
@me = MoovAtom::MoovEngine.new @vars1
|
31
|
+
@url = "#{MoovAtom::API_URL}/cancel"
|
32
|
+
json = File.join(File.dirname(__FILE__), 'fixtures', 'cancel.json')
|
33
|
+
FakeWeb.register_uri(:post, "#{@url}.json", :body => json)
|
34
|
+
xml = File.join(File.dirname(__FILE__), 'fixtures', 'cancel.xml')
|
35
|
+
FakeWeb.register_uri(:post, "#{@url}.xml", :body => xml)
|
36
|
+
end
|
37
|
+
|
38
|
+
after do
|
39
|
+
# clean up the registry after each test
|
40
|
+
FakeWeb.clean_registry
|
41
|
+
|
42
|
+
# enable all real requests after testing
|
43
|
+
FakeWeb.allow_net_connect = true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "accepts a hash to update attributes" do
|
47
|
+
|
48
|
+
# create a MoovEngine object using the values from the @vars1 hash
|
49
|
+
me = MoovAtom::MoovEngine.new @vars1
|
50
|
+
|
51
|
+
# call cancel() passing the hash of values from @vars2
|
52
|
+
me.cancel @vars2
|
53
|
+
|
54
|
+
# the instance 'me' should now contain the values from the @vars2 hash
|
55
|
+
@vars2.each {|k,v| me.instance_variable_get("@#{k}").must_equal v}
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
it "accepts a block to update attributes" do
|
60
|
+
|
61
|
+
# create a new MoovEngine object with a block using the values from @vars1
|
62
|
+
me = MoovAtom::MoovEngine.new do |me|
|
63
|
+
@vars1.each {|k,v| me.instance_variable_set "@#{k}", v}
|
64
|
+
end
|
65
|
+
|
66
|
+
# call cancel() passing a block that sets instance variables to the
|
67
|
+
# values in the @vars2 hash
|
68
|
+
me.cancel do |me|
|
69
|
+
@vars2.each {|k,v| me.instance_variable_set "@#{k}", v}
|
70
|
+
end
|
71
|
+
|
72
|
+
# the instance 'me' should now contain the values from the @vars2 hash
|
73
|
+
@vars2.each {|k,v| me.instance_variable_get("@#{k}").must_equal v}
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
it "sets the action attribute to cancel" do
|
78
|
+
|
79
|
+
# create a new MoovEngine object
|
80
|
+
me = MoovAtom::MoovEngine.new @vars1
|
81
|
+
|
82
|
+
# call the cancel() method
|
83
|
+
me.cancel
|
84
|
+
|
85
|
+
# after calling cancel() @action should be 'cancel'
|
86
|
+
me.action.must_equal 'cancel'
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
# tests for the api call to get details about an existing video
|
91
|
+
describe "API Requests" do
|
92
|
+
|
93
|
+
it "cancels encoding of a video using json" do
|
94
|
+
@me.cancel
|
95
|
+
@me.response["uuid"].must_equal @vars1[:uuid]
|
96
|
+
end
|
97
|
+
|
98
|
+
it "cancels encoding of a video using xml" do
|
99
|
+
@me.format = 'xml'
|
100
|
+
@me.cancel
|
101
|
+
@me.response.root.elements["uuid"].text.must_equal @vars1[:uuid]
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# this file contains all the tests associated with requesting the details of a
|
4
|
+
# video on Moovatom's servers.
|
5
|
+
|
6
|
+
describe MoovAtom::MoovEngine, "Details Request Unit Tests" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@vars1 = {
|
10
|
+
uuid: '123',
|
11
|
+
username: 'jsmith',
|
12
|
+
userkey: '987654321',
|
13
|
+
title: 'My Greatest Movie',
|
14
|
+
blurb: 'The greatest movie ever made',
|
15
|
+
sourcefile: 'http://example.com/greatest.mp4',
|
16
|
+
callbackurl: 'http://example.com/callback'
|
17
|
+
}
|
18
|
+
|
19
|
+
@vars2 = {
|
20
|
+
uuid: '321',
|
21
|
+
username: 'asmith',
|
22
|
+
userkey: '123456789',
|
23
|
+
title: 'My Best Movie',
|
24
|
+
blurb: 'The bestest movie ever made',
|
25
|
+
sourcefile: 'http://example.com/best.mp4',
|
26
|
+
callbackurl: 'http://example.com/callback_url'
|
27
|
+
}
|
28
|
+
|
29
|
+
# mock up the connection to moovatom.com
|
30
|
+
@me = MoovAtom::MoovEngine.new @vars1
|
31
|
+
@url = "#{MoovAtom::API_URL}/detail"
|
32
|
+
json = File.join(File.dirname(__FILE__), 'fixtures', 'detail.json')
|
33
|
+
FakeWeb.register_uri(:post, "#{@url}.json", :body => json)
|
34
|
+
xml = File.join(File.dirname(__FILE__), 'fixtures', 'detail.xml')
|
35
|
+
FakeWeb.register_uri(:post, "#{@url}.xml", :body => xml)
|
36
|
+
end
|
37
|
+
|
38
|
+
after do
|
39
|
+
# clean up the registry after each test
|
40
|
+
FakeWeb.clean_registry
|
41
|
+
|
42
|
+
# enable all real requests after testing
|
43
|
+
FakeWeb.allow_net_connect = true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "accepts a hash to update attributes" do
|
47
|
+
|
48
|
+
# create a MoovEngine object using the values from the @vars1 hash
|
49
|
+
me = MoovAtom::MoovEngine.new @vars1
|
50
|
+
|
51
|
+
# call get_details() passing the hash of values from @vars2
|
52
|
+
me.get_details @vars2
|
53
|
+
|
54
|
+
# the instance 'me' should now contain the values from the @vars2 hash
|
55
|
+
@vars2.each {|k,v| me.instance_variable_get("@#{k}").must_equal v}
|
56
|
+
end
|
57
|
+
|
58
|
+
it "accepts a block to update attributes" do
|
59
|
+
|
60
|
+
# create a new MoovEngine object with a block using the values from @vars1
|
61
|
+
me = MoovAtom::MoovEngine.new do |me|
|
62
|
+
@vars1.each {|k,v| me.instance_variable_set "@#{k}", v}
|
63
|
+
end
|
64
|
+
|
65
|
+
# call get_details() passing a block that sets instance variables to the
|
66
|
+
# values in the @vars2 hash
|
67
|
+
me.get_details do |me|
|
68
|
+
@vars2.each {|k,v| me.instance_variable_set "@#{k}", v}
|
69
|
+
end
|
70
|
+
|
71
|
+
# the instance 'me' should now contain the values from the @vars2 hash
|
72
|
+
@vars2.each {|k,v| me.instance_variable_get("@#{k}").must_equal v}
|
73
|
+
end
|
74
|
+
|
75
|
+
it "sets the action attribute to detail" do
|
76
|
+
|
77
|
+
# create a new MoovEngine object
|
78
|
+
me = MoovAtom::MoovEngine.new @vars1
|
79
|
+
|
80
|
+
# call the get_details() method
|
81
|
+
me.get_details
|
82
|
+
|
83
|
+
# after calling get_details() @action should be 'detail'
|
84
|
+
me.action.must_equal 'detail'
|
85
|
+
end
|
86
|
+
|
87
|
+
# tests for the api call to get details about an existing video
|
88
|
+
describe "API Requests" do
|
89
|
+
|
90
|
+
it "gets details of a video using json" do
|
91
|
+
@me.get_details
|
92
|
+
@me.response["uuid"].must_equal @vars1[:uuid]
|
93
|
+
end
|
94
|
+
|
95
|
+
it "gets details of a video using xml" do
|
96
|
+
@me.format = 'xml'
|
97
|
+
@me.get_details
|
98
|
+
@me.response.root.elements["uuid"].text.must_equal @vars1[:uuid]
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
data/spec/encode_spec.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# this file contains all the tests associated with requesting a new encoding on
|
4
|
+
# Moovatom's servers.
|
5
|
+
|
6
|
+
describe MoovAtom::MoovEngine, "Encode Request Unit Tests" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@vars1 = {
|
10
|
+
uuid: '123',
|
11
|
+
username: 'jsmith',
|
12
|
+
userkey: '987654321',
|
13
|
+
title: 'My Greatest Movie',
|
14
|
+
blurb: 'The greatest movie ever made',
|
15
|
+
sourcefile: 'http://example.com/greatest.mp4',
|
16
|
+
callbackurl: 'http://example.com/callback'
|
17
|
+
}
|
18
|
+
|
19
|
+
@vars2 = {
|
20
|
+
uuid: '321',
|
21
|
+
username: 'asmith',
|
22
|
+
userkey: '123456789',
|
23
|
+
title: 'My Best Movie',
|
24
|
+
blurb: 'The bestest movie ever made',
|
25
|
+
sourcefile: 'http://example.com/best.mp4',
|
26
|
+
callbackurl: 'http://example.com/callback_url'
|
27
|
+
}
|
28
|
+
|
29
|
+
# mock up the connection to moovatom.com
|
30
|
+
@me = MoovAtom::MoovEngine.new @vars1
|
31
|
+
@url = "#{MoovAtom::API_URL}/encode"
|
32
|
+
json = File.join(File.dirname(__FILE__), 'fixtures', 'encode.json')
|
33
|
+
FakeWeb.register_uri(:post, "#{@url}.json", :body => json)
|
34
|
+
xml = File.join(File.dirname(__FILE__), 'fixtures', 'encode.xml')
|
35
|
+
FakeWeb.register_uri(:post, "#{@url}.xml", :body => xml)
|
36
|
+
end
|
37
|
+
|
38
|
+
after do
|
39
|
+
# clean up the registry after each test
|
40
|
+
FakeWeb.clean_registry
|
41
|
+
|
42
|
+
# enable all real requests after testing
|
43
|
+
FakeWeb.allow_net_connect = true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "accepts a hash to update attributes" do
|
47
|
+
|
48
|
+
# create a MoovEngine object using the values from the @vars1 hash
|
49
|
+
me = MoovAtom::MoovEngine.new @vars1
|
50
|
+
|
51
|
+
# call encode() passing the hash of values from @vars2
|
52
|
+
me.encode @vars2
|
53
|
+
|
54
|
+
# the instance 'me' should now contain the values from the @vars2 hash
|
55
|
+
@vars2.each {|k,v| me.instance_variable_get("@#{k}").must_equal v}
|
56
|
+
end
|
57
|
+
|
58
|
+
it "accepts a block to update attributes" do
|
59
|
+
|
60
|
+
# create a new MoovEngine object with a block using the values from @vars1
|
61
|
+
me = MoovAtom::MoovEngine.new do |me|
|
62
|
+
@vars1.each {|k,v| me.instance_variable_set "@#{k}", v}
|
63
|
+
end
|
64
|
+
|
65
|
+
# call encode() passing a block that sets instance variables to the
|
66
|
+
# values in the @vars2 hash
|
67
|
+
me.encode do |me|
|
68
|
+
@vars2.each {|k,v| me.instance_variable_set "@#{k}", v}
|
69
|
+
end
|
70
|
+
|
71
|
+
# the instance 'me' should now contain the values from the @vars2 hash
|
72
|
+
@vars2.each {|k,v| me.instance_variable_get("@#{k}").must_equal v}
|
73
|
+
end
|
74
|
+
|
75
|
+
it "sets the action attribute to encode" do
|
76
|
+
|
77
|
+
# create a new MoovEngine object
|
78
|
+
me = MoovAtom::MoovEngine.new @vars1
|
79
|
+
|
80
|
+
# call the encode() method
|
81
|
+
me.encode
|
82
|
+
|
83
|
+
# after calling encode() @action should be 'encode'
|
84
|
+
me.action.must_equal 'encode'
|
85
|
+
end
|
86
|
+
|
87
|
+
# tests for the api call to get details about an existing video
|
88
|
+
describe "API Requests" do
|
89
|
+
|
90
|
+
it "starts a new encoding using json" do
|
91
|
+
@me.encode
|
92
|
+
@me.response["uuid"].must_equal "321"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "starts a new encoding using xml" do
|
96
|
+
@me.format = 'xml'
|
97
|
+
@me.encode
|
98
|
+
@me.response.root.elements["uuid"].text.must_equal "321"
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|