sproutvideo-rb 1.6.0 → 1.9.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.
@@ -1,73 +1,97 @@
1
1
  module Sproutvideo
2
2
  class Analytics < Resource
3
-
4
3
  def self.play_counts(options={})
5
- url = "/stats/counts"
6
- if options.include?(:video_id)
7
- video_id = options.delete(:video_id)
8
- url += "/#{video_id}"
9
- end
4
+ url = build_path("/stats/counts", options)
5
+ get(url, options)
6
+ end
7
+
8
+ def self.download_counts(options ={})
9
+ url = build_path("/stats/downloads", options)
10
10
  get(url, options)
11
11
  end
12
12
 
13
13
  def self.domains(options={})
14
- url = "/stats/domains"
15
- if options.include?(:video_id)
16
- video_id = options.delete(:video_id)
17
- url += "/#{video_id}"
18
- end
14
+ url = build_path("/stats/domains", options)
19
15
  get(url, options)
20
16
  end
21
17
 
22
18
  def self.geo(options={})
23
- url = "/stats/geo"
24
- if options.include?(:video_id)
25
- video_id = options.delete(:video_id)
26
- url += "/#{video_id}"
27
- end
19
+ url = build_path("/stats/geo", options)
28
20
  get(url, options)
29
21
  end
30
22
 
31
23
  def self.video_types(options={})
32
- url = "/stats/video_types"
33
- if options.include?(:video_id)
34
- video_id = options.delete(:video_id)
35
- url += "/#{video_id}"
36
- end
24
+ url = build_path("/stats/video_types", options)
37
25
  get(url, options)
38
26
  end
39
27
 
40
28
  def self.playback_types(options={})
41
- url = "/stats/playback_types"
42
- if options.include?(:video_id)
43
- video_id = options.delete(:video_id)
44
- url += "/#{video_id}"
45
- end
29
+ url = build_path("/stats/playback_types", options)
46
30
  get(url, options)
47
31
  end
48
32
 
49
33
  def self.device_types(options={})
50
- url = "/stats/device_types"
51
- if options.include?(:video_id)
52
- video_id = options.delete(:video_id)
53
- url += "/#{video_id}"
54
- end
34
+ url = build_path("/stats/device_types", options)
55
35
  get(url, options)
56
36
  end
57
37
 
58
38
  def self.engagement(options={})
59
- url = "/stats/engagement"
60
- if options.include?(:video_id)
61
- video_id = options.delete(:video_id)
62
- url += "/#{video_id}"
39
+ url = build_path("/stats/engagement", options)
40
+ get(url, options)
41
+ end
42
+
43
+ def self.engagement_sessions(video_id=nil, options={})
44
+ if video_id.nil?
45
+ url = "/stats/engagement/sessions"
46
+ else
47
+ url = "/stats/engagement/#{video_id}/sessions"
63
48
  end
64
49
  get(url, options)
65
50
  end
66
51
 
67
- def self.engagement_sessions(video_id, options={})
68
- url = "/stats/engagement/#{video_id}/sessions"
52
+ def self.live_stream_engagement(options={})
53
+ if options.include?(:live_stream_id)
54
+ url = build_path("/stats/engagement", options)
55
+ else
56
+ url = "/stats/live_streams/engagement"
57
+ end
69
58
  get(url, options)
70
59
  end
71
60
 
61
+ def self.live_stream_engagement_sessions(live_stream_id=nil, options={})
62
+ if live_stream_id.nil?
63
+ url = "/stats/live_streams/engagement/sessions"
64
+ else
65
+ url = "/stats/live_streams/#{live_stream_id}/engagement/sessions"
66
+ end
67
+ get(url, options)
68
+ end
69
+
70
+ def self.popular_videos(options={})
71
+ get("/stats/popular_videos", options)
72
+ end
73
+
74
+ def self.popular_downloads(options={})
75
+ get('/stats/popular_downloads', options)
76
+ end
77
+
78
+ def self.live_stream_overview(live_stream_id, options={})
79
+ get("/stats/live_streams/#{live_stream_id}/overview", options)
80
+ end
81
+
82
+ private
83
+
84
+ def self.build_path(path, options)
85
+ if options.include?(:video_id)
86
+ video_id = options.delete(:video_id)
87
+ path += "/#{video_id}"
88
+ end
89
+ if options.include?(:live_stream_id)
90
+ video_id = options.delete(:live_stream_id)
91
+ resource = path.split('/').last
92
+ path = "/stats/live_streams/#{video_id}/#{resource}"
93
+ end
94
+ path
95
+ end
72
96
  end
73
- end
97
+ end
@@ -0,0 +1,39 @@
1
+ module Sproutvideo
2
+ class CallToAction < Resource
3
+ def self.create(options = {})
4
+ post(build_url(options), options)
5
+ end
6
+
7
+ def self.list(options = {})
8
+ url = build_url(options)
9
+ params = {
10
+ :page => options.delete(:page) || 1,
11
+ :per_page => options.delete(:per_page) || 25
12
+ }
13
+ params = params.merge(options)
14
+ get(url, params)
15
+ end
16
+
17
+ def self.details(options = {})
18
+ get("#{build_url(options)}/#{options[:id]}", options)
19
+ end
20
+
21
+ def self.update(options = {})
22
+ put("#{build_url(options)}/#{options[:id]}", options)
23
+ end
24
+
25
+ def self.destroy(options = {})
26
+ delete("#{build_url(options)}/#{options[:id]}", options)
27
+ end
28
+
29
+ private
30
+
31
+ def self.build_url(options)
32
+ if !options.include?(:video_id)
33
+ STDERR.puts "The video_id option is required for this endpoint."
34
+ end
35
+ video_id = options.delete(:video_id)
36
+ "/videos/#{video_id}/calls_to_action"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ module Sproutvideo
2
+ class Folder < Resource
3
+ def self.create(options = {})
4
+ post('/folders', options)
5
+ end
6
+
7
+ def self.list(options={})
8
+ params = {
9
+ :page => options.delete(:page) || 1,
10
+ :per_page => options.delete(:per_page) || 25
11
+ }
12
+ params = params.merge(options)
13
+ get('/folders', params)
14
+ end
15
+
16
+ def self.details(folder_id, options = {})
17
+ get("/folders/#{folder_id}", options)
18
+ end
19
+
20
+ def self.update(folder_id, options = {})
21
+ put("/folders/#{folder_id}", options)
22
+ end
23
+
24
+ def self.destroy(folder_id, options = {})
25
+ delete("/folders/#{folder_id}", options)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,43 @@
1
+ module Sproutvideo
2
+ class LiveStream < Resource
3
+
4
+ def self.create(options={})
5
+ if options.include?(:custom_poster_frame)
6
+ poster_frame = options.delete(:custom_poster_frame)
7
+ upload("/live_streams", poster_frame, options, :custom_poster_frame)
8
+ else
9
+ post("/live_streams", options)
10
+ end
11
+ end
12
+
13
+ def self.list(options={})
14
+ params = {
15
+ :page => options.delete(:page) || 1,
16
+ :per_page => options.delete(:per_page) || 25
17
+ }
18
+ params = params.merge(options)
19
+ get("/live_streams", params)
20
+ end
21
+
22
+ def self.details(live_stream_id, options={})
23
+ get("/live_streams/#{live_stream_id}", options)
24
+ end
25
+
26
+ def self.update(live_stream_id, options={})
27
+ if options.include?(:custom_poster_frame)
28
+ poster_frame = options.delete(:custom_poster_frame)
29
+ upload("/live_streams/#{live_stream_id}", poster_frame, options.merge({method: :PUT}), :custom_poster_frame)
30
+ else
31
+ put("/live_streams/#{live_stream_id}", options)
32
+ end
33
+ end
34
+
35
+ def self.destroy(live_stream_id, options={})
36
+ delete("/live_streams/#{live_stream_id}", options)
37
+ end
38
+
39
+ def self.end_stream(live_stream_id, options={})
40
+ put("/live_streams/#{live_stream_id}/end_stream", options)
41
+ end
42
+ end
43
+ end
@@ -20,18 +20,14 @@ module Sproutvideo
20
20
  Response.new(resp)
21
21
  end
22
22
 
23
- def self.upload(path, file_path, options={})
23
+ def self.upload(path, file_path, options = {}, field_name)
24
24
  resp = nil
25
-
25
+
26
26
  method = options.delete(:method) == :PUT ? :PUT : :POST
27
27
 
28
28
  File.open(file_path) do |file|
29
-
30
- if method == :POST
31
- body = {:source_video => file}.merge(options.dup)
32
- else
33
- body = {:custom_poster_frame => file}
34
- end
29
+
30
+ body = { field_name => file }.merge(options.dup)
35
31
 
36
32
  begin
37
33
  resp = RestClient.send(
@@ -44,11 +40,11 @@ module Sproutvideo
44
40
  resp = e.response
45
41
  end
46
42
  end
47
-
43
+
48
44
  Response.new(resp)
49
45
  end
50
46
 
51
- def self.get(path, options={})
47
+ def self.get(path, options = {})
52
48
  begin
53
49
  resp = RestClient.get(
54
50
  "#{base_url}#{path}",
@@ -59,7 +55,7 @@ module Sproutvideo
59
55
  Response.new(resp)
60
56
  end
61
57
 
62
- def self.put(path, options={})
58
+ def self.put(path, options = {})
63
59
  body = MultiJson.encode(options.dup)
64
60
  begin
65
61
  resp = RestClient.put(
@@ -72,15 +68,15 @@ module Sproutvideo
72
68
  Response.new(resp)
73
69
  end
74
70
 
75
- def self.delete(path, options={})
71
+ def self.delete(path, options = {})
76
72
  begin
77
73
  resp = RestClient.delete(
78
74
  "#{base_url}#{path}",
79
- {'SproutVideo-Api-Key' => api_key})
75
+ {'SproutVideo-Api-Key' => api_key, :params => options.dup})
80
76
  rescue => e
81
77
  resp = e.response
82
78
  end
83
79
  Response.new(resp)
84
80
  end
85
81
  end
86
- end
82
+ end
@@ -0,0 +1,39 @@
1
+ module Sproutvideo
2
+ class Subtitle < Resource
3
+ def self.create(options = {})
4
+ post(build_url(options), options)
5
+ end
6
+
7
+ def self.list(options = {})
8
+ url = build_url(options)
9
+ params = {
10
+ :page => options.delete(:page) || 1,
11
+ :per_page => options.delete(:per_page) || 25
12
+ }
13
+ params = params.merge(options)
14
+ get(url, params)
15
+ end
16
+
17
+ def self.details(options = {})
18
+ get("#{build_url(options)}/#{options[:id]}", options)
19
+ end
20
+
21
+ def self.update(options = {})
22
+ put("#{build_url(options)}/#{options[:id]}", options)
23
+ end
24
+
25
+ def self.destroy(options = {})
26
+ delete("#{build_url(options)}/#{options[:id]}", options)
27
+ end
28
+
29
+ private
30
+
31
+ def self.build_url(options)
32
+ if !options.include?(:video_id)
33
+ STDERR.puts "The video_id option is required for this endpoint."
34
+ end
35
+ video_id = options.delete(:video_id)
36
+ "/videos/#{video_id}/subtitles"
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Sproutvideo
2
- VERSION = "1.6.0"
2
+ VERSION = "1.9.0"
3
3
  end
@@ -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={})
@@ -55,12 +55,11 @@ module Sproutvideo
55
55
 
56
56
  string_to_sign << "#{url_params}"
57
57
 
58
- digest = OpenSSL::Digest::Digest.new('sha1')
58
+ digest = OpenSSL::Digest.new('sha1')
59
59
  b64_hmac = [OpenSSL::HMAC.digest(digest, Sproutvideo.api_key, string_to_sign)].pack("m").strip
60
60
  signature = CGI.escape(b64_hmac)
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,15 +1,19 @@
1
1
  require 'multi_json'
2
2
  require 'rest_client'
3
3
 
4
- require 'sproutvideo/version.rb'
5
- require 'sproutvideo/sproutvideo.rb'
6
- require 'sproutvideo/response.rb'
7
- require 'sproutvideo/resource.rb'
8
- require 'sproutvideo/video.rb'
9
- require 'sproutvideo/tag.rb'
10
- require 'sproutvideo/playlist.rb'
11
- require 'sproutvideo/login.rb'
12
- require 'sproutvideo/access_grant.rb'
13
- require 'sproutvideo/analytics.rb'
14
- require 'sproutvideo/upload_token.rb'
15
- require 'sproutvideo/account.rb'
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'
@@ -13,7 +13,7 @@ describe Sproutvideo::AccessGrant do
13
13
  end
14
14
 
15
15
  it "should POST the correct url and return a response" do
16
- data = {:email => 'test@example.com', :password => 'password'}
16
+ data = {:video_id => 'video_id', :login_d => 'login_id'}
17
17
  RestClient.should_receive(:post).with(
18
18
  @url,
19
19
  MultiJson.encode(data),
@@ -71,7 +71,7 @@ describe Sproutvideo::AccessGrant do
71
71
  end
72
72
 
73
73
  it "should PUT the correct url and return a response" do
74
- data = {:password => 'new password'}
74
+ data = {:allowed_plays => 10}
75
75
 
76
76
  RestClient.should_receive(:put).with(
77
77
  @url,
@@ -91,9 +91,20 @@ describe Sproutvideo::AccessGrant do
91
91
  it "should DELETE the correct url and return a response" do
92
92
  RestClient.should_receive(:delete).with(
93
93
  @url,
94
- {'SproutVideo-Api-Key' => @api_key}).and_return(@msg)
94
+ {'SproutVideo-Api-Key' => @api_key, :params=> {}}).and_return(@msg)
95
95
  Sproutvideo::AccessGrant.destroy(@access_grant_id).class.should == Sproutvideo::Response
96
96
  end
97
97
  end
98
98
 
99
+ describe "#bulk_create" do
100
+ it "should POST the correct url and return a response" do
101
+ data = [{:video_id => 'video_id', :login_id => 'login_id_1'}, {:video_id => 'video_id', :login_id => 'login_id_2'}]
102
+ RestClient.should_receive(:post).with(
103
+ "#{Sproutvideo.base_url}/access_grants/bulk",
104
+ MultiJson.encode(data),
105
+ {'SproutVideo-Api-Key' => @api_key}).and_return(@msg)
106
+ Sproutvideo::AccessGrant.bulk_create(data).class.should == Sproutvideo::Response
107
+ end
108
+ end
109
+
99
110
  end