zencoder-flix_cloud-gem 0.1.1 → 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/VERSION.yml +2 -2
- data/lib/flix_cloud/exceptions.rb +5 -3
- data/lib/flix_cloud/job.rb +14 -5
- data/lib/flix_cloud/record.rb +8 -3
- data/test/flix_cloud/job_test.rb +53 -8
- metadata +2 -2
data/VERSION.yml
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
-
class FlixCloud::
|
2
|
-
|
3
|
-
class FlixCloud::CreateError <
|
1
|
+
class FlixCloud::Error < StandardError; end
|
2
|
+
class FlixCloud::SaveError < FlixCloud::Error; end
|
3
|
+
class FlixCloud::CreateError < FlixCloud::Error; end
|
4
|
+
class FlixCloud::Unauthorized < FlixCloud::Error; end
|
5
|
+
class FlixCloud::RequestFailed < FlixCloud::Error; end
|
data/lib/flix_cloud/job.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class FlixCloud::Job < FlixCloud::Record
|
2
2
|
|
3
|
-
attr_accessor :id, :initialized_at, :api_key, :recipe_id, :response
|
3
|
+
attr_accessor :id, :initialized_at, :api_key, :recipe_id, :recipe_name, :response
|
4
4
|
|
5
5
|
record_column :file_locations, 'FileLocations'
|
6
6
|
|
@@ -20,8 +20,12 @@ class FlixCloud::Job < FlixCloud::Record
|
|
20
20
|
self.errors << "file_locations is required"
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
if recipe_id || recipe_name
|
24
|
+
if recipe_id && recipe_name
|
25
|
+
self.errors << "recipe_id and recipe_name cannot both be used"
|
26
|
+
end
|
27
|
+
else
|
28
|
+
self.errors << "recipe_id or recipe_name is required"
|
25
29
|
end
|
26
30
|
|
27
31
|
unless api_key
|
@@ -34,7 +38,7 @@ class FlixCloud::Job < FlixCloud::Record
|
|
34
38
|
def save
|
35
39
|
return false unless valid?
|
36
40
|
|
37
|
-
self.response =
|
41
|
+
self.response = post('jobs', to_xml)
|
38
42
|
|
39
43
|
if response.success?
|
40
44
|
self.id = response.body_as_hash['job']['id']
|
@@ -70,7 +74,12 @@ class FlixCloud::Job < FlixCloud::Record
|
|
70
74
|
|
71
75
|
xml.tag!("api-request") do
|
72
76
|
xml.tag!("api-key", api_key)
|
73
|
-
|
77
|
+
|
78
|
+
if recipe_name
|
79
|
+
xml.tag!("recipe-name", recipe_name)
|
80
|
+
else
|
81
|
+
xml.tag!("recipe-id", recipe_id)
|
82
|
+
end
|
74
83
|
|
75
84
|
if file_locations
|
76
85
|
xml.tag!("file-locations") do
|
data/lib/flix_cloud/record.rb
CHANGED
@@ -30,9 +30,14 @@ class FlixCloud::Record
|
|
30
30
|
protected
|
31
31
|
|
32
32
|
def post(path, body)
|
33
|
-
|
34
|
-
"https://flixcloud.com/#{path}",
|
35
|
-
|
33
|
+
begin
|
34
|
+
FlixCloud::Response.new(RestClient::Resource.new("https://flixcloud.com/#{path}",
|
35
|
+
:verify_ssl => OpenSSL::SSL::VERIFY_PEER).post(body, :content_type => 'application/xml', :accept => 'application/xml'))
|
36
|
+
rescue RestClient::Unauthorized
|
37
|
+
raise FlixCloud::Unauthorized
|
38
|
+
rescue RestClient::RequestFailed
|
39
|
+
raise FlixCloud::RequestFailed
|
40
|
+
end
|
36
41
|
end
|
37
42
|
|
38
43
|
end
|
data/test/flix_cloud/job_test.rb
CHANGED
@@ -16,8 +16,20 @@ class FlixCloud::JobTest < Test::Unit::TestCase
|
|
16
16
|
assert_match /file_locations is required/, @job.errors.to_s
|
17
17
|
end
|
18
18
|
|
19
|
-
should "require recipe_id" do
|
20
|
-
assert_match /recipe_id is required/, @job.errors.to_s
|
19
|
+
should "require recipe_id or recipe_name" do
|
20
|
+
assert_match /recipe_id or recipe_name is required/, @job.errors.to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
context "When validating a job object with both recipe_id and recipe_name are set" do
|
26
|
+
setup do
|
27
|
+
@job = FlixCloud::Job.new(:recipe_name => 'recipe-name', :recipe_id => 1)
|
28
|
+
@job.valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
should "require that both recipe_id and recipe_name cannot be used" do
|
32
|
+
assert_match /recipe_id and recipe_name cannot both be used/, @job.errors.to_s
|
21
33
|
end
|
22
34
|
end
|
23
35
|
|
@@ -97,6 +109,28 @@ class FlixCloud::JobTest < Test::Unit::TestCase
|
|
97
109
|
end
|
98
110
|
|
99
111
|
|
112
|
+
context "A job with recipe_id set" do
|
113
|
+
setup do
|
114
|
+
@job = FlixCloud::Job.new(:recipe_id => 1)
|
115
|
+
end
|
116
|
+
|
117
|
+
should "serialize to xml and include the recipe_id, not the recipe_name" do
|
118
|
+
assert_equal %{<?xml version="1.0" encoding="UTF-8"?><api-request><api-key></api-key><recipe-id>1</recipe-id></api-request>}, @job.to_xml
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
context "A job with a recipe_name set" do
|
124
|
+
setup do
|
125
|
+
@job = FlixCloud::Job.new(:recipe_name => 'recipe-name')
|
126
|
+
end
|
127
|
+
|
128
|
+
should "serialize to xml and include the recipe_name, not the recipe_id" do
|
129
|
+
assert_equal %{<?xml version="1.0" encoding="UTF-8"?><api-request><api-key></api-key><recipe-name>recipe-name</recipe-name></api-request>}, @job.to_xml
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
100
134
|
context "A job with all attributes set" do
|
101
135
|
setup do
|
102
136
|
@job = FlixCloud::Job.new(:recipe_id => 1,
|
@@ -157,12 +191,11 @@ class FlixCloud::JobTest < Test::Unit::TestCase
|
|
157
191
|
|
158
192
|
context "when saving with malformed xml (should really never happen, but what if?)" do
|
159
193
|
setup do
|
160
|
-
FakeWeb.register_uri(:post, 'https://flixcloud.com/jobs', :
|
161
|
-
:status => ['400', 'Bad Request'])
|
194
|
+
FakeWeb.register_uri(:post, 'https://flixcloud.com/jobs', :status => ['400', 'Bad Request'])
|
162
195
|
end
|
163
196
|
|
164
197
|
should "raise a RequestFailed error" do
|
165
|
-
assert_raises
|
198
|
+
assert_raises FlixCloud::RequestFailed do
|
166
199
|
@job.save
|
167
200
|
end
|
168
201
|
end
|
@@ -171,12 +204,24 @@ class FlixCloud::JobTest < Test::Unit::TestCase
|
|
171
204
|
|
172
205
|
context "when saving and the schema doesn't validate (should really never happen, but what if?)" do
|
173
206
|
setup do
|
174
|
-
FakeWeb.register_uri(:post, 'https://flixcloud.com/jobs', :
|
175
|
-
:status => ['400', 'Bad Request'])
|
207
|
+
FakeWeb.register_uri(:post, 'https://flixcloud.com/jobs', :status => ['400', 'Bad Request'])
|
176
208
|
end
|
177
209
|
|
178
210
|
should "raise a RequestFailed error" do
|
179
|
-
assert_raises
|
211
|
+
assert_raises FlixCloud::RequestFailed do
|
212
|
+
@job.save
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
context "when saving and the api-key is not valid" do
|
219
|
+
setup do
|
220
|
+
FakeWeb.register_uri(:post, 'https://flixcloud.com/jobs', :status => ['401', 'Unauthorized'])
|
221
|
+
end
|
222
|
+
|
223
|
+
should "raise an Unauthorized error" do
|
224
|
+
assert_raises FlixCloud::Unauthorized do
|
180
225
|
@job.save
|
181
226
|
end
|
182
227
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zencoder-flix_cloud-gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Sutton
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-09 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|