telestream_cloud 1.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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +357 -0
- data/Rakefile +9 -0
- data/lib/telestream_cloud.rb +30 -0
- data/lib/telestream_cloud/api_authentication.rb +66 -0
- data/lib/telestream_cloud/base.rb +111 -0
- data/lib/telestream_cloud/config.rb +87 -0
- data/lib/telestream_cloud/connection.rb +101 -0
- data/lib/telestream_cloud/errors.rb +17 -0
- data/lib/telestream_cloud/faraday.rb +84 -0
- data/lib/telestream_cloud/flip.rb +9 -0
- data/lib/telestream_cloud/modules/associations.rb +55 -0
- data/lib/telestream_cloud/modules/builders.rb +45 -0
- data/lib/telestream_cloud/modules/destroyers.rb +25 -0
- data/lib/telestream_cloud/modules/factory_connection.rb +7 -0
- data/lib/telestream_cloud/modules/finders.rb +68 -0
- data/lib/telestream_cloud/modules/router.rb +62 -0
- data/lib/telestream_cloud/modules/updatable.rb +31 -0
- data/lib/telestream_cloud/modules/video_state.rb +16 -0
- data/lib/telestream_cloud/proxies/encoding_scope.rb +56 -0
- data/lib/telestream_cloud/proxies/profile_scope.rb +7 -0
- data/lib/telestream_cloud/proxies/proxy.rb +27 -0
- data/lib/telestream_cloud/proxies/scope.rb +94 -0
- data/lib/telestream_cloud/proxies/video_scope.rb +28 -0
- data/lib/telestream_cloud/resources/encoding.rb +47 -0
- data/lib/telestream_cloud/resources/factory.rb +72 -0
- data/lib/telestream_cloud/resources/profile.rb +22 -0
- data/lib/telestream_cloud/resources/resource.rb +48 -0
- data/lib/telestream_cloud/resources/video.rb +39 -0
- data/lib/telestream_cloud/telestream_cloud.rb +69 -0
- data/lib/telestream_cloud/upload_session.rb +102 -0
- data/lib/telestream_cloud/version.rb +3 -0
- data/spec/cloud_spec.rb +132 -0
- data/spec/encoding_spec.rb +260 -0
- data/spec/heroku_spec.rb +32 -0
- data/spec/panda_spec.rb +206 -0
- data/spec/profile_spec.rb +117 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/video_spec.rb +399 -0
- data/telestream_cloud.gemspec +30 -0
- metadata +191 -0
@@ -0,0 +1,260 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe TelestreamCloud::Encoding do
|
4
|
+
before(:each) do
|
5
|
+
|
6
|
+
TelestreamCloud.configure do
|
7
|
+
access_key "my_access_key"
|
8
|
+
secret_key "my_secret_key"
|
9
|
+
api_host "api.example.com"
|
10
|
+
factory_id 'my_cloud_id'
|
11
|
+
api_port 85
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should find by video_id" do
|
17
|
+
encoding_json = "[{\"abc\":\"efg\",\"id\":456}]"
|
18
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).
|
19
|
+
to_return(:body => encoding_json)
|
20
|
+
TelestreamCloud::Encoding.find_all_by_video_id("123").first.id.should == 456
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should create an encoding using instance method" do
|
24
|
+
encoding_json = "{\"source_url\":\"my_source_url\",\"id\":\"456\"}"
|
25
|
+
stub_http_request(:post, /api.example.com:85\/v3.0\/encodings.json/).
|
26
|
+
with(:body => /source_url=my_source_url/).
|
27
|
+
to_return(:body => encoding_json)
|
28
|
+
|
29
|
+
encoding = TelestreamCloud::Encoding.new(:source_url => "my_source_url", :video_id => "123")
|
30
|
+
encoding.create.should == true
|
31
|
+
encoding.id.should == "456"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should find by encoding_id" do
|
35
|
+
encoding_json = "{\"abc\":\"efg\",\"id\":\"456\"}"
|
36
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/encodings\/456.json/).
|
37
|
+
to_return(:body => encoding_json)
|
38
|
+
encoding = TelestreamCloud::Encoding.find("456")
|
39
|
+
encoding.id.should == "456"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should find by the video through the association" do
|
43
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
44
|
+
encoding_json = "{\"abc\":\"efg\",\"id\":\"456\", \"video_id\":\"123\"}"
|
45
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/encodings\/456.json/).
|
46
|
+
to_return(:body => encoding_json)
|
47
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).
|
48
|
+
to_return(:body => video_json)
|
49
|
+
encoding = TelestreamCloud::Encoding.find("456")
|
50
|
+
encoding.video.id.should == "123"
|
51
|
+
encoding.id.should == "456"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should filter on find" do
|
55
|
+
encoding_json = "[{\"source_url\":\"my_source_url\",\"id\":\"456\"}]"
|
56
|
+
|
57
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/encodings.json/).
|
58
|
+
with{|r| r.uri.query =~ /profile_name=my_profile/ && r.uri.query =~ /video_id=123/ }.
|
59
|
+
to_return(:body => encoding_json)
|
60
|
+
|
61
|
+
encodings = TelestreamCloud::Encoding.all(:video_id => "123", :profile_name => "my_profile")
|
62
|
+
encodings.first.id.should == "456"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return the encoding url" do
|
66
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
67
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/factories\/my_cloud_id.json/).
|
68
|
+
to_return(:body => cloud_json)
|
69
|
+
|
70
|
+
encoding = TelestreamCloud::Encoding.new({:id => "456", :extname => ".ext", :path => "abc/panda", "files" => ["abc/panda.ext"], :status => 'success'})
|
71
|
+
encoding.url.should == "http://my-bucket.s3.amazonaws.com/abc/panda.ext"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return the secure encoding url" do
|
75
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
76
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/factories\/my_cloud_id.json/).
|
77
|
+
to_return(:body => cloud_json)
|
78
|
+
|
79
|
+
encoding = TelestreamCloud::Encoding.new({:id => "456", :extname => ".ext", :path => "abc/panda", "files" => ["abc/panda.ext"], :status => 'success'})
|
80
|
+
encoding.url(:https => true).should == "https://my-bucket.s3.amazonaws.com/abc/panda.ext"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should generate a screenshot array" do
|
84
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
85
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/factories\/my_cloud_id.json/).
|
86
|
+
to_return(:body => cloud_json)
|
87
|
+
|
88
|
+
encoding = TelestreamCloud::Encoding.new({:id => "456", :extname => ".ext", :status => "success", :path => "abc/panda"})
|
89
|
+
encoding.screenshots[0].should == "http://my-bucket.s3.amazonaws.com/abc/panda_1.jpg"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should generate a screenshot array" do
|
93
|
+
encoding = TelestreamCloud::Encoding.new({:id => "456", :extname => ".ext", :status => "fail"})
|
94
|
+
encoding.screenshots.should == []
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
it "should create an encoding through the association" do
|
99
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
100
|
+
encoding_json = "{\"abc\":\"efg\",\"id\":\"456\", \"video_id\":\"123\", \"profile_id\":\"901\"}"
|
101
|
+
|
102
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).
|
103
|
+
to_return(:body => video_json)
|
104
|
+
|
105
|
+
stub_http_request(:post, /api.example.com:85\/v3.0\/encodings.json/).
|
106
|
+
with{|r| r.body =~ /video_id=123/ && r.body =~ /profile_id=901/}.
|
107
|
+
to_return(:body => encoding_json)
|
108
|
+
|
109
|
+
video = TelestreamCloud::Video.find("123")
|
110
|
+
|
111
|
+
encoding = video.encodings.create(:profile_id => "901")
|
112
|
+
encoding.id.should == "456"
|
113
|
+
encoding.profile_id.should == "901"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should create an encoding through the association" do
|
117
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
118
|
+
encoding_json = "{\"abc\":\"efg\",\"id\":\"456\", \"video_id\":\"123\", \"profile_id\":\"901\"}"
|
119
|
+
|
120
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).
|
121
|
+
to_return(:body => video_json)
|
122
|
+
|
123
|
+
stub_http_request(:post, /api.example.com:85\/v3.0\/encodings.json/).
|
124
|
+
with{|r| r.body =~ /video_id=123/ && r.body =~ /profile_id=901/}.
|
125
|
+
to_return(:body => encoding_json)
|
126
|
+
|
127
|
+
video = TelestreamCloud::Video.find("123")
|
128
|
+
|
129
|
+
encoding = video.encodings.create!(:profile_id => "901")
|
130
|
+
encoding.id.should == "456"
|
131
|
+
encoding.profile_id.should == "901"
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
it "should filter the profile name after triggering the request" do
|
136
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
137
|
+
encodings_1_json = "[{\"id\":\"456\", \"video_id\":\"123\", \"profile_name\":\"h264\"}]"
|
138
|
+
encodings_2_json = "[{\"id\":\"789\", \"video_id\":\"123\", \"profile_name\":\"ogg\"}]"
|
139
|
+
|
140
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).
|
141
|
+
to_return(:body => video_json)
|
142
|
+
|
143
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).
|
144
|
+
with{|r| r.uri.query =~ /profile_name=h264/ }.
|
145
|
+
to_return(:body => encodings_1_json)
|
146
|
+
|
147
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).
|
148
|
+
with{|r| r.uri.query =~ /profile_name=ogg/ }.
|
149
|
+
to_return(:body => encodings_2_json)
|
150
|
+
|
151
|
+
video = TelestreamCloud::Video.find("123")
|
152
|
+
video.encodings.find_by_profile_name("h264").id.should == "456"
|
153
|
+
video.encodings.find_by_profile_name("ogg").id.should == "789"
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should create an encoding through the association" do
|
157
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
158
|
+
encodings_json = "[{\"abc\":\"efg\",\"id\":\"456\", \"video_id\":\"123\", \"profile_id\":\"901\"}]"
|
159
|
+
|
160
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).
|
161
|
+
to_return(:body => video_json)
|
162
|
+
|
163
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).
|
164
|
+
with{|r| r.uri.query =~ /profile_id=901/}.
|
165
|
+
to_return(:body => encodings_json)
|
166
|
+
|
167
|
+
video = TelestreamCloud::Video.find("123")
|
168
|
+
encodings = video.encodings.all(:profile_id => "901")
|
169
|
+
encodings.first.id = "456"
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should create an encoding through the association" do
|
173
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
174
|
+
encodings_json = "[{\"abc\":\"efg\",\"id\":\"456\", \"video_id\":\"123\", \"profile_id\":\"901\"}]"
|
175
|
+
|
176
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).
|
177
|
+
to_return(:body => video_json)
|
178
|
+
|
179
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).
|
180
|
+
with{|r| r.uri.query =~ /profile_id=901/}.
|
181
|
+
to_return(:body => encodings_json)
|
182
|
+
|
183
|
+
video = TelestreamCloud::Video.find("123")
|
184
|
+
encodings = video.encodings.profile("901")
|
185
|
+
encodings.first.id = "456"
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should filter encodings specifying video and status as a method" do
|
189
|
+
encoding_json = "[{\"source_url\":\"my_source_url\",\"id\":\"456\"}]"
|
190
|
+
|
191
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/encodings.json/).
|
192
|
+
with{|r| r.uri.query =~ /status=success/ && r.uri.query =~ /video_id=123/ }.
|
193
|
+
to_return(:body => encoding_json)
|
194
|
+
|
195
|
+
encodings = TelestreamCloud::Encoding.video(123).status("success").all
|
196
|
+
encodings.first.id.should == "456"
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should filter encodings specifying video and status as a method" do
|
200
|
+
encoding_json = "[{\"source_url\":\"my_source_url\",\"id\":\"456\"}]"
|
201
|
+
|
202
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/encodings.json/).
|
203
|
+
with{|r| r.uri.query =~ /profile_id=prof_1/ && r.uri.query =~ /video_id=123/ }.
|
204
|
+
to_return(:body => encoding_json)
|
205
|
+
|
206
|
+
encodings = TelestreamCloud::Encoding.video(123).profile("prof_1").all
|
207
|
+
encodings.first.id.should == "456"
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should filter encodings specifying video and profile id as a method" do
|
211
|
+
encoding_json = "[{\"source_url\":\"my_source_url\",\"id\":\"456\"}]"
|
212
|
+
|
213
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/encodings.json/).
|
214
|
+
with{|r| r.uri.query =~ /profile_name=prof_name/ && r.uri.query =~ /video_id=123/ }.
|
215
|
+
to_return(:body => encoding_json)
|
216
|
+
|
217
|
+
encodings = TelestreamCloud::Encoding.video(123).profile_name("prof_name").all
|
218
|
+
encodings.first.id.should == "456"
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should find an encoding" do
|
222
|
+
encoding_json = "[{\"source_url\":\"my_source_url\",\"id\":\"456\"}]"
|
223
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/encodings\/456.json/).
|
224
|
+
to_return(:body => encoding_json)
|
225
|
+
|
226
|
+
TelestreamCloud::Encoding.find("456")
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should tell if the encoding is success" do
|
230
|
+
encoding = TelestreamCloud::Encoding.new({:status => "success"})
|
231
|
+
encoding.success?.should == true
|
232
|
+
encoding.processing?.should == false
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should tell if the encoding is success" do
|
236
|
+
encoding = TelestreamCloud::Encoding.new({:status => "processing"})
|
237
|
+
encoding.success?.should == false
|
238
|
+
encoding.processing?.should == true
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should tell if the encoding is success" do
|
242
|
+
encoding = TelestreamCloud::Encoding.new({:status => "fail"})
|
243
|
+
encoding.success?.should == false
|
244
|
+
encoding.fail?.should == true
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should return the most recent updated encoding" do
|
248
|
+
video_json = "[{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}]"
|
249
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/encodings.json/).
|
250
|
+
with{|r| r.uri.query =~ /per_page=1/ }.
|
251
|
+
to_return(:body => video_json)
|
252
|
+
TelestreamCloud::Encoding.first
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should not delegate scope if the method do not really exist in the scope" do
|
256
|
+
lambda {TelestreamCloud::Encoding.reload}.should raise_error(NoMethodError)
|
257
|
+
lambda {TelestreamCloud::Encoding.each}.should raise_error(NoMethodError)
|
258
|
+
lambda {TelestreamCloud::Encoding.size}.should raise_error(NoMethodError)
|
259
|
+
end
|
260
|
+
end
|
data/spec/heroku_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe TelestreamCloud::Video do
|
4
|
+
before(:each) do
|
5
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\"}"
|
6
|
+
stub_http_request(:get, /api.example.com:443\/v2\/factories\/my_cloud_id.json/).
|
7
|
+
to_return(:body => cloud_json)
|
8
|
+
|
9
|
+
my_heroku_url = "http://access_key:secret_key@api.example.com:443/my_cloud_id"
|
10
|
+
ENV['PANDASTREAM_URL']= my_heroku_url
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should get all videos" do
|
14
|
+
TelestreamCloud.configure_heroku
|
15
|
+
|
16
|
+
videos_json = "[]"
|
17
|
+
stub_http_request(:get, /api.example.com:443\/v3.0\/videos.json/).to_return(:body => videos_json)
|
18
|
+
|
19
|
+
TelestreamCloud::Video.all.should be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should get all videos" do
|
23
|
+
TelestreamCloud.configure ENV['PANDASTREAM_URL']
|
24
|
+
|
25
|
+
videos_json = "[]"
|
26
|
+
stub_http_request(:get, /api.example.com:443\/v3.0\/videos.json/).to_return(:body => videos_json)
|
27
|
+
|
28
|
+
TelestreamCloud::Video.all.should be_empty
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
data/spec/panda_spec.rb
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'timecop'
|
3
|
+
|
4
|
+
describe TelestreamCloud do
|
5
|
+
before(:each) do
|
6
|
+
new_time = Time.utc(2010, 1, 12, 1, 0, 0)
|
7
|
+
Timecop.freeze(new_time)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "when not connected" do
|
11
|
+
|
12
|
+
["get", "post", "put", "delete"].each do |method|
|
13
|
+
it "should raise error for #{method}" do
|
14
|
+
lambda {
|
15
|
+
TelestreamCloud.send(method, nil, nil)
|
16
|
+
}.should raise_error(TelestreamCloud::ConfigurationError, "Telestream Cloud is not configured!")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "root configuration with hash" do
|
23
|
+
it "should not fail is access_key and secret_key are given" do
|
24
|
+
proc do
|
25
|
+
TelestreamCloud.configure({:access_key => "bar", :secret_key => "baz"})
|
26
|
+
end.should_not raise_error(TelestreamCloud::ConfigurationError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should fail if access_key or secret_key are missing" do
|
30
|
+
proc do
|
31
|
+
TelestreamCloud.configure({:secret_key => "baz"})
|
32
|
+
end.should raise_error(TelestreamCloud::ConfigurationError)
|
33
|
+
proc do
|
34
|
+
TelestreamCloud.configure({:access_key => "bar"})
|
35
|
+
end.should raise_error(TelestreamCloud::ConfigurationError)
|
36
|
+
proc do
|
37
|
+
TelestreamCloud.configure({})
|
38
|
+
end.should raise_error(TelestreamCloud::ConfigurationError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "root configuration with block" do
|
43
|
+
it "should not fail is access_key and secret_key are given" do
|
44
|
+
proc do
|
45
|
+
TelestreamCloud.configure do
|
46
|
+
access_key "bar"
|
47
|
+
secret_key "baz"
|
48
|
+
end
|
49
|
+
end.should_not raise_error(TelestreamCloud::ConfigurationError)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should fail if access_key or secret_key are missing" do
|
53
|
+
proc do
|
54
|
+
TelestreamCloud.configure do
|
55
|
+
secret_key "baz"
|
56
|
+
end
|
57
|
+
end.should raise_error(TelestreamCloud::ConfigurationError)
|
58
|
+
proc do
|
59
|
+
TelestreamCloud.configure do
|
60
|
+
access_key "bar"
|
61
|
+
end
|
62
|
+
end.should raise_error(TelestreamCloud::ConfigurationError)
|
63
|
+
proc do
|
64
|
+
TelestreamCloud.configure do
|
65
|
+
end
|
66
|
+
end.should raise_error(TelestreamCloud::ConfigurationError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
shared_examples_for "Connected" do
|
71
|
+
|
72
|
+
it "should make get request with signed request to panda server" do
|
73
|
+
stub_http_request(:get, "http://myapihost:85/v3.0/videos?access_key=my_access_key&factory_id=my_cloud_id&signature=ArhKqAFUwLQl9RhSmnOv5L2CMWhr0ZFOxA0B9IKIg8I=×tamp=2010-01-12T01%3A00%3A00.000000Z").to_return(:body => "{\"abc\":\"d\"}")
|
74
|
+
@tc.get("/videos").should == {'abc' => 'd'}
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should create a signed version of the parameters" do
|
78
|
+
signed_params = @tc.signed_params('POST',
|
79
|
+
'/videos.json',
|
80
|
+
{"param1" => 'one', "param2" => 'two'}
|
81
|
+
)
|
82
|
+
signed_params.should == {
|
83
|
+
'access_key' => "my_access_key",
|
84
|
+
'timestamp' => "2010-01-12T01:00:00.000000Z",
|
85
|
+
'factory_id' => 'my_cloud_id',
|
86
|
+
'signature' => 'A/7DSazLSnr8wiX2QUKCWE3C1IXAAdIpEcnFF4Qc8Rw=',
|
87
|
+
'param1' => 'one',
|
88
|
+
'param2' => 'two'
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should create a signed version of the parameters without additional arguments" do
|
93
|
+
@tc.signed_params('POST', '/videos.json').should == {
|
94
|
+
'access_key' => "my_access_key",
|
95
|
+
'timestamp' => "2010-01-12T01:00:00.000000Z",
|
96
|
+
'factory_id' => 'my_cloud_id',
|
97
|
+
'signature' => 'Ne/W+cvZAZ4yE70PcXgLbPieGrwdaCX9WPUCQeJBPhs='
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
it "should create a signed version of the parameters and difficult characters" do
|
103
|
+
signed_params = @tc.signed_params('POST',
|
104
|
+
'/videos.json',
|
105
|
+
{"tilde" => '~', "space" => ' '}
|
106
|
+
)
|
107
|
+
signed_params.should == {
|
108
|
+
'access_key' => "my_access_key",
|
109
|
+
'timestamp' => "2010-01-12T01:00:00.000000Z",
|
110
|
+
'factory_id' => 'my_cloud_id',
|
111
|
+
'signature' => 'g3shJBMg/7Kmbj3kl0eb4ziT3zounhFpC5jJIg+3Kts=',
|
112
|
+
'tilde' => '~',
|
113
|
+
'space' => ' '
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
it "should not include file inside the signature" do
|
119
|
+
@tc.signed_params('POST', '/videos.json', { "file" => "my_file" }).should == {
|
120
|
+
'access_key' => "my_access_key",
|
121
|
+
'timestamp' => "2010-01-12T01:00:00.000000Z",
|
122
|
+
'factory_id' => 'my_cloud_id',
|
123
|
+
'signature' => 'Ne/W+cvZAZ4yE70PcXgLbPieGrwdaCX9WPUCQeJBPhs=',
|
124
|
+
'file' => "my_file"
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should stringify keys" do
|
129
|
+
@tc.signed_params('POST', '/videos.json', { :file => "symbol_key" }).should == {
|
130
|
+
'access_key' => "my_access_key",
|
131
|
+
'timestamp' => "2010-01-12T01:00:00.000000Z",
|
132
|
+
'factory_id' => 'my_cloud_id',
|
133
|
+
'signature' => 'Ne/W+cvZAZ4yE70PcXgLbPieGrwdaCX9WPUCQeJBPhs=',
|
134
|
+
'file' => "symbol_key"
|
135
|
+
}
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "TelestreamCloud.connect " do
|
140
|
+
before(:each) do
|
141
|
+
@tc = TelestreamCloud.connect!({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "factory_id" => 'my_cloud_id'})
|
142
|
+
end
|
143
|
+
it_should_behave_like "Connected"
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "TelestreamCloud.connect with symbols" do
|
147
|
+
before(:each) do
|
148
|
+
@tc = TelestreamCloud.connect!({:access_key => "my_access_key", :secret_key => "my_secret_key", :api_host => "myapihost", :api_port => 85, :factory_id => 'my_cloud_id'})
|
149
|
+
end
|
150
|
+
|
151
|
+
it_should_behave_like "Connected"
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "Panda::Connection.new" do
|
155
|
+
before(:each) do
|
156
|
+
@tc = TelestreamCloud::Connection.new({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "factory_id" => 'my_cloud_id'})
|
157
|
+
end
|
158
|
+
it_should_behave_like "Connected"
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "Using hash as a return format" do
|
162
|
+
|
163
|
+
before(:each) do
|
164
|
+
@tc = TelestreamCloud::Connection.new({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "factory_id" => 'my_cloud_id' })
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should make get request" do
|
168
|
+
stub_http_request(:get, "http://myapihost:85/v3.0/videos?access_key=my_access_key&factory_id=my_cloud_id&signature=ArhKqAFUwLQl9RhSmnOv5L2CMWhr0ZFOxA0B9IKIg8I=×tamp=2010-01-12T01%3A00%3A00.000000Z").to_return(:body => "{\"key\":\"value\"}")
|
169
|
+
@tc.get("/videos").should == {'key' => 'value'}
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
# describe "ActiveSupport::JSON parsing" do
|
175
|
+
#
|
176
|
+
# it "should use active support if it has been defined and if restclient is used " do
|
177
|
+
# @tc = Panda::Connection.new({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "cloud_id" => 'my_cloud_id' })
|
178
|
+
# Panda.adapter = 'restclient'
|
179
|
+
#
|
180
|
+
# stub_http_request(:get, "http://myapihost:85/v2/videos?access_key=my_access_key&cloud_id=my_cloud_id&signature=DYpg2K6d7kGo%2FuWPO%2FaQgtQmY3BPtFEtQgdQhVe8teM%3D×tamp=2010-01-12T01%3A00%3A00.000000Z").to_return(:body => "abc")
|
181
|
+
#
|
182
|
+
#
|
183
|
+
# module ActiveSupport
|
184
|
+
# class JSON; end
|
185
|
+
# end
|
186
|
+
#
|
187
|
+
# ActiveSupport::JSON.should_receive(:decode).with("abc").and_return("blah")
|
188
|
+
# @tc.get("/videos").should == "blah"
|
189
|
+
#
|
190
|
+
# Object.send :remove_const, :ActiveSupport
|
191
|
+
# end
|
192
|
+
# end
|
193
|
+
|
194
|
+
describe "parsing" do
|
195
|
+
it "should raise an error if the response is not JSON parsable" do
|
196
|
+
@connection = TelestreamCloud::Connection.new({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "cloud_id" => 'my_cloud_id' })
|
197
|
+
|
198
|
+
stub_http_request(:get, //).to_return(:body => "blahblah")
|
199
|
+
|
200
|
+
lambda {
|
201
|
+
@connection.get("/fake")
|
202
|
+
}.should raise_error(TelestreamCloud::ServiceNotAvailable)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|