encoding-dot-com 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,311 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Encoding.com Queue facade" do
4
+
5
+ before :each do
6
+ @http = mock("Http Interface")
7
+ @facade = EncodingDotCom::Queue.new(1234, "abcd", @http)
8
+ end
9
+
10
+ def expect_xml_with_xpath(xpath)
11
+ @http.should_receive(:post).with(EncodingDotCom::Queue::ENDPOINT,
12
+ EncodingXpathMatcher.new(xpath)).and_return(stub("Http Response", :code => "200", :body => ""))
13
+ end
14
+
15
+ def expect_response_xml(response_xml)
16
+ response = stub("Http Response", :code => "200", :body => response_xml)
17
+ @http.should_receive(:post).and_return(response)
18
+ end
19
+
20
+ describe "any xml sent to encoding.com" do
21
+ [:add_and_process, :status].each do |method|
22
+ it "should have a root query node for method #{method}" do
23
+ expect_xml_with_xpath("/query")
24
+ @facade.send(method, stub("source"))
25
+ end
26
+
27
+ it "should have a user_id node for method #{method}" do
28
+ expect_xml_with_xpath("/query/userid[text()=1234]")
29
+ @facade.send(method, stub("source"))
30
+ end
31
+
32
+ it "should have a user key node for method #{method}" do
33
+ expect_xml_with_xpath("/query/userkey[text()='abcd']")
34
+ @facade.send(method, stub("source"))
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "request sent to encoding.com" do
40
+ it "should return true if a success" do
41
+ @http.should_receive(:post).and_return(stub("Http Response", :code => "200", :body => ""))
42
+ @facade.add_and_process(stub("source"), {}).should be_true
43
+ end
44
+
45
+ it "should raise an AvailabilityError if response status from encoding.com is not a 200" do
46
+ @http.should_receive(:post).and_return(stub("Http Response", :code => "503", :body => ""))
47
+ lambda { @facade.add_and_process(stub("source"), {}) }.should raise_error(EncodingDotCom::AvailabilityError)
48
+ end
49
+
50
+ it "should raise an MessageError if response contains errors" do
51
+ response = stub("Http Response",
52
+ :code => "200",
53
+ :body => "<?xml version=\"1.0\"?>\n<response><errors><error>Wrong query format</error></errors></response>\n")
54
+ @http.should_receive(:post).and_return(response)
55
+ lambda { @facade.add_and_process(stub("source"), {}) }.should raise_error(EncodingDotCom::MessageError)
56
+ end
57
+ end
58
+
59
+ describe "xml sent to encoding.com to process a video" do
60
+ it "should have an action of 'AddMedia'." do
61
+ expect_xml_with_xpath("/query/action[text()='AddMedia']")
62
+ @facade.add_and_process(stub("source"), {})
63
+ end
64
+
65
+ it "should include the source url" do
66
+ expect_xml_with_xpath("/query/source[text()='http://example.com/']")
67
+ @facade.add_and_process("http://example.com/", {})
68
+ end
69
+
70
+ it "should include the formats provided" do
71
+ expect_xml_with_xpath("/query/format/output[text()='flv']")
72
+ format = EncodingDotCom::Format.create("output" => "flv")
73
+ @facade.add_and_process(stub("source"), {stub("destination") => format})
74
+ end
75
+
76
+ it "should include the destination urls in the formats provided" do
77
+ expect_xml_with_xpath("/query/format/destination[text()='http://example.com']")
78
+ format = EncodingDotCom::Format.create("output" => "flv")
79
+ @facade.add_and_process(stub("source"), {"http://example.com" => format})
80
+ end
81
+ end
82
+
83
+ describe "calling add_and_process" do
84
+ it "should return the a media id" do
85
+ expect_response_xml("<response><MediaID>1234</MediaID></response>")
86
+ @facade.add_and_process(stub("source"), {}).should == 1234
87
+ end
88
+ end
89
+
90
+ describe "xml sent to encoding.com to get the status of a job" do
91
+ it "should include a action node with 'GetStatus'" do
92
+ expect_xml_with_xpath("/query/action[text()='GetStatus']")
93
+ @facade.status("mediaid")
94
+ end
95
+
96
+ it "should include a media id node" do
97
+ expect_xml_with_xpath("/query/mediaid[text()='abcd']")
98
+ @facade.status("abcd")
99
+ end
100
+ end
101
+
102
+ describe "calling simple status method" do
103
+ it "should respond with a string status from encoding.com" do
104
+ expect_response_xml("<response><status>New</status></response>")
105
+ @facade.status("mediaid").should == "New"
106
+ end
107
+ end
108
+
109
+ describe "calling get media list method" do
110
+ it "should include an action node with 'GetMediaList'" do
111
+ expect_xml_with_xpath("/query/action[text()='GetMediaList']")
112
+ @facade.list
113
+ end
114
+
115
+ describe "returned MediaListItems" do
116
+ before :each do
117
+ expect_response_xml(<<-END
118
+ <response>
119
+ <media>
120
+ <mediafile>foo.wmv</mediafile>
121
+ <mediaid>1234</mediaid>
122
+ <mediastatus>Closed</mediastatus>
123
+ <createdate>2009-01-01 12:00:01</createdate>
124
+ <startdate>2009-01-01 12:00:02</startdate>
125
+ <finishdate>2009-01-01 12:00:03</finishdate>
126
+ </media>
127
+ </response>
128
+ END
129
+ )
130
+ end
131
+
132
+ it "should return an array of media list values" do
133
+ @facade.list.should be_kind_of(Enumerable)
134
+ end
135
+
136
+ it "should have a hash of returned attributes with a mediafile key" do
137
+ @facade.list.first.media_file.should == "foo.wmv"
138
+ end
139
+
140
+ it "should have a hash of returned attributes with a mediaid key" do
141
+ @facade.list.first.media_id.should == 1234
142
+ end
143
+
144
+ it "should have a hash of returned attributes with a mediastatus key" do
145
+ @facade.list.first.media_status.should == "Closed"
146
+ end
147
+
148
+ it "should have a hash of returned attributes with a createdate key" do
149
+ @facade.list.first.create_date.should == Time.local(2009, 1, 1, 12, 0, 1)
150
+ end
151
+
152
+ it "should have a hash of returned attributes with a startdate key" do
153
+ @facade.list.first.start_date.should == Time.local(2009, 1, 1, 12, 0, 2)
154
+ end
155
+
156
+ it "should have a hash of returned attributes with a finishdate key" do
157
+ @facade.list.first.finish_date.should == Time.local(2009, 1, 1, 12, 0, 3)
158
+ end
159
+ end
160
+ end
161
+
162
+ describe "deleting specified media and all its items in the queue" do
163
+ it "should have an action of 'CancelMedia'." do
164
+ expect_xml_with_xpath("/query/action[text()='CancelMedia']")
165
+ @facade.cancel(5678)
166
+ end
167
+
168
+ it "should have a mediaid of 1234." do
169
+ expect_xml_with_xpath("/query/mediaid[text()='5678']")
170
+ @facade.cancel(5678)
171
+ end
172
+ end
173
+
174
+ describe "processing items already in the encoding" do
175
+ it "should have an action of 'CancelMedia'." do
176
+ expect_xml_with_xpath("/query/action[text()='ProcessMedia']")
177
+ @facade.process(5678)
178
+ end
179
+
180
+ it "should have a mediaid of 1234." do
181
+ expect_xml_with_xpath("/query/mediaid[text()='5678']")
182
+ @facade.process(5678)
183
+ end
184
+ end
185
+
186
+ describe "updating formats of an item already in the encoding.com queue" do
187
+ it "should have an action of 'UpdateMedia'." do
188
+ expect_xml_with_xpath("/query/action[text()='UpdateMedia']")
189
+ @facade.update(5678, {})
190
+ end
191
+
192
+ it "should have a mediaid of 1234." do
193
+ expect_xml_with_xpath("/query/mediaid[text()='5678']")
194
+ @facade.update(5678, {})
195
+ end
196
+
197
+ it "should include the formats provided" do
198
+ expect_xml_with_xpath("/query/format/output[text()='flv']")
199
+ format = EncodingDotCom::Format.create("output" => "flv")
200
+ @facade.update(5678, {stub("destination") => format})
201
+ end
202
+
203
+ it "should include the destination urls in the formats provided" do
204
+ expect_xml_with_xpath("/query/format/destination[text()='http://example.com']")
205
+ format = EncodingDotCom::Format.create("output" => "flv")
206
+ @facade.update(5678, {"http://example.com" => format})
207
+ end
208
+ end
209
+
210
+ describe "adding an item to the encoding.com queue but not processing it" do
211
+ it "should have an action of 'AddMedia'." do
212
+ expect_xml_with_xpath("/query/action[text()='AddMediaBenchmark']")
213
+ @facade.add(stub("source"), {})
214
+ end
215
+
216
+ it "should include the source url" do
217
+ expect_xml_with_xpath("/query/source[text()='http://example.com/']")
218
+ @facade.add("http://example.com/", {})
219
+ end
220
+
221
+ it "should include the formats provided" do
222
+ expect_xml_with_xpath("/query/format/output[text()='flv']")
223
+ format = EncodingDotCom::Format.create("output" => "flv")
224
+ @facade.add(stub("source"), {stub("destination") => format})
225
+ end
226
+
227
+ it "should include the destination urls in the formats provided" do
228
+ expect_xml_with_xpath("/query/format/destination[text()='http://example.com']")
229
+ format = EncodingDotCom::Format.create("output" => "flv")
230
+ @facade.add(stub("source"), {"http://example.com" => format})
231
+ end
232
+ end
233
+
234
+ describe "getting information about a specified media item" do
235
+ it "should have an action of 'GetMediaInfo'." do
236
+ expect_xml_with_xpath("/query/action[text()='GetMediaInfo']")
237
+ @facade.info(5678)
238
+ end
239
+
240
+ it "should have a mediaid of 1234." do
241
+ expect_xml_with_xpath("/query/mediaid[text()='5678']")
242
+ @facade.cancel(5678)
243
+ end
244
+
245
+ describe "returned media info object" do
246
+ before :each do
247
+ expect_response_xml(<<-END
248
+ <?xml version="1.0"?>
249
+ <response>
250
+ <bitrate>1807k</bitrate>
251
+ <duration>6464.83</duration>
252
+ <video_codec>mpeg4</video_codec>
253
+ <video_bitrate>1679k</video_bitrate>
254
+ <frame_rate>23.98</frame_rate>
255
+ <size>640x352</size>
256
+ <pixel_aspect_ratio>1:1</pixel_aspect_ratio>
257
+ <display_aspect_ratio>20:11</display_aspect_ratio>
258
+ <audio_codec>ac3</audio_codec>
259
+ <audio_sample_rate>48000</audio_sample_rate>
260
+ <audio_channels>2</audio_channels>
261
+ </response>
262
+ END
263
+ )
264
+ end
265
+
266
+ it "should have a bitrate" do
267
+ @facade.info(1234).bitrate.should == "1807k"
268
+ end
269
+
270
+ it "should have a duration" do
271
+ @facade.info(1234).duration.should == 6464.83
272
+ end
273
+
274
+ it "should have a video_codec" do
275
+ @facade.info(1234).video_codec.should == "mpeg4"
276
+ end
277
+
278
+ it "should have a video_bitrate" do
279
+ @facade.info(1234).video_bitrate.should == "1679k"
280
+ end
281
+
282
+ it "should have a frame rate" do
283
+ @facade.info(1234).frame_rate.should == 23.98
284
+ end
285
+
286
+ it "should have a size" do
287
+ @facade.info(1234).size.should == "640x352"
288
+ end
289
+
290
+ it "should hava a pixel aspect ratio" do
291
+ @facade.info(1234).pixel_aspect_ratio.should == "1:1"
292
+ end
293
+
294
+ it "should have a display aspect ratio" do
295
+ @facade.info(1234).display_aspect_ratio.should == "20:11"
296
+ end
297
+
298
+ it "should have an audio codec" do
299
+ @facade.info(1234).audio_codec.should == "ac3"
300
+ end
301
+
302
+ it "should have an audio sample rate" do
303
+ @facade.info(1234).audio_sample_rate.should == 48_000
304
+ end
305
+
306
+ it "should have audio channels" do
307
+ @facade.info(1234).audio_channels.should == 2
308
+ end
309
+ end
310
+ end
311
+ end
@@ -0,0 +1,46 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'encoding-dot-com'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+ require 'nokogiri'
8
+
9
+ class EncodingXpathMatcher
10
+ def initialize(xpath)
11
+ @xpath = xpath
12
+ end
13
+
14
+ def ==(post_vars)
15
+ ! Nokogiri::XML(post_vars[:xml]).xpath(@xpath).empty?
16
+ end
17
+ end
18
+
19
+ module XpathMatchers
20
+ class HaveXpath
21
+ def initialize(xpath)
22
+ @xpath = xpath
23
+ end
24
+
25
+ def matches?(xml)
26
+ @xml = xml
27
+ Nokogiri::XML(xml).xpath(@xpath).any?
28
+ end
29
+
30
+ def failure_message
31
+ "expected #{@xml} to have xpath #{@xpath}"
32
+ end
33
+
34
+ def negative_failure_message
35
+ "expected #{@xml} not to have xpath #{@xpath}"
36
+ end
37
+ end
38
+
39
+ def have_xpath(xpath)
40
+ HaveXpath.new(xpath)
41
+ end
42
+ end
43
+
44
+ Spec::Runner.configure do |config|
45
+ config.include(XpathMatchers)
46
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Encoding.com Thumbnail Format" do
4
+
5
+ it "should have an output attribute of 'thumbnail'" do
6
+ EncodingDotCom::ThumbnailFormat.new.output.should == "thumbnail"
7
+ end
8
+
9
+ it "should return a ThumbnailFormat if the output is 'thumbnail'" do
10
+ EncodingDotCom::Format.create("output" => "thumbnail").should be_instance_of(EncodingDotCom::ThumbnailFormat)
11
+ end
12
+
13
+ def format_xml(attributes={})
14
+ format = EncodingDotCom::ThumbnailFormat.new(attributes)
15
+ Nokogiri::XML::Builder.new {|b| format.build_xml(b, "http://example.com") }.to_xml
16
+ end
17
+
18
+ it "should produce a format node in the xml output" do
19
+ format_xml.should have_xpath("/format")
20
+ end
21
+
22
+ it "should produce an output node in the xml output" do
23
+ format_xml.should have_xpath("/format/output[text()='thumbnail']")
24
+ end
25
+
26
+ it "should produce a height node in the xml output" do
27
+ format_xml("height" => 10).should have_xpath("/format/height[text()='10']")
28
+ end
29
+
30
+ it "should produce a width node in the xml output" do
31
+ format_xml("width" => 10).should have_xpath("/format/width[text()='10']")
32
+ end
33
+
34
+ it "should produce a time node in the xml output" do
35
+ format_xml("time" => 10).should have_xpath("/format/time[text()='10']")
36
+ end
37
+
38
+ it "should produce a destination node in the output" do
39
+ format_xml.should have_xpath("/format/destination[text()='http://example.com']")
40
+ end
41
+
42
+ describe "valid times" do
43
+ it "can be a number greater than 0.01" do
44
+ lambda { EncodingDotCom::ThumbnailFormat.new("time" => "0") }.should raise_error(EncodingDotCom::IllegalFormatAttribute)
45
+ lambda { EncodingDotCom::ThumbnailFormat.new("time" => "0.5") }.should_not raise_error
46
+ end
47
+
48
+ it "can be specified in HH:MM::SS.ms format" do
49
+ lambda { EncodingDotCom::ThumbnailFormat.new("time" => "00:00:01.5") }.should_not raise_error
50
+ end
51
+ end
52
+
53
+ describe "valid dimensions" do
54
+ it "should be a positive integer height" do
55
+ lambda { EncodingDotCom::ThumbnailFormat.new("height" => -1) }.should raise_error(EncodingDotCom::IllegalFormatAttribute)
56
+ lambda { EncodingDotCom::ThumbnailFormat.new("height" => 1) }.should_not raise_error
57
+ end
58
+
59
+ it "should be a positive integer width" do
60
+ lambda { EncodingDotCom::ThumbnailFormat.new("width" => -1) }.should raise_error(EncodingDotCom::IllegalFormatAttribute)
61
+ lambda { EncodingDotCom::ThumbnailFormat.new("width" => 1) }.should_not raise_error
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: encoding-dot-com
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roland Swingler
8
+ - Alan Kennedy
9
+ - Levent Ali
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-12-07 00:00:00 +00:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: nokogiri
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: "0"
26
+ version:
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ type: :development
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ version:
37
+ description: A ruby wrapper for the encoding.com API
38
+ email: roland.swingler@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - encoding-dot-com.gemspec
54
+ - lib/encoding-dot-com.rb
55
+ - lib/encoding_dot_com.rb
56
+ - lib/encoding_dot_com/attribute_restrictions.rb
57
+ - lib/encoding_dot_com/errors.rb
58
+ - lib/encoding_dot_com/flv_vp6_format.rb
59
+ - lib/encoding_dot_com/format.rb
60
+ - lib/encoding_dot_com/http_adapters/curb_adapter.rb
61
+ - lib/encoding_dot_com/http_adapters/net_http_adapter.rb
62
+ - lib/encoding_dot_com/media_info.rb
63
+ - lib/encoding_dot_com/media_list_item.rb
64
+ - lib/encoding_dot_com/queue.rb
65
+ - lib/encoding_dot_com/thumbnail_format.rb
66
+ - lib/encoding_dot_com/video_format.rb
67
+ - spec/encoding_dot_com/http_adapters/curb_adapter_spec.rb
68
+ - spec/encoding_dot_com/http_adapters/net_http_adapter_spec.rb
69
+ - spec/flv_vp6_format_spec.rb
70
+ - spec/format_spec.rb
71
+ - spec/media_list_item_spec.rb
72
+ - spec/queue_spec.rb
73
+ - spec/spec_helper.rb
74
+ - spec/thumbnail_format_spec.rb
75
+ has_rdoc: true
76
+ homepage: http://encodingdotcom.rubyforge.org/
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --charset=UTF-8
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.5
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: A ruby wrapper for the encoding.com API
103
+ test_files:
104
+ - spec/flv_vp6_format_spec.rb
105
+ - spec/spec_helper.rb
106
+ - spec/encoding_dot_com/http_adapters/net_http_adapter_spec.rb
107
+ - spec/encoding_dot_com/http_adapters/curb_adapter_spec.rb
108
+ - spec/format_spec.rb
109
+ - spec/queue_spec.rb
110
+ - spec/media_list_item_spec.rb
111
+ - spec/thumbnail_format_spec.rb