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,117 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe TelestreamCloud::Profile 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:85\/v3.0\/factories\/my_cloud_id.json/).
|
7
|
+
to_return(:body => cloud_json)
|
8
|
+
|
9
|
+
TelestreamCloud.configure do
|
10
|
+
access_key "my_access_key"
|
11
|
+
secret_key "my_secret_key"
|
12
|
+
api_host "api.example.com"
|
13
|
+
factory_id 'my_cloud_id'
|
14
|
+
api_port 85
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should create a profile" do
|
20
|
+
profile_json = "{\"title\":\"my_profile\",\"id\":\"123\"}"
|
21
|
+
stub_http_request(:post, /api.example.com:85\/v3.0\/profiles.json/).
|
22
|
+
with(:body => /title=my_profile/).
|
23
|
+
to_return(:body => profile_json)
|
24
|
+
|
25
|
+
profile = TelestreamCloud::Profile.new(:title => "my_profile")
|
26
|
+
|
27
|
+
profile.new?.should == true
|
28
|
+
profile.changed?.should == true
|
29
|
+
profile.save.should == true
|
30
|
+
profile.changed?.should == false
|
31
|
+
profile.id.should == "123"
|
32
|
+
profile.new?.should == false
|
33
|
+
|
34
|
+
profile.changed?.should == false
|
35
|
+
|
36
|
+
profile.title = "new_last_title"
|
37
|
+
profile.changed?.should == true
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
it "should update a profile and sending the changed attributes" do
|
42
|
+
profile_json = "{\"title\":\"my_profile\",\"id\":\"123\"}"
|
43
|
+
stub_http_request(:put, /api.example.com:85\/v3.0\/profiles\/999.json/).
|
44
|
+
with{|r| !(r.body =~ /title=my_new_profile_title/) && r.body =~ /width=80/}.
|
45
|
+
to_return(:body => profile_json)
|
46
|
+
|
47
|
+
profile = TelestreamCloud::Profile.new(:id => "999", :title => "my_profile_title")
|
48
|
+
|
49
|
+
profile.width=80
|
50
|
+
profile.new?.should == false
|
51
|
+
profile.save.should == true
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
it "should not call update a profile" do
|
56
|
+
profile_json = "{\"title\":\"my_profile\",\"id\":\"123\"}"
|
57
|
+
stub_http_request(:put, /api.example.com:85\/v3.0\/profiles\/123.json/).
|
58
|
+
with(:body => /title=my_profile/).
|
59
|
+
to_return(:body => profile_json)
|
60
|
+
|
61
|
+
profile = TelestreamCloud::Profile.new(:id => "123")
|
62
|
+
profile.title = "my_profile"
|
63
|
+
|
64
|
+
profile.new?.should == false
|
65
|
+
profile.save.should == true
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
it "should have a many relation on encodings" do
|
70
|
+
encoding_json = "[{\"abc\":\"efg\",\"id\":456}]"
|
71
|
+
profile_json = "{\"title\":\"my_profile\",\"id\":\"901\"}"
|
72
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/profiles\/901\/encodings.json/).
|
73
|
+
to_return(:body => encoding_json)
|
74
|
+
|
75
|
+
profile = TelestreamCloud::Profile.new(:title => "my_source_url", :id => "901")
|
76
|
+
profile.encodings.first.id.should == 456
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should reload the object" do
|
80
|
+
profile_json = "{\"title\":\"my_profile\",\"id\":\"123\"}"
|
81
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/profiles\/123.json/).
|
82
|
+
to_return(:body => profile_json)
|
83
|
+
|
84
|
+
profile = TelestreamCloud::Profile.new(:id => "123", :title => "my_new_profile_title")
|
85
|
+
profile.title.should == "my_new_profile_title"
|
86
|
+
profile.reload
|
87
|
+
profile.id.should == "123"
|
88
|
+
profile.title.should == "my_profile"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "shoud raise an exeception if it's a new object" do
|
92
|
+
profile = TelestreamCloud::Profile.new(:title => "my_new_profile_title")
|
93
|
+
lambda {
|
94
|
+
profile.reload
|
95
|
+
}.should raise_error("RecordNotFound")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "shoud raise an exeception if it's a new object" do
|
99
|
+
profile_json = "{\"title\":\"my_profile\",\"id\":\"123\"}"
|
100
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/profiles\/123.json/).
|
101
|
+
to_return(:body => profile_json)
|
102
|
+
|
103
|
+
profile = TelestreamCloud::Profile.find(123)
|
104
|
+
profile.reload.should == profile
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should not delegate scope if the method do not really exist in the scope" do
|
108
|
+
lambda {TelestreamCloud::Profile.reload}.should raise_error(NoMethodError)
|
109
|
+
lambda {TelestreamCloud::Profile.each}.should raise_error(NoMethodError)
|
110
|
+
lambda {TelestreamCloud::Profile.size}.should raise_error(NoMethodError)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should tell if profile is using a preset" do
|
114
|
+
TelestreamCloud::Profile.new(:title => "abc").preset?.should be_truthy
|
115
|
+
TelestreamCloud::Profile.new(:preset_name => "abc").preset?.should be_falsey
|
116
|
+
end
|
117
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'telestream_cloud'
|
4
|
+
require 'rspec'
|
5
|
+
|
6
|
+
require 'webmock/rspec'
|
7
|
+
include WebMock::API
|
8
|
+
|
9
|
+
def hputs(*args)
|
10
|
+
puts ERB::Util.html_escape(args.join("\n")).gsub(/\r?\n/, '<br/>') + '<br/>'
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.before(:each) do
|
15
|
+
TelestreamCloud.instance_variable_set("@connection", nil)
|
16
|
+
TelestreamCloud.instance_variable_set("@factory", nil)
|
17
|
+
end
|
18
|
+
end
|
data/spec/video_spec.rb
ADDED
@@ -0,0 +1,399 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe TelestreamCloud::Video 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 create a video object" do
|
17
|
+
v = TelestreamCloud::Video.new({ :test => "abc" })
|
18
|
+
v.test.should == "abc"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should tell video is new" do
|
22
|
+
v = TelestreamCloud::Video.new({ :id => "abc" })
|
23
|
+
v.new?.should be_falsey
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not tell video is new" do
|
27
|
+
v = TelestreamCloud::Video.new({ :attr => "abc" })
|
28
|
+
v.new?.should be_truthy
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should find return all videos" do
|
32
|
+
|
33
|
+
videos_json = "[{\"source_url\":\"my_source_url\",\"id\":111},{\"source_url\":\"http://a.b.com/file2.mp4\",\"id\":222}]"
|
34
|
+
|
35
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos.json/).to_return(:body => videos_json)
|
36
|
+
|
37
|
+
videos = TelestreamCloud::Video.all
|
38
|
+
videos.first.id.should == 111
|
39
|
+
videos.first.source_url.should == "my_source_url"
|
40
|
+
videos.size.should == 2
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should find a videos having the correct id" do
|
44
|
+
|
45
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
46
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).to_return(:body => video_json)
|
47
|
+
|
48
|
+
video = TelestreamCloud::Video.find("123")
|
49
|
+
video.id.should == "123"
|
50
|
+
video.source_url.should == "my_source_url"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should raise exception if id is nil" do
|
54
|
+
|
55
|
+
lambda {
|
56
|
+
TelestreamCloud::Video.find(nil)
|
57
|
+
}.should raise_error('find method requires a correct value')
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should list all video's encodings" do
|
62
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
63
|
+
encodings_json = "[{\"abc\":\"my_source_url\",\"id\":\"456\"}]"
|
64
|
+
|
65
|
+
encodings = [TelestreamCloud::Encoding.new({:abc => "my_source_url", :id => "456"})]
|
66
|
+
|
67
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).to_return(:body => video_json)
|
68
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).to_return(:body => encodings_json)
|
69
|
+
|
70
|
+
video = TelestreamCloud::Video.find("123")
|
71
|
+
video.encodings.first.attributes.should == encodings.first.attributes
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should delete a video using class" do
|
75
|
+
video_json = "{\"deleted\":\"ok\"}"
|
76
|
+
stub_http_request(:delete, /api.example.com:85\/v3.0\/videos\/123.json/).to_return(:body => video_json)
|
77
|
+
|
78
|
+
video = TelestreamCloud::Video.new(:source_url => "my_source_url", :id => "123")
|
79
|
+
video.factory
|
80
|
+
video.delete.should == true
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should delete a video using instance" do
|
84
|
+
video_json = "{\"deleted\":\"ok\"}"
|
85
|
+
stub_http_request(:delete, /api.example.com:85\/v3.0\/videos\/123.json/).to_return(:body => video_json)
|
86
|
+
|
87
|
+
TelestreamCloud::Video.delete("123")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should have an error object if something goes wrong" do
|
91
|
+
response = "{\"message\":\"no-abc\",\"error\":\"error-abc\"}"
|
92
|
+
|
93
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/abc.json/).to_return(:body => response)
|
94
|
+
|
95
|
+
lambda {
|
96
|
+
TelestreamCloud::Video.find "abc"
|
97
|
+
}.should raise_error(TelestreamCloud::APIError, "error-abc: no-abc")
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should have an error object if something goes wrong" do
|
101
|
+
response = "{\"message\":\"no-abc\",\"error\":\"error-abc\"}"
|
102
|
+
|
103
|
+
stub_http_request(:put, /api.example.com:85\/v3.0\/profiles\/abc.json/).to_return(:body => response)
|
104
|
+
|
105
|
+
obj = TelestreamCloud::Profile.new(:id => "abc")
|
106
|
+
original_attrs = obj.attributes
|
107
|
+
obj.save
|
108
|
+
|
109
|
+
obj.errors.size.should == 1
|
110
|
+
obj.errors.first.to_s.should == "error-abc: no-abc"
|
111
|
+
obj.attributes.should == original_attrs
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should connect to eu" do
|
116
|
+
|
117
|
+
|
118
|
+
TelestreamCloud.configure do
|
119
|
+
access_key "my_access_key"
|
120
|
+
secret_key "my_secret_key"
|
121
|
+
factory_id 'my_cloud_id'
|
122
|
+
region "eu"
|
123
|
+
end
|
124
|
+
|
125
|
+
stub_http_request(:get, /api-eu.pandastream.com:443/).
|
126
|
+
to_return(:body => "{\"id\":\"123\"}")
|
127
|
+
TelestreamCloud::Video.find "123"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should accept a string as a port" do
|
131
|
+
TelestreamCloud.configure do
|
132
|
+
access_key "my_access_key"
|
133
|
+
secret_key "my_secret_key"
|
134
|
+
factory_id 'my_cloud_id'
|
135
|
+
api_port '443'
|
136
|
+
end
|
137
|
+
|
138
|
+
stub_http_request(:get, /https:\/\/api.pandastream.com:443/).
|
139
|
+
to_return(:body => "{\"id\":\"123\"}")
|
140
|
+
TelestreamCloud::Video.find "123"
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should connect to eu and trigger the request" do
|
144
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\"}"
|
145
|
+
stub_http_request(:get, /api-eu.pandastream.com:80\/v3.0\/factories\/my_cloud_id.json/).
|
146
|
+
to_return(:body => cloud_json)
|
147
|
+
|
148
|
+
TelestreamCloud.configure do |c|
|
149
|
+
c.access_key "my_access_key"
|
150
|
+
c.secret_key "my_secret_key"
|
151
|
+
c.factory_id 'my_cloud_id'
|
152
|
+
c.region "eu"
|
153
|
+
end
|
154
|
+
|
155
|
+
stub_http_request(:get, /api-eu.pandastream.com:443/).
|
156
|
+
to_return(:body => "{\"id\":\"123\"}")
|
157
|
+
TelestreamCloud::Video.find "123"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should use the correct connection" do
|
161
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
162
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"cloud1\"}"
|
163
|
+
cloud2_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"cloud2\"}"
|
164
|
+
|
165
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/factories\/cloud1.json/).
|
166
|
+
to_return(:body => cloud_json)
|
167
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/factories\/cloud2.json/).
|
168
|
+
to_return(:body => cloud2_json)
|
169
|
+
|
170
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).
|
171
|
+
to_return(:body => video_json)
|
172
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).
|
173
|
+
to_return(:body => video_json)
|
174
|
+
|
175
|
+
cloud = TelestreamCloud::Factory.new(:id => "cloud1")
|
176
|
+
|
177
|
+
cloud2 = TelestreamCloud::Factory.new(:id => "cloud2")
|
178
|
+
|
179
|
+
video = cloud.videos.find("123")
|
180
|
+
video2 = cloud2.videos.find("123")
|
181
|
+
|
182
|
+
video.factory.id.should == "cloud1"
|
183
|
+
video2.factory.id.should == "cloud2"
|
184
|
+
|
185
|
+
TelestreamCloud::Video.factory.id.should == "my_cloud_id"
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should create a video using class method" do
|
189
|
+
video_json = "{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}"
|
190
|
+
|
191
|
+
stub_http_request(:post, /api.example.com:85\/v3.0\/videos.json/).
|
192
|
+
with(:body => /source_url=url_panda.mp4/).
|
193
|
+
to_return(:body => video_json)
|
194
|
+
|
195
|
+
video = TelestreamCloud::Video.create(:source_url => "url_panda.mp4")
|
196
|
+
video.id.should == "123"
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should create a video and reload" do
|
200
|
+
video_json = "{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}"
|
201
|
+
|
202
|
+
stub_http_request(:post, /api.example.com:85\/v3.0\/videos.json/).
|
203
|
+
with(:body => /source_url=url_panda.mp4/).
|
204
|
+
to_return(:body => video_json)
|
205
|
+
|
206
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).to_return(:body => video_json)
|
207
|
+
|
208
|
+
video = TelestreamCloud::Video.create(:source_url => "url_panda.mp4")
|
209
|
+
video.reload.should == video
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should create a video using class method and a block" do
|
213
|
+
video_json = "{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}"
|
214
|
+
|
215
|
+
stub_http_request(:post, /api.example.com:85\/v3.0\/videos.json/).
|
216
|
+
with(:body => /source_url=url_panda.mp4/).
|
217
|
+
to_return(:body => video_json)
|
218
|
+
|
219
|
+
video = TelestreamCloud::Video.create do |v|
|
220
|
+
v.source_url = "url_panda.mp4"
|
221
|
+
end
|
222
|
+
|
223
|
+
video.id.should == "123"
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should return a json on attributes" do
|
227
|
+
video = TelestreamCloud::Video.new(:attr => "value")
|
228
|
+
|
229
|
+
MultiJson.decode( video.to_json ).should == {"attr" => "value", "factory_id" => "my_cloud_id"}
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should create an encoding using video scope" do
|
233
|
+
encoding_json = "{\"source_url\":\"my_source_url\",\"id\":\"678\"}"
|
234
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
235
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).
|
236
|
+
to_return(:body => video_json)
|
237
|
+
|
238
|
+
stub_http_request(:post, /api.example.com:85\/v3.0\/encodings.json/).
|
239
|
+
with(:body => /profile_id=345/).
|
240
|
+
to_return(:body => encoding_json)
|
241
|
+
|
242
|
+
video = TelestreamCloud::Video.find "123"
|
243
|
+
encoding = video.encodings.create(:profile_id => "345")
|
244
|
+
encoding.id.should == "678"
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should not create a model having an id" do
|
248
|
+
video = TelestreamCloud::Video.new(:id => "abc")
|
249
|
+
lambda {
|
250
|
+
video.create
|
251
|
+
}.should raise_error "Can't create attribute. Already have an id=abc"
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should not create a model having an id" do
|
255
|
+
lambda {
|
256
|
+
TelestreamCloud::Video.create(:id => "abc")
|
257
|
+
}.should raise_error "Can't create attribute. Already have an id=abc"
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should not call the request twice" do
|
261
|
+
video_json = "{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}"
|
262
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).to_return(:body => video_json)
|
263
|
+
video = TelestreamCloud::Video.find("123")
|
264
|
+
|
265
|
+
encodings_json = "[{\"abc\":\"my_source_url\",\"id\":\"456\"}]"
|
266
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).to_return(:body => encodings_json)
|
267
|
+
|
268
|
+
encodings = video.encodings
|
269
|
+
encodings.first
|
270
|
+
encodings.first
|
271
|
+
|
272
|
+
WebMock.should have_requested(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).once
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'should generate json of encodings' do
|
276
|
+
video_json = "{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}"
|
277
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).to_return(:body => video_json)
|
278
|
+
video = TelestreamCloud::Video.find("123")
|
279
|
+
|
280
|
+
encodings_json = "[{\"abc\":\"my_source_url\",\"id\":\"456\"}]"
|
281
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).to_return(:body => encodings_json)
|
282
|
+
|
283
|
+
MultiJson.decode( video.encodings.first.to_json ).should == {"abc" => "my_source_url", "id" => "456", "factory_id" => "my_cloud_id"}
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should return the video url" do
|
287
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
288
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/factories\/my_cloud_id.json/).
|
289
|
+
to_return(:body => cloud_json)
|
290
|
+
|
291
|
+
video = TelestreamCloud::Video.new({:id => "456", :extname => ".ext", :path => "abc/panda", :status => 'success'})
|
292
|
+
video.url.should == "http://my-bucket.s3.amazonaws.com/abc/panda.ext"
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should return the secure video url" do
|
296
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
297
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/factories\/my_cloud_id.json/).
|
298
|
+
to_return(:body => cloud_json)
|
299
|
+
|
300
|
+
video = TelestreamCloud::Video.new({:id => "456", :extname => ".ext", :path => "abc/panda", :status => 'success'})
|
301
|
+
video.url(:https => true).should == "https://my-bucket.s3.amazonaws.com/abc/panda.ext"
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should generate a screenshot url" do
|
305
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
306
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/factories\/my_cloud_id.json/).
|
307
|
+
to_return(:body => cloud_json)
|
308
|
+
|
309
|
+
video = TelestreamCloud::Video.new({:id => "456", :extname => ".ext", :status => "success", :path => "abc/panda"})
|
310
|
+
video.preview_url.should == "http://my-bucket.s3.amazonaws.com/abc/panda_1.jpg"
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should generate a secure screenshot url" do
|
314
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my-bucket.s3.amazonaws.com/\"}"
|
315
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/factories\/my_cloud_id.json/).
|
316
|
+
to_return(:body => cloud_json)
|
317
|
+
|
318
|
+
video = TelestreamCloud::Video.new({:id => "456", :extname => ".ext", :status => "success", :path => "abc/panda"})
|
319
|
+
video.preview_url(:https => true).should == "https://my-bucket.s3.amazonaws.com/abc/panda_1.jpg"
|
320
|
+
end
|
321
|
+
|
322
|
+
it "should call the request if the scope has changed" do
|
323
|
+
video_json = "{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}"
|
324
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).to_return(:body => video_json)
|
325
|
+
video = TelestreamCloud::Video.find("123")
|
326
|
+
|
327
|
+
encodings_json = "[{\"abc\":\"my_source_url\",\"id\":\"456\"}]"
|
328
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).to_return(:body => encodings_json)
|
329
|
+
|
330
|
+
encodings = video.encodings.status("success")
|
331
|
+
|
332
|
+
encodings.first
|
333
|
+
encodings.last
|
334
|
+
|
335
|
+
video.encodings.first
|
336
|
+
|
337
|
+
WebMock.should have_requested(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).once
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should not call the request twice" do
|
341
|
+
video_json = "{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}"
|
342
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).to_return(:body => video_json)
|
343
|
+
video = TelestreamCloud::Video.find("123")
|
344
|
+
|
345
|
+
encodings_json = "[{\"abc\":\"my_source_url\",\"id\":\"456\"}]"
|
346
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).to_return(:body => encodings_json)
|
347
|
+
|
348
|
+
encodings = video.encodings
|
349
|
+
encodings.first.id.should == "456"
|
350
|
+
encodings.reload
|
351
|
+
|
352
|
+
WebMock.should have_requested(:get, /api.example.com:85\/v3.0\/videos\/123\/encodings.json/).twice
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should tell if the video is success" do
|
356
|
+
encoding = TelestreamCloud::Video.new({:status => "success"})
|
357
|
+
encoding.success?.should == true
|
358
|
+
encoding.processing?.should == false
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should tell if the video is success" do
|
362
|
+
encoding = TelestreamCloud::Video.new({:status => "processing"})
|
363
|
+
encoding.success?.should == false
|
364
|
+
encoding.processing?.should == true
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should tell if the video is success" do
|
368
|
+
encoding = TelestreamCloud::Video.new({:status => "fail"})
|
369
|
+
encoding.success?.should == false
|
370
|
+
encoding.fail?.should == true
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should return the most recent updated video" do
|
374
|
+
video_json = "[{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}]"
|
375
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos.json/).
|
376
|
+
with{|r| r.uri.query =~ /per_page=1/ }.
|
377
|
+
to_return(:body => video_json)
|
378
|
+
TelestreamCloud::Video.first
|
379
|
+
end
|
380
|
+
|
381
|
+
it "should not delegate scope if the method do not really exist in the scope" do
|
382
|
+
lambda {TelestreamCloud::Video.reload}.should raise_error(NoMethodError)
|
383
|
+
lambda {TelestreamCloud::Video.each}.should raise_error(NoMethodError)
|
384
|
+
lambda {TelestreamCloud::Video.size}.should raise_error(NoMethodError)
|
385
|
+
end
|
386
|
+
|
387
|
+
it "should lazy load the cloud" do
|
388
|
+
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\"}"
|
389
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/factories\/my_cloud_id.json/).
|
390
|
+
to_return(:body => cloud_json)
|
391
|
+
|
392
|
+
video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
|
393
|
+
stub_http_request(:get, /api.example.com:85\/v3.0\/videos\/123.json/).
|
394
|
+
to_return(:body => video_json)
|
395
|
+
|
396
|
+
video = TelestreamCloud::Video.find "123"
|
397
|
+
video.factory.s3_videos_bucket.should == "my_bucket"
|
398
|
+
end
|
399
|
+
end
|