sproutvideo-rb 1.7.0 → 1.8.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 +4 -4
- data/Gemfile +3 -4
- data/Gemfile.lock +14 -11
- data/README.markdown +196 -10
- data/lib/sproutvideo/access_grant.rb +2 -2
- data/lib/sproutvideo/analytics.rb +53 -38
- data/lib/sproutvideo/call_to_action.rb +39 -0
- data/lib/sproutvideo/folder.rb +28 -0
- data/lib/sproutvideo/live_stream.rb +43 -0
- data/lib/sproutvideo/resource.rb +6 -10
- data/lib/sproutvideo/subtitle.rb +39 -0
- data/lib/sproutvideo/version.rb +1 -1
- data/lib/sproutvideo/video.rb +3 -4
- data/lib/sproutvideo.rb +16 -13
- data/spec/sproutvideo/analytics_spec.rb +92 -14
- data/spec/sproutvideo/call_to_action_spec.rb +98 -0
- data/spec/sproutvideo/folder_spec.rb +107 -0
- data/spec/sproutvideo/live_stream_spec.rb +152 -0
- data/spec/sproutvideo/subtitle_spec.rb +98 -0
- data/spec/sproutvideo/video_spec.rb +1 -1
- data/sproutvideo-rb.gemspec +18 -16
- metadata +25 -11
data/lib/sproutvideo/version.rb
CHANGED
data/lib/sproutvideo/video.rb
CHANGED
@@ -2,11 +2,11 @@ module Sproutvideo
|
|
2
2
|
class Video < Resource
|
3
3
|
|
4
4
|
def self.create(file_path='', options={})
|
5
|
-
upload("/videos", file_path, options)
|
5
|
+
upload("/videos", file_path, options, :source_video)
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.replace(video_id, file_path='')
|
9
|
-
upload("/videos/#{video_id}/replace", file_path)
|
9
|
+
upload("/videos/#{video_id}/replace", file_path, {}, :source_video)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.list(options={})
|
@@ -27,7 +27,7 @@ module Sproutvideo
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.upload_poster_frame(video_id, file_path='')
|
30
|
-
upload("/videos/#{video_id}", file_path, {:method => :PUT})
|
30
|
+
upload("/videos/#{video_id}", file_path, {:method => :PUT}, :custom_poster_frame)
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.destroy(video_id, options={})
|
@@ -61,6 +61,5 @@ module Sproutvideo
|
|
61
61
|
|
62
62
|
"#{protocol}://#{host}#{path}?signature=#{signature}#{actual_url_params}"
|
63
63
|
end
|
64
|
-
|
65
64
|
end
|
66
65
|
end
|
data/lib/sproutvideo.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
require 'multi_json'
|
2
2
|
require 'rest_client'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
4
|
+
require_relative 'sproutvideo/version.rb'
|
5
|
+
require_relative 'sproutvideo/sproutvideo.rb'
|
6
|
+
require_relative 'sproutvideo/response.rb'
|
7
|
+
require_relative 'sproutvideo/resource.rb'
|
8
|
+
require_relative 'sproutvideo/video.rb'
|
9
|
+
require_relative 'sproutvideo/tag.rb'
|
10
|
+
require_relative 'sproutvideo/playlist.rb'
|
11
|
+
require_relative 'sproutvideo/login.rb'
|
12
|
+
require_relative 'sproutvideo/access_grant.rb'
|
13
|
+
require_relative 'sproutvideo/analytics.rb'
|
14
|
+
require_relative 'sproutvideo/upload_token.rb'
|
15
|
+
require_relative 'sproutvideo/account.rb'
|
16
|
+
require_relative 'sproutvideo/folder.rb'
|
17
|
+
require_relative 'sproutvideo/subtitle.rb'
|
18
|
+
require_relative 'sproutvideo/call_to_action.rb'
|
19
|
+
require_relative 'sproutvideo/live_stream.rb'
|
@@ -12,7 +12,7 @@ describe Sproutvideo::Analytics do
|
|
12
12
|
@url = "#{Sproutvideo.base_url}/stats/counts"
|
13
13
|
end
|
14
14
|
|
15
|
-
it "should GET the correct url for overall method call and return a response" do
|
15
|
+
it "should GET the correct url for overall method call and return a response" do
|
16
16
|
RestClient.should_receive(:get).with(
|
17
17
|
@url,
|
18
18
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
@@ -24,6 +24,12 @@ describe Sproutvideo::Analytics do
|
|
24
24
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
25
25
|
Sproutvideo::Analytics.play_counts(:video_id => 'abc123').class.should == Sproutvideo::Response
|
26
26
|
end
|
27
|
+
it "should GET the correct url for individual live stream method call and return a response" do
|
28
|
+
RestClient.should_receive(:get).with(
|
29
|
+
"#{Sproutvideo.base_url}/stats/live_streams/abc123/counts",
|
30
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
31
|
+
Sproutvideo::Analytics.play_counts(:live_stream_id => 'abc123').class.should == Sproutvideo::Response
|
32
|
+
end
|
27
33
|
it "should GET the correct url if dates are passed in" do
|
28
34
|
RestClient.should_receive(:get).with(
|
29
35
|
@url,
|
@@ -37,7 +43,7 @@ describe Sproutvideo::Analytics do
|
|
37
43
|
@url = "#{Sproutvideo.base_url}/stats/domains"
|
38
44
|
end
|
39
45
|
|
40
|
-
it "should GET the correct url for overall method call and return a response" do
|
46
|
+
it "should GET the correct url for overall method call and return a response" do
|
41
47
|
RestClient.should_receive(:get).with(
|
42
48
|
@url,
|
43
49
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
@@ -49,6 +55,12 @@ describe Sproutvideo::Analytics do
|
|
49
55
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
50
56
|
Sproutvideo::Analytics.domains(:video_id => 'abc123').class.should == Sproutvideo::Response
|
51
57
|
end
|
58
|
+
it "should GET the correct url for individual live stream method call and return a response" do
|
59
|
+
RestClient.should_receive(:get).with(
|
60
|
+
"#{Sproutvideo.base_url}/stats/live_streams/abc123/device_types",
|
61
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
62
|
+
Sproutvideo::Analytics.device_types(:live_stream_id => 'abc123').class.should == Sproutvideo::Response
|
63
|
+
end
|
52
64
|
it "should GET the correct url if dates are passed in" do
|
53
65
|
RestClient.should_receive(:get).with(
|
54
66
|
@url,
|
@@ -62,7 +74,7 @@ describe Sproutvideo::Analytics do
|
|
62
74
|
@url = "#{Sproutvideo.base_url}/stats/geo"
|
63
75
|
end
|
64
76
|
|
65
|
-
it "should GET the correct url for overall method call and return a response" do
|
77
|
+
it "should GET the correct url for overall method call and return a response" do
|
66
78
|
RestClient.should_receive(:get).with(
|
67
79
|
@url,
|
68
80
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
@@ -74,6 +86,12 @@ describe Sproutvideo::Analytics do
|
|
74
86
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
75
87
|
Sproutvideo::Analytics.geo(:video_id => 'abc123').class.should == Sproutvideo::Response
|
76
88
|
end
|
89
|
+
it "should GET the correct url for individual live stream method call and return a response" do
|
90
|
+
RestClient.should_receive(:get).with(
|
91
|
+
"#{Sproutvideo.base_url}/stats/live_streams/abc123/geo",
|
92
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
93
|
+
Sproutvideo::Analytics.geo(:live_stream_id => 'abc123').class.should == Sproutvideo::Response
|
94
|
+
end
|
77
95
|
it "should GET the correct url if dates are passed in" do
|
78
96
|
RestClient.should_receive(:get).with(
|
79
97
|
@url,
|
@@ -93,7 +111,7 @@ describe Sproutvideo::Analytics do
|
|
93
111
|
@url = "#{Sproutvideo.base_url}/stats/video_types"
|
94
112
|
end
|
95
113
|
|
96
|
-
it "should GET the correct url for overall method call and return a response" do
|
114
|
+
it "should GET the correct url for overall method call and return a response" do
|
97
115
|
RestClient.should_receive(:get).with(
|
98
116
|
@url,
|
99
117
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
@@ -118,7 +136,7 @@ describe Sproutvideo::Analytics do
|
|
118
136
|
@url = "#{Sproutvideo.base_url}/stats/playback_types"
|
119
137
|
end
|
120
138
|
|
121
|
-
it "should GET the correct url for overall method call and return a response" do
|
139
|
+
it "should GET the correct url for overall method call and return a response" do
|
122
140
|
RestClient.should_receive(:get).with(
|
123
141
|
@url,
|
124
142
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
@@ -143,7 +161,7 @@ describe Sproutvideo::Analytics do
|
|
143
161
|
@url = "#{Sproutvideo.base_url}/stats/device_types"
|
144
162
|
end
|
145
163
|
|
146
|
-
it "should GET the correct url for overall method call and return a response" do
|
164
|
+
it "should GET the correct url for overall method call and return a response" do
|
147
165
|
RestClient.should_receive(:get).with(
|
148
166
|
@url,
|
149
167
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
@@ -168,7 +186,7 @@ describe Sproutvideo::Analytics do
|
|
168
186
|
@url = "#{Sproutvideo.base_url}/stats/engagement"
|
169
187
|
end
|
170
188
|
|
171
|
-
it "should GET the correct url for overall method call and return a response" do
|
189
|
+
it "should GET the correct url for overall method call and return a response" do
|
172
190
|
RestClient.should_receive(:get).with(
|
173
191
|
@url,
|
174
192
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
@@ -182,24 +200,84 @@ describe Sproutvideo::Analytics do
|
|
182
200
|
end
|
183
201
|
end
|
184
202
|
|
203
|
+
describe "#live_stream_engagment" do
|
204
|
+
it "should GET the correct url for live streams method call and return a response" do
|
205
|
+
RestClient.should_receive(:get).with(
|
206
|
+
"#{Sproutvideo.base_url}/stats/live_streams/engagement",
|
207
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
208
|
+
Sproutvideo::Analytics.live_stream_engagement.class.should == Sproutvideo::Response
|
209
|
+
end
|
210
|
+
it "should GET the correct url for individual live stream method call and return a response" do
|
211
|
+
RestClient.should_receive(:get).with(
|
212
|
+
"#{Sproutvideo.base_url}/stats/live_streams/abc123/engagement",
|
213
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
214
|
+
Sproutvideo::Analytics.live_stream_engagement(:live_stream_id => 'abc123').class.should == Sproutvideo::Response
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
185
218
|
describe "#engagement_sessions" do
|
186
219
|
before(:each) do
|
187
|
-
@
|
220
|
+
@id = "abc123"
|
188
221
|
end
|
189
|
-
|
222
|
+
|
223
|
+
it "should GET the correct url for overall method call and return a response" do
|
190
224
|
RestClient.should_receive(:get).with(
|
191
|
-
|
225
|
+
"#{Sproutvideo.base_url}/stats/engagement/sessions",
|
192
226
|
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
193
|
-
Sproutvideo::Analytics.engagement_sessions
|
227
|
+
Sproutvideo::Analytics.engagement_sessions.class.should == Sproutvideo::Response
|
194
228
|
end
|
195
229
|
|
196
230
|
it "should use pagination params" do
|
197
231
|
RestClient.should_receive(:get).with(
|
198
|
-
|
232
|
+
"#{Sproutvideo.base_url}/stats/engagement/sessions",
|
199
233
|
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 2, :per_page => 5}}).and_return(@msg)
|
200
|
-
Sproutvideo::Analytics.engagement_sessions(
|
234
|
+
Sproutvideo::Analytics.engagement_sessions(nil, :page => 2, :per_page => 5)
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should GET the correct url for video specific method call and return a response" do
|
238
|
+
RestClient.should_receive(:get).with(
|
239
|
+
"#{Sproutvideo.base_url}/stats/engagement/#{@id}/sessions",
|
240
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
241
|
+
Sproutvideo::Analytics.engagement_sessions(@id).class.should == Sproutvideo::Response
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "#live_stream_engagement_sessions" do
|
246
|
+
before(:each) do
|
247
|
+
@id = "abc123"
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should GET the correct url for overall live stream method call and return a response" do
|
251
|
+
RestClient.should_receive(:get).with(
|
252
|
+
"#{Sproutvideo.base_url}/stats/live_streams/engagement/sessions",
|
253
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
254
|
+
Sproutvideo::Analytics.live_stream_engagement_sessions.class.should == Sproutvideo::Response
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should GET the correct url for livestream specific method call and return a response" do
|
258
|
+
RestClient.should_receive(:get).with(
|
259
|
+
"#{Sproutvideo.base_url}/stats/live_streams/#{@id}/engagement/sessions",
|
260
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
261
|
+
Sproutvideo::Analytics.live_stream_engagement_sessions(@id).class.should == Sproutvideo::Response
|
201
262
|
end
|
202
263
|
end
|
203
264
|
|
265
|
+
describe "#popular_videos" do
|
266
|
+
it "should GET the correct url for overall method call and return a response" do
|
267
|
+
RestClient.should_receive(:get).with(
|
268
|
+
"#{Sproutvideo.base_url}/stats/popular_videos",
|
269
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
270
|
+
Sproutvideo::Analytics.popular_videos.class.should == Sproutvideo::Response
|
271
|
+
end
|
272
|
+
end
|
204
273
|
|
205
|
-
|
274
|
+
describe "#live_stream_overview" do
|
275
|
+
it "should GET the correct url for overall method call and return a response" do
|
276
|
+
id = "abc123"
|
277
|
+
RestClient.should_receive(:get).with(
|
278
|
+
"#{Sproutvideo.base_url}/stats/live_streams/#{id}/overview",
|
279
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
280
|
+
Sproutvideo::Analytics.live_stream_overview(id)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
|
+
describe Sproutvideo::CallToAction do
|
3
|
+
before(:each) do
|
4
|
+
@api_key = 'abc123'
|
5
|
+
@video_id = 1
|
6
|
+
Sproutvideo.api_key = @api_key
|
7
|
+
Sproutvideo.base_url = 'https://api.sproutvideo.com/v1'
|
8
|
+
@msg = mock(:to_s => "{}", :code => 200)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#create" do
|
12
|
+
it "should POST the correct url and return a response" do
|
13
|
+
request_data = { :text => 'join now!', :url => 'https://sproutvideo.com', start_time: 1, end_time: 2 }
|
14
|
+
RestClient.should_receive(:post).with(
|
15
|
+
"#{Sproutvideo.base_url}/videos/#{@video_id}/calls_to_action",
|
16
|
+
MultiJson.encode(request_data),
|
17
|
+
{'SproutVideo-Api-Key' => @api_key}).and_return(@msg)
|
18
|
+
data = request_data
|
19
|
+
data[:video_id] = @video_id
|
20
|
+
Sproutvideo::CallToAction.create(data).class.should == Sproutvideo::Response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#list" do
|
25
|
+
before(:each) do
|
26
|
+
@url = "#{Sproutvideo.base_url}/videos/#{@video_id}/calls_to_action"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should GET the correct url and return a response" do
|
30
|
+
|
31
|
+
RestClient.should_receive(:get).with(
|
32
|
+
@url,
|
33
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 1, :per_page => 25}}).and_return(@msg)
|
34
|
+
Sproutvideo::CallToAction.list(video_id: @video_id).class.should == Sproutvideo::Response
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should merge params" do
|
38
|
+
RestClient.should_receive(:get).with(
|
39
|
+
@url,
|
40
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 1, :per_page => 25, :foo => 'bar'}}).and_return(@msg)
|
41
|
+
Sproutvideo::CallToAction.list(video_id: @video_id, :foo => 'bar')
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should use pagination params" do
|
45
|
+
RestClient.should_receive(:get).with(
|
46
|
+
@url,
|
47
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 2, :per_page => 5}}).and_return(@msg)
|
48
|
+
Sproutvideo::CallToAction.list(video_id: @video_id, :page => 2, :per_page => 5)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#details" do
|
53
|
+
before(:each) do
|
54
|
+
@cta_id = '12'
|
55
|
+
@url = "#{Sproutvideo.base_url}/videos/#{@video_id}/calls_to_action/#{@cta_id}"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should get the correct url and return a response" do
|
59
|
+
RestClient.should_receive(:get).with(
|
60
|
+
@url,
|
61
|
+
{'SproutVideo-Api-Key' => @api_key, :params => { id: @cta_id }}).and_return(@msg)
|
62
|
+
Sproutvideo::CallToAction.details(id: @cta_id, video_id: @video_id).class.should == Sproutvideo::Response
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#update" do
|
67
|
+
before(:each) do
|
68
|
+
@cta_id = '12'
|
69
|
+
@url = "#{Sproutvideo.base_url}/videos/#{@video_id}/calls_to_action/#{@cta_id}"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should PUT the correct url and return a response" do
|
73
|
+
request_data = {:text => 'joinnnnnn', id: @cta_id}
|
74
|
+
|
75
|
+
RestClient.should_receive(:put).with(
|
76
|
+
@url,
|
77
|
+
MultiJson.encode(request_data),
|
78
|
+
{'SproutVideo-Api-Key' => @api_key}).and_return(@msg)
|
79
|
+
data = request_data
|
80
|
+
data[:video_id] = @video_id
|
81
|
+
Sproutvideo::CallToAction.update(data).class.should == Sproutvideo::Response
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#delete" do
|
86
|
+
before(:each) do
|
87
|
+
@cta_id = '12'
|
88
|
+
@url = "#{Sproutvideo.base_url}/videos/#{@video_id}/calls_to_action/#{@cta_id}"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should DELETE the correct url and return a response" do
|
92
|
+
RestClient.should_receive(:delete).with(
|
93
|
+
@url,
|
94
|
+
{'SproutVideo-Api-Key' => @api_key, :params => { id: @cta_id }}).and_return(@msg)
|
95
|
+
Sproutvideo::CallToAction.destroy(id: @cta_id, video_id: @video_id).class.should == Sproutvideo::Response
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
|
+
describe Sproutvideo::Folder do
|
3
|
+
before(:each) do
|
4
|
+
@api_key = 'abc123'
|
5
|
+
Sproutvideo.api_key = @api_key
|
6
|
+
Sproutvideo.base_url = 'https://api.sproutvideo.com/v1'
|
7
|
+
@msg = mock(:to_s => "{}", :code => 200)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#create" do
|
11
|
+
before(:each) do
|
12
|
+
@url = "#{Sproutvideo.base_url}/folders"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should POST the correct url and return a response" do
|
16
|
+
data = { :name => 'test folder', :parent_id => 'abc123' }
|
17
|
+
RestClient.should_receive(:post).with(
|
18
|
+
@url,
|
19
|
+
MultiJson.encode(data),
|
20
|
+
{'SproutVideo-Api-Key' => @api_key}).and_return(@msg)
|
21
|
+
Sproutvideo::Folder.create(data).class.should == Sproutvideo::Response
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#list" do
|
26
|
+
before(:each) do
|
27
|
+
@url = "#{Sproutvideo.base_url}/folders"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should GET the correct url and return a response" do
|
31
|
+
|
32
|
+
RestClient.should_receive(:get).with(
|
33
|
+
@url,
|
34
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 1, :per_page => 25}}).and_return(@msg)
|
35
|
+
Sproutvideo::Folder.list.class.should == Sproutvideo::Response
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should merge params" do
|
39
|
+
RestClient.should_receive(:get).with(
|
40
|
+
@url,
|
41
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 1, :per_page => 25, :foo => 'bar'}}).and_return(@msg)
|
42
|
+
Sproutvideo::Folder.list(:foo => 'bar')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should use pagination params" do
|
46
|
+
RestClient.should_receive(:get).with(
|
47
|
+
@url,
|
48
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 2, :per_page => 5}}).and_return(@msg)
|
49
|
+
Sproutvideo::Folder.list(:page => 2, :per_page => 5)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#details" do
|
54
|
+
before(:each) do
|
55
|
+
@folder_id = 1
|
56
|
+
@url = "#{Sproutvideo.base_url}/folders/#{@folder_id}"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should get the correct url and return a response" do
|
60
|
+
RestClient.should_receive(:get).with(
|
61
|
+
@url,
|
62
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
63
|
+
Sproutvideo::Folder.details(@folder_id).class.should == Sproutvideo::Response
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#update" do
|
68
|
+
before(:each) do
|
69
|
+
@folder_id = 1
|
70
|
+
@url = "#{Sproutvideo.base_url}/folders/#{@folder_id}"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should PUT the correct url and return a response" do
|
74
|
+
data = {:name => 'new name'}
|
75
|
+
|
76
|
+
RestClient.should_receive(:put).with(
|
77
|
+
@url,
|
78
|
+
MultiJson.encode(data),
|
79
|
+
{'SproutVideo-Api-Key' => @api_key}).and_return(@msg)
|
80
|
+
Sproutvideo::Folder.update(@folder_id, data).class.should == Sproutvideo::Response
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#delete" do
|
86
|
+
before(:each) do
|
87
|
+
@folder_id = 1
|
88
|
+
@url = "#{Sproutvideo.base_url}/folders/#{@folder_id}"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should DELETE the correct url and return a response" do
|
92
|
+
RestClient.should_receive(:delete).with(
|
93
|
+
@url,
|
94
|
+
{'SproutVideo-Api-Key' => @api_key, :params =>{}}).and_return(@msg)
|
95
|
+
Sproutvideo::Folder.destroy(@folder_id).class.should == Sproutvideo::Response
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should delete with the proper params' do
|
99
|
+
RestClient.should_receive(:delete).with(
|
100
|
+
@url,
|
101
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {delete_all: true}}
|
102
|
+
).and_return(@msg)
|
103
|
+
Sproutvideo::Folder.destroy(@folder_id, delete_all: true).class.should == Sproutvideo::Response
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
|
+
describe Sproutvideo::LiveStream do
|
3
|
+
before(:each) do
|
4
|
+
@api_key = 'abc123'
|
5
|
+
Sproutvideo.api_key = @api_key
|
6
|
+
Sproutvideo.base_url = 'https://api.sproutvideo.com/v1'
|
7
|
+
@msg = mock(:to_s => "{}", :code => 200)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#create" do
|
11
|
+
it "should POST the correct url and return a response" do
|
12
|
+
data = { title: 'newww live stream'}
|
13
|
+
RestClient.should_receive(:post).with(
|
14
|
+
"#{Sproutvideo.base_url}/live_streams",
|
15
|
+
MultiJson.encode(data),
|
16
|
+
{'SproutVideo-Api-Key' => @api_key}).and_return(@msg)
|
17
|
+
|
18
|
+
Sproutvideo::LiveStream.create(data).class.should == Sproutvideo::Response
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should POST the correct url with file and return a response" do
|
22
|
+
File.open("upload_test", "w+") do |f|
|
23
|
+
f.syswrite("upload!")
|
24
|
+
end
|
25
|
+
|
26
|
+
file = File.open('upload_test')
|
27
|
+
|
28
|
+
File.stub!(:open).with('upload_test').and_yield(file)
|
29
|
+
|
30
|
+
RestClient.should_receive(:post).with(
|
31
|
+
"#{Sproutvideo.base_url}/live_streams",
|
32
|
+
{:custom_poster_frame => file, :title => 'test title'},
|
33
|
+
{'SproutVideo-Api-Key' => @api_key, :timeout => 18000}).and_return(@msg)
|
34
|
+
Sproutvideo::LiveStream.create({:title => 'test title', :custom_poster_frame => 'upload_test' }).class.should == Sproutvideo::Response
|
35
|
+
|
36
|
+
FileUtils.rm('upload_test')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#list" do
|
41
|
+
before(:each) do
|
42
|
+
@url = "#{Sproutvideo.base_url}/live_streams"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should GET the correct url and return a response" do
|
46
|
+
|
47
|
+
RestClient.should_receive(:get).with(
|
48
|
+
@url,
|
49
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 1, :per_page => 25}}).and_return(@msg)
|
50
|
+
Sproutvideo::LiveStream.list.class.should == Sproutvideo::Response
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should merge params" do
|
54
|
+
RestClient.should_receive(:get).with(
|
55
|
+
@url,
|
56
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 1, :per_page => 25, :foo => 'bar'}}).and_return(@msg)
|
57
|
+
Sproutvideo::LiveStream.list(:foo => 'bar')
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should use pagination params" do
|
61
|
+
RestClient.should_receive(:get).with(
|
62
|
+
@url,
|
63
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 2, :per_page => 5}}).and_return(@msg)
|
64
|
+
Sproutvideo::LiveStream.list(:page => 2, :per_page => 5)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should request live_streams for a tag if tag_id is passed in" do
|
68
|
+
RestClient.should_receive(:get).with(
|
69
|
+
@url,
|
70
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {:page => 1, :per_page => 25, :tag_id => 'asdf'}}).and_return(@msg)
|
71
|
+
Sproutvideo::LiveStream.list(:tag_id => 'asdf')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#details" do
|
76
|
+
before(:each) do
|
77
|
+
@live_stream_id = 1
|
78
|
+
@url = "#{Sproutvideo.base_url}/live_streams/#{@live_stream_id}"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should get the correct url and return a response" do
|
82
|
+
RestClient.should_receive(:get).with(
|
83
|
+
@url,
|
84
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
85
|
+
Sproutvideo::LiveStream.details(@live_stream_id).class.should == Sproutvideo::Response
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#update" do
|
90
|
+
before(:each) do
|
91
|
+
@live_stream_id = 1
|
92
|
+
@url = "#{Sproutvideo.base_url}/live_streams/#{@live_stream_id}"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should PUT the correct url and return a response" do
|
96
|
+
data = {:title => 'new title'}
|
97
|
+
|
98
|
+
RestClient.should_receive(:put).with(
|
99
|
+
@url,
|
100
|
+
MultiJson.encode(data),
|
101
|
+
{'SproutVideo-Api-Key' => @api_key}).and_return(@msg)
|
102
|
+
Sproutvideo::LiveStream.update(@live_stream_id, data).class.should == Sproutvideo::Response
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should PUT the correct url and return a response" do
|
106
|
+
File.open("upload_test2", "w+") do |f|
|
107
|
+
f.syswrite("upload!")
|
108
|
+
end
|
109
|
+
|
110
|
+
file = File.open('upload_test2')
|
111
|
+
|
112
|
+
File.stub!(:open).with('upload_test2').and_yield(file)
|
113
|
+
|
114
|
+
RestClient.should_receive(:put).with(
|
115
|
+
"#{Sproutvideo.base_url}/live_streams/#{@live_stream_id}",
|
116
|
+
{:custom_poster_frame => file, :title => 'test title'},
|
117
|
+
{'SproutVideo-Api-Key' => @api_key, :timeout => 18000}).and_return(@msg)
|
118
|
+
Sproutvideo::LiveStream.update(@live_stream_id, {:title => 'test title', :custom_poster_frame => 'upload_test2' }).class.should == Sproutvideo::Response
|
119
|
+
|
120
|
+
FileUtils.rm('upload_test2')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "#delete" do
|
125
|
+
before(:each) do
|
126
|
+
@live_stream_id = 1
|
127
|
+
@url = "#{Sproutvideo.base_url}/live_streams/#{@live_stream_id}"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should DELETE the correct url and return a response" do
|
131
|
+
RestClient.should_receive(:delete).with(
|
132
|
+
@url,
|
133
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
134
|
+
Sproutvideo::LiveStream.destroy(@live_stream_id).class.should == Sproutvideo::Response
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "#end_stream" do
|
139
|
+
before(:each) do
|
140
|
+
@live_stream_id = 1
|
141
|
+
@url = "#{Sproutvideo.base_url}/live_streams/#{@live_stream_id}/end_stream"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should PUT the correct url and return a response" do
|
145
|
+
RestClient.should_receive(:put).with(
|
146
|
+
@url,
|
147
|
+
"{}",
|
148
|
+
{'SproutVideo-Api-Key' => @api_key}).and_return(@msg)
|
149
|
+
Sproutvideo::LiveStream.end_stream(@live_stream_id).class.should == Sproutvideo::Response
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|