zencoder-flix_cloud-gem 0.0.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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Zencoder
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,11 @@
1
+ FlixCloud Gem
2
+ =============
3
+
4
+ The gem for interacting with the API on [FlixCloud](http://flixcloud.com).
5
+
6
+ See [http://flixcloud.com/api](http://flixcloud.com/api) for more details on the API.
7
+
8
+ COPYRIGHT
9
+ ---------
10
+
11
+ Copyright (c) 2009 Zencoder. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "flix_cloud-gem"
8
+ gem.summary = %{Gem for integrating with http://flixcloud.com}
9
+ gem.email = "nate@sevenwire.com"
10
+ gem.homepage = "http://github.com/zencoder/flix_cloud-gem"
11
+ gem.authors = ["Nathan Sutton"]
12
+ gem.add_dependency('builder', '>= 2.1.2')
13
+ gem.add_dependency('crack', '>= 0.1.1')
14
+ gem.add_dependency('rest-client', '>= 0.9.2')
15
+
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ rescue LoadError
19
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/*_test.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ if File.exist?('VERSION.yml')
48
+ config = YAML.load(File.read('VERSION.yml'))
49
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
50
+ else
51
+ version = ""
52
+ end
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "flix_cloud-gem #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
59
+
data/lib/flix_cloud.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'builder'
2
+ require 'restclient'
3
+ require 'crack/xml'
4
+
5
+ module FlixCloud; end
6
+
7
+ require File.dirname(__FILE__) + '/flix_cloud/record'
8
+ require File.dirname(__FILE__) + '/flix_cloud/job'
9
+ require File.dirname(__FILE__) + '/flix_cloud/file_locations'
10
+ require File.dirname(__FILE__) + '/flix_cloud/file'
11
+ require File.dirname(__FILE__) + '/flix_cloud/input_file'
12
+ require File.dirname(__FILE__) + '/flix_cloud/output_file'
13
+ require File.dirname(__FILE__) + '/flix_cloud/watermark_file'
14
+ require File.dirname(__FILE__) + '/flix_cloud/parameters'
15
+ require File.dirname(__FILE__) + '/flix_cloud/response'
16
+ require File.dirname(__FILE__) + '/flix_cloud/extensions/hash'
@@ -0,0 +1,22 @@
1
+ module FlixCloud
2
+ module Extensions
3
+ # Both methods ripped directly out of rails
4
+ module Hash
5
+ def deep_merge(other_hash)
6
+ self.merge(other_hash) do |key, oldval, newval|
7
+ oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
8
+ newval = newval.to_hash if newval.respond_to?(:to_hash)
9
+ oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.deep_merge(newval) : newval
10
+ end
11
+ end
12
+
13
+ # Returns a new hash with +self+ and +other_hash+ merged recursively.
14
+ # Modifies the receiver in place.
15
+ def deep_merge!(other_hash)
16
+ replace(deep_merge(other_hash))
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ Hash.send(:include, FlixCloud::Extensions::Hash) unless Hash.instance_methods.include?('deep_merge')
@@ -0,0 +1,21 @@
1
+ class FlixCloud::File < FlixCloud::Record
2
+
3
+ attr_accessor :url
4
+
5
+ record_column :parameters, 'Parameters'
6
+
7
+ def valid?
8
+ self.errors = []
9
+
10
+ unless url
11
+ self.errors << "url is required"
12
+ end
13
+
14
+ if parameters && !parameters.valid?
15
+ self.errors << {:parameters => parameters.errors}
16
+ end
17
+
18
+ errors.empty?
19
+ end
20
+
21
+ end
@@ -0,0 +1,33 @@
1
+ class FlixCloud::FileLocations < FlixCloud::Record
2
+
3
+ record_column :input, 'InputFile'
4
+ record_column :output, 'OutputFile'
5
+ record_column :watermark, 'WatermarkFile'
6
+
7
+ def valid?
8
+ self.errors = []
9
+
10
+ if input
11
+ unless input.valid?
12
+ self.errors << {:input => input.errors}
13
+ end
14
+ else
15
+ self.errors << "input is required"
16
+ end
17
+
18
+ if output
19
+ unless output.valid?
20
+ self.errors << {:output => output.errors}
21
+ end
22
+ else
23
+ self.errors << "output is required"
24
+ end
25
+
26
+ if watermark && !watermark.valid?
27
+ self.errors << {:watermark => watermark.errors}
28
+ end
29
+
30
+ errors.empty?
31
+ end
32
+
33
+ end
@@ -0,0 +1,2 @@
1
+ class FlixCloud::InputFile < FlixCloud::File
2
+ end
@@ -0,0 +1,124 @@
1
+ class FlixCloud::Job < FlixCloud::Record
2
+
3
+ attr_accessor :id, :initialized_at, :api_key, :recipe_id, :response
4
+
5
+ record_column :file_locations, 'FileLocations'
6
+
7
+ def initialize(attrs={})
8
+ super
9
+ self.shortcut_attributes = attrs
10
+ end
11
+
12
+ def valid?
13
+ self.errors = []
14
+
15
+ if file_locations
16
+ unless file_locations.valid?
17
+ self.errors << {:file_locations => file_locations.errors}
18
+ end
19
+ else
20
+ self.errors << "file_locations is required"
21
+ end
22
+
23
+ unless recipe_id
24
+ self.errors << "recipe_id is required"
25
+ end
26
+
27
+ unless api_key
28
+ self.errors << "api_key is required"
29
+ end
30
+
31
+ errors.empty?
32
+ end
33
+
34
+ def save
35
+ return false unless valid?
36
+
37
+ self.response = FlixCloud::Response.new(post('jobs', to_xml))
38
+
39
+ if response.success?
40
+ self.id = response.body_as_hash['job']['id']
41
+ self.initialized_at = response.body_as_hash['job']['initialized_job_at']
42
+ else
43
+ self.errors = response.errors
44
+ end
45
+
46
+ response.success?
47
+ end
48
+
49
+ def to_xml
50
+ xml = Builder::XmlMarkup.new
51
+
52
+ xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
53
+
54
+ xml.tag!("api-request") do
55
+ xml.tag!("api-key", api_key)
56
+ xml.tag!("recipe-id", recipe_id)
57
+
58
+ if file_locations
59
+ xml.tag!("file-locations") do
60
+ if file_locations.input
61
+ xml.input do
62
+ xml.url(file_locations.input.url)
63
+ if file_locations.input.parameters
64
+ xml.parameters do
65
+ xml.user(file_locations.input.parameters.user)
66
+ xml.password(file_locations.input.parameters.password)
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ if file_locations.output
73
+ xml.output do
74
+ xml.url(file_locations.output.url)
75
+ if file_locations.output.parameters
76
+ xml.parameters do
77
+ xml.user(file_locations.output.parameters.user)
78
+ xml.password(file_locations.output.parameters.password)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ if file_locations.watermark
85
+ xml.watermark do
86
+ xml.url(file_locations.watermark.url)
87
+ if file_locations.watermark.parameters
88
+ xml.parameters do
89
+ xml.user(file_locations.watermark.parameters.user)
90
+ xml.password(file_locations.watermark.parameters.password)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ xml.target!
100
+ end
101
+
102
+
103
+ protected
104
+
105
+ def shortcut_attributes=(attrs)
106
+ translated_attributes = {}
107
+
108
+ attrs.each do |key, value|
109
+ if match = key.to_s.match(/^(input|output|watermark)_(url|user|password)$/)
110
+ file_type = match[1].to_sym
111
+ parameter_type = match[2].to_sym
112
+
113
+ if parameter_type == :url
114
+ translated_attributes.deep_merge!(:file_locations => { file_type => { :url => value}})
115
+ else
116
+ translated_attributes.deep_merge!(:file_locations => { file_type => { :parameters => { parameter_type => value}}})
117
+ end
118
+ end
119
+ end
120
+
121
+ self.attributes = translated_attributes unless translated_attributes.empty?
122
+ end
123
+
124
+ end
@@ -0,0 +1,2 @@
1
+ class FlixCloud::OutputFile < FlixCloud::File
2
+ end
@@ -0,0 +1,19 @@
1
+ class FlixCloud::Parameters < FlixCloud::File
2
+
3
+ attr_accessor :user, :password
4
+
5
+ def valid?
6
+ self.errors = []
7
+
8
+ unless user
9
+ self.errors << "user is required"
10
+ end
11
+
12
+ unless password
13
+ self.errors << "password is required"
14
+ end
15
+
16
+ errors.empty?
17
+ end
18
+
19
+ end
@@ -0,0 +1,38 @@
1
+ class FlixCloud::Record
2
+
3
+ attr_accessor :errors
4
+
5
+ def initialize(attrs={})
6
+ self.errors = []
7
+ self.attributes = attrs
8
+ end
9
+
10
+ def attributes=(attrs)
11
+ attrs.each do |key, value|
12
+ send("#{key}=", value) if respond_to?("#{key}=")
13
+ end
14
+ end
15
+
16
+ def self.record_column(attribute, klass)
17
+ eval %{
18
+ attr_reader :#{attribute}
19
+
20
+ def #{attribute}=(value)
21
+ if @#{attribute}
22
+ @#{attribute}.attributes = value
23
+ else
24
+ @#{attribute} = FlixCloud::#{klass}.new(value)
25
+ end
26
+ end
27
+ }
28
+ end
29
+
30
+ protected
31
+
32
+ def post(path, body)
33
+ RestClient::Resource.new(
34
+ "https://flixcloud.com/#{path}",
35
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER).post(body, :content_type => 'application/xml', :accept => 'application/xml')
36
+ end
37
+
38
+ end
@@ -0,0 +1,26 @@
1
+ class FlixCloud::Response
2
+
3
+ attr_accessor :code, :body, :errors, :body_as_hash
4
+
5
+ def initialize(response)
6
+ self.code = response.code
7
+ self.body = response.to_s
8
+ self.body_as_hash = Crack::XML.parse(response.to_s)
9
+ self.errors = []
10
+ process_response_xml
11
+ end
12
+
13
+ def success?
14
+ errors.empty?
15
+ end
16
+
17
+
18
+ protected
19
+
20
+ def process_response_xml
21
+ if body_as_hash['errors'] && body_as_hash['errors'].is_a?(Hash) && body_as_hash['errors']['error']
22
+ self.errors = Array(body_as_hash['errors']['error'])
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,2 @@
1
+ class FlixCloud::WatermarkFile < FlixCloud::File
2
+ end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ class FlixCloud::FileLocationsTest < Test::Unit::TestCase
4
+
5
+ context "When validationg a file locations object with no attributes set" do
6
+ setup do
7
+ @file_locations = FlixCloud::FileLocations.new
8
+ @file_locations.valid?
9
+ end
10
+
11
+ should "require input" do
12
+ assert_match /input is required/, @file_locations.errors.to_s
13
+ end
14
+
15
+ should "require output" do
16
+ assert_match /output is required/, @file_locations.errors.to_s
17
+ end
18
+ end
19
+
20
+ context "When validating a file locations object with input, output, and watermark objects that are invalid" do
21
+ setup do
22
+ @file_locations = FlixCloud::FileLocations.new(:input => {}, :output => {}, :watermark => {})
23
+ @file_locations.valid?
24
+ end
25
+
26
+ should "inherit the input object's errors" do
27
+ assert @file_locations.errors.any?{|error|
28
+ error.is_a?(Hash) && error[:input] && !error[:input].empty?
29
+ }, "Did not inherit input object's errors"
30
+ end
31
+
32
+ should "inherit the output object's errors" do
33
+ assert @file_locations.errors.any?{|error|
34
+ error.is_a?(Hash) && error[:output] && !error[:output].empty?
35
+ }, "Did not inherit output object's errors"
36
+ end
37
+
38
+ should "inherit the watermark object's errors" do
39
+ assert @file_locations.errors.any?{|error|
40
+ error.is_a?(Hash) && error[:watermark] && !error[:watermark].empty?
41
+ }, "Did not inherit watermark object's errors"
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class FlixCloud::FileTest < Test::Unit::TestCase
4
+
5
+ context "When validating a file object with no attributes set" do
6
+ setup do
7
+ @file = FlixCloud::File.new
8
+ @file.valid?
9
+ end
10
+
11
+ should "require url" do
12
+ assert_match /url is required/, @file.errors.to_s
13
+ end
14
+ end
15
+
16
+ context "When validating a file object with a parameters object that is invalid" do
17
+ setup do
18
+ @file = FlixCloud::File.new(:parameters => {})
19
+ @file.valid?
20
+ end
21
+
22
+ should "inherit the parameters object's errors" do
23
+ assert @file.errors.any?{|error|
24
+ error.is_a?(Hash) && error[:parameters] && !error[:parameters].empty?
25
+ }, "Did not inherit parameters object's errors"
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ class FlixCloud::InputFileTest < Test::Unit::TestCase
4
+ should "do something unique, eventually" do
5
+ end
6
+ end
@@ -0,0 +1,257 @@
1
+ require 'test_helper'
2
+
3
+ class FlixCloud::JobTest < Test::Unit::TestCase
4
+
5
+ context "When validating a job object with no attributes set" do
6
+ setup do
7
+ @job = FlixCloud::Job.new
8
+ @job.valid?
9
+ end
10
+
11
+ should "require an api key" do
12
+ assert_match /api_key is required/, @job.errors.to_s
13
+ end
14
+
15
+ should "require file_locations" do
16
+ assert_match /file_locations is required/, @job.errors.to_s
17
+ end
18
+
19
+ should "require recipe_id" do
20
+ assert_match /recipe_id is required/, @job.errors.to_s
21
+ end
22
+ end
23
+
24
+
25
+ context "When validating a job object with a file_locations object that is invalid" do
26
+ setup do
27
+ @job = FlixCloud::Job.new(:file_locations => {})
28
+ @job.valid?
29
+ end
30
+
31
+ should "inherit the file_locations object's errors" do
32
+ assert @job.errors.any?{|error|
33
+ error.is_a?(Hash) && error[:file_locations] && !error[:file_locations].empty?
34
+ }, "Did not inherit file_locations object's errors"
35
+ end
36
+ end
37
+
38
+
39
+ context "When validating a job object with errors on the deepest nested object possible (parameters)" do
40
+ setup do
41
+ @job = FlixCloud::Job.new(:file_locations => {:input => {:parameters => {}}})
42
+ @job.valid?
43
+ end
44
+
45
+ should "inherit the errors of the deepest nested object possible (parameters)" do
46
+ first_level_errors = @job.errors.find{|error| error.is_a?(Hash) && error[:file_locations] && !error[:file_locations].empty? }[:file_locations]
47
+ second_level_errors = first_level_errors.find{|error| error.is_a?(Hash) && error[:input] && !error[:input].empty? }[:input]
48
+
49
+ assert second_level_errors.any?{|error|
50
+ error.is_a?(Hash) && error[:parameters] && !error[:parameters].empty?
51
+ }, "Did not inherit the errors of the deepest nested object possible (parameters)"
52
+ end
53
+ end
54
+
55
+
56
+ context "A job with no attributes set" do
57
+ setup do
58
+ @job = FlixCloud::Job.new
59
+ end
60
+
61
+ should "serialize to xml, excluding everything but api-key and recipe-id" do
62
+ assert_equal %{<?xml version="1.0" encoding="UTF-8"?><api-request><api-key></api-key><recipe-id></recipe-id></api-request>}, @job.to_xml
63
+ end
64
+ end
65
+
66
+
67
+ context "A job with file_locations set" do
68
+ setup do
69
+ @job = FlixCloud::Job.new(:file_locations => {})
70
+ end
71
+
72
+ should "serialize to xml, excluding everything but api-key, recipe-id, and file-locations" do
73
+ assert_equal %{<?xml version="1.0" encoding="UTF-8"?><api-request><api-key></api-key><recipe-id></recipe-id><file-locations></file-locations></api-request>}, @job.to_xml
74
+ end
75
+ end
76
+
77
+
78
+ context "A job with file_locations and input set" do
79
+ setup do
80
+ @job = FlixCloud::Job.new(:file_locations => {:input => {}})
81
+ end
82
+
83
+ should "serialize to xml, excluding everything but api-key, recipe-id, file-locations, and input" do
84
+ assert_equal %{<?xml version="1.0" encoding="UTF-8"?><api-request><api-key></api-key><recipe-id></recipe-id><file-locations><input><url></url></input></file-locations></api-request>}, @job.to_xml
85
+ end
86
+ end
87
+
88
+
89
+ context "A job with file-locations, input, and input-parameters set" do
90
+ setup do
91
+ @job = FlixCloud::Job.new(:file_locations => {:input => {:parameters => {}}})
92
+ end
93
+
94
+ should "serialize to xml, excluding everything but api-key, recipe-id, file-locations, input, and input-parameters" do
95
+ assert_equal %{<?xml version="1.0" encoding="UTF-8"?><api-request><api-key></api-key><recipe-id></recipe-id><file-locations><input><url></url><parameters><user></user><password></password></parameters></input></file-locations></api-request>}, @job.to_xml
96
+ end
97
+ end
98
+
99
+
100
+ context "A job with all attributes set" do
101
+ setup do
102
+ @job = FlixCloud::Job.new(:recipe_id => 1,
103
+ :api_key => 'this_is_an_api_key',
104
+ :file_locations => { :input => { :url => 'http://flixcloud.com/somefile.mp4',
105
+ :parameters => { :user => 'user',
106
+ :password => 'password'}},
107
+ :output => { :url => 'ftp://flixcloud.com/somefile.mp4',
108
+ :parameters => { :user => 'user',
109
+ :password => 'password'}},
110
+ :watermark => { :url => 'http://flixcloud.com/somefile.mp4',
111
+ :parameters => { :user => 'user',
112
+ :password => 'password'}}})
113
+ end
114
+
115
+ should "serialize everything to xml" do
116
+ assert_equal %{<?xml version="1.0" encoding="UTF-8"?><api-request><api-key>this_is_an_api_key</api-key><recipe-id>1</recipe-id><file-locations><input><url>http://flixcloud.com/somefile.mp4</url><parameters><user>user</user><password>password</password></parameters></input><output><url>ftp://flixcloud.com/somefile.mp4</url><parameters><user>user</user><password>password</password></parameters></output><watermark><url>http://flixcloud.com/somefile.mp4</url><parameters><user>user</user><password>password</password></parameters></watermark></file-locations></api-request>}, @job.to_xml
117
+ end
118
+ end
119
+
120
+
121
+ context "An invalid job when attempting to save" do
122
+ setup do
123
+ @job = FlixCloud::Job.new
124
+ @result = @job.save
125
+ end
126
+
127
+ should "return false" do
128
+ assert_equal false, @result
129
+ end
130
+
131
+ should "set errors on the job" do
132
+ assert @job.errors.is_a?(Array)
133
+ assert_not_equal [], @job.errors
134
+ end
135
+ end
136
+
137
+ context "A valid job when attempting to save" do
138
+ setup do
139
+ FakeWeb.allow_net_connect = false
140
+ @job = FlixCloud::Job.new(:recipe_id => 1,
141
+ :api_key => 'this_is_an_api_key',
142
+ :file_locations => { :input => { :url => 'http://flixcloud.com/somefile.mp4',
143
+ :parameters => { :user => 'user',
144
+ :password => 'password'}},
145
+ :output => { :url => 'ftp://flixcloud.com/somefile.mp4',
146
+ :parameters => { :user => 'user',
147
+ :password => 'password'}},
148
+ :watermark => { :url => 'http://flixcloud.com/somefile.mp4',
149
+ :parameters => { :user => 'user',
150
+ :password => 'password'}}})
151
+ end
152
+
153
+ teardown do
154
+ FakeWeb.clean_registry
155
+ FakeWeb.allow_net_connect = true
156
+ end
157
+
158
+ context "when saving with malformed xml (should really never happen, but what if?)" do
159
+ setup do
160
+ FakeWeb.register_uri(:post, 'https://flixcloud.com/jobs', :string => %{<?xml version="1.0" encoding="UTF-8"?><errors><error>Malformed XML received, please check the syntax of your XML</error></errors>},
161
+ :status => ['400', 'Bad Request'])
162
+ end
163
+
164
+ should "raise a RequestFailed error" do
165
+ assert_raises RestClient::RequestFailed do
166
+ @job.save
167
+ end
168
+ end
169
+ end
170
+
171
+
172
+ context "when saving and the schema doesn't validate (should really never happen, but what if?)" do
173
+ setup do
174
+ FakeWeb.register_uri(:post, 'https://flixcloud.com/jobs', :string => %{<?xml version="1.0" encoding="UTF-8"?><errors><error>You are missing this thing and that thing</error></errors>},
175
+ :status => ['400', 'Bad Request'])
176
+ end
177
+
178
+ should "raise a RequestFailed error" do
179
+ assert_raises RestClient::RequestFailed do
180
+ @job.save
181
+ end
182
+ end
183
+ end
184
+
185
+
186
+ context "when saving and there are errors on the job so it can't be saved" do
187
+ setup do
188
+ FakeWeb.register_uri(:post, 'https://flixcloud.com/jobs', :string => %{<?xml version="1.0" encoding="UTF-8"?><errors><error>You are missing this thing and that thing</error></errors>},
189
+ :status => ['200', 'OK'])
190
+ end
191
+
192
+ should "return false" do
193
+ assert_equal false, @job.save
194
+ end
195
+
196
+ should "set the jobs errors to the response body's errors" do
197
+ @job.save
198
+ assert_equal ["You are missing this thing and that thing"], @job.errors
199
+ end
200
+ end
201
+
202
+ context "when saving was successful" do
203
+ setup do
204
+ FakeWeb.register_uri(:post, 'https://flixcloud.com/jobs', :string => %{<?xml version="1.0" encoding="UTF-8"?><job><id type="integer">1</id><initialized-job-at type="datetime">2009-04-07T23:15:33+02:00</initialized-job-at></job>},
205
+ :status => ['200', 'OK'])
206
+ end
207
+
208
+ should "return true" do
209
+ assert_equal true, @job.save
210
+ end
211
+
212
+ should "save the id from the response on the job" do
213
+ @job.save
214
+ assert_equal 1, @job.id
215
+ end
216
+
217
+ should "save the initialization time from the response on the job" do
218
+ @job.save
219
+ assert_equal "Tue Apr 07 21:15:33 UTC 2009", @job.initialized_at.to_s
220
+ end
221
+ end
222
+ end
223
+
224
+ context "When using shortcut attributes for job initialization" do
225
+ setup do
226
+ @job = FlixCloud::Job.new(:api_key => 'your-api-key',
227
+ :recipe_id => 2,
228
+ :input_url => 'your-input-url',
229
+ :input_user => 'your-input-user',
230
+ :input_password => 'your-input-password',
231
+ :output_url => 'your-output-url',
232
+ :output_user => 'your-output-user',
233
+ :output_password => 'your-output-password',
234
+ :watermark_url => 'your-watermark-url',
235
+ :watermark_user => 'your-watermark-user',
236
+ :watermark_password => 'your-watermark-password')
237
+ end
238
+
239
+ should "set the urls" do
240
+ assert_equal 'your-input-url', @job.file_locations.input.url
241
+ assert_equal 'your-output-url', @job.file_locations.output.url
242
+ assert_equal 'your-watermark-url', @job.file_locations.watermark.url
243
+ end
244
+
245
+ should "set the users" do
246
+ assert_equal 'your-input-user', @job.file_locations.input.parameters.user
247
+ assert_equal 'your-output-user', @job.file_locations.output.parameters.user
248
+ assert_equal 'your-watermark-user', @job.file_locations.watermark.parameters.user
249
+ end
250
+
251
+ should "set the passwords" do
252
+ assert_equal 'your-input-password', @job.file_locations.input.parameters.password
253
+ assert_equal 'your-output-password', @job.file_locations.output.parameters.password
254
+ assert_equal 'your-watermark-password', @job.file_locations.watermark.parameters.password
255
+ end
256
+ end
257
+ end
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ class FlixCloud::OutputFileTest < Test::Unit::TestCase
4
+ should "do something unique, eventually" do
5
+ end
6
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class FlixCloud::ParametersTest < Test::Unit::TestCase
4
+
5
+ context "When validating a parameters object with no attributes set" do
6
+ setup do
7
+ @parameters = FlixCloud::Parameters.new
8
+ @parameters.valid?
9
+ end
10
+
11
+ should "require user" do
12
+ assert_match /user is required/, @parameters.errors.to_s
13
+ end
14
+
15
+ should "require password" do
16
+ assert_match /password is required/, @parameters.errors.to_s
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ class FlixCloud::BogusRecordTestClass < FlixCloud::Record
4
+ record_column :bogus_record_test_child, 'BogusRecordTestChildClass'
5
+ end
6
+
7
+ class FlixCloud::BogusRecordTestChildClass < FlixCloud::Record
8
+ attr_accessor :bogus_attribute
9
+ end
10
+
11
+ class FlixCloud::RecordTest < Test::Unit::TestCase
12
+
13
+ context "With a record object initialized with no options" do
14
+ setup do
15
+ @record = FlixCloud::Record.new
16
+ end
17
+
18
+ should "intialize errors to an empty array" do
19
+ assert_equal [], @record.errors
20
+ end
21
+ end
22
+
23
+ context "With a record object initialized with options" do
24
+ setup do
25
+ @record = FlixCloud::Record.new(:errors => 'will be set, but', :bad_attributes => 'will not be set')
26
+ end
27
+
28
+ should "set the values of attributes that have attr_writers" do
29
+ assert_equal 'will be set, but', @record.errors
30
+ end
31
+ end
32
+
33
+ context "With a bogus class has a record column and has been initialized with attributes" do
34
+ setup do
35
+ @bogus_record = FlixCloud::BogusRecordTestClass.new(:bogus_record_test_child => {:bogus_attribute => 'bogus value'})
36
+ end
37
+
38
+ should "initialize both the parent class and the child class appropriately, assigning to the child attributes" do
39
+ assert_not_nil @bogus_record
40
+ assert @bogus_record.bogus_record_test_child.is_a?(FlixCloud::BogusRecordTestChildClass)
41
+ assert_equal 'bogus value', @bogus_record.bogus_record_test_child.bogus_attribute
42
+ end
43
+
44
+ should "update the child attributes when assigning to the parent's child object attribute (confusing?)" do
45
+ @bogus_record.bogus_record_test_child = {:bogus_attribute => 'a new bogus value'}
46
+ assert_equal 'a new bogus value', @bogus_record.bogus_record_test_child.bogus_attribute
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ class FlixCloud::ResponseTest < Test::Unit::TestCase
4
+
5
+ context "A response initialized with a rest client response" do
6
+ setup do
7
+ @rest_client_response = stub_rest_client_response(200, '<?xml version="1.0" encoding="UTF-8"?><something>wonderful</something>')
8
+ @response = FlixCloud::Response.new(@rest_client_response)
9
+ end
10
+
11
+ should "store code in the code attribute" do
12
+ assert_equal @rest_client_response.code, @response.code
13
+ end
14
+
15
+ should "store the body of the message in the body attribute" do
16
+ assert_equal @rest_client_response.to_s, @response.body
17
+ end
18
+
19
+ should "store body converted to a hash in the body_as_hash attribute" do
20
+ assert_equal Crack::XML.parse(@rest_client_response.to_s), @response.body_as_hash
21
+ end
22
+
23
+ should "initialize errors to an empty array" do
24
+ assert_equal [], @response.errors
25
+ end
26
+ end
27
+
28
+ context "A response initialized with a rest client response with a blank message body" do
29
+ setup do
30
+ @response = FlixCloud::Response.new(stub_rest_client_response(200, ''))
31
+ end
32
+
33
+ should "be successful" do
34
+ assert @response.success?
35
+ end
36
+
37
+ should "have a blank array for the errors attribute" do
38
+ assert_equal [], @response.errors
39
+ end
40
+ end
41
+
42
+ context "A response initialized with a rest client response with a message body of errors" do
43
+ setup do
44
+ @response = FlixCloud::Response.new(stub_rest_client_response(200, '<?xml version="1.0" encoding="UTF-8"?><errors><error>There was an error doing something</error></errors>'))
45
+ end
46
+
47
+ should "not be successful" do
48
+ assert !@response.success?
49
+ end
50
+
51
+ should "store the errors in the errors attribute" do
52
+ assert_equal ['There was an error doing something'], @response.errors
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ class FlixCloud::WatermarkFileTest < Test::Unit::TestCase
4
+ should "do something unique, eventually" do
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+ require 'fakeweb'
6
+
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
+ require 'flix_cloud'
10
+
11
+ class Test::Unit::TestCase
12
+ def stub_rest_client_response(code, body)
13
+ stub(:code => code, :to_s => body)
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zencoder-flix_cloud-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Sutton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-07 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: builder
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: crack
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.1
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rest-client
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.2
44
+ version:
45
+ description:
46
+ email: nate@sevenwire.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.markdown
54
+ files:
55
+ - LICENSE
56
+ - README.markdown
57
+ - Rakefile
58
+ - lib/flix_cloud.rb
59
+ - lib/flix_cloud/extensions/hash.rb
60
+ - lib/flix_cloud/file.rb
61
+ - lib/flix_cloud/file_locations.rb
62
+ - lib/flix_cloud/input_file.rb
63
+ - lib/flix_cloud/job.rb
64
+ - lib/flix_cloud/output_file.rb
65
+ - lib/flix_cloud/parameters.rb
66
+ - lib/flix_cloud/record.rb
67
+ - lib/flix_cloud/response.rb
68
+ - lib/flix_cloud/watermark_file.rb
69
+ - test/flix_cloud/file_locations_test.rb
70
+ - test/flix_cloud/file_test.rb
71
+ - test/flix_cloud/input_file_test.rb
72
+ - test/flix_cloud/job_test.rb
73
+ - test/flix_cloud/output_files_test.rb
74
+ - test/flix_cloud/parameters_test.rb
75
+ - test/flix_cloud/record_test.rb
76
+ - test/flix_cloud/response_test.rb
77
+ - test/flix_cloud/watermark_file_test.rb
78
+ - test/test_helper.rb
79
+ has_rdoc: true
80
+ homepage: http://github.com/zencoder/flix_cloud-gem
81
+ post_install_message:
82
+ rdoc_options:
83
+ - --charset=UTF-8
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.2.0
102
+ signing_key:
103
+ specification_version: 2
104
+ summary: Gem for integrating with http://flixcloud.com
105
+ test_files:
106
+ - test/flix_cloud/file_locations_test.rb
107
+ - test/flix_cloud/file_test.rb
108
+ - test/flix_cloud/input_file_test.rb
109
+ - test/flix_cloud/job_test.rb
110
+ - test/flix_cloud/output_files_test.rb
111
+ - test/flix_cloud/parameters_test.rb
112
+ - test/flix_cloud/record_test.rb
113
+ - test/flix_cloud/response_test.rb
114
+ - test/flix_cloud/watermark_file_test.rb
115
+ - test/test_helper.rb