sproutvideo-rb 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +11 -2
- data/lib/sproutvideo/version.rb +1 -1
- data/lib/sproutvideo/video.rb +33 -0
- data/spec/sproutvideo/video_spec.rb +44 -0
- data/sproutvideo-rb.gemspec +3 -3
- metadata +20 -20
data/README.markdown
CHANGED
@@ -103,6 +103,16 @@ Pass in the id of the video you wish to delete.
|
|
103
103
|
```ruby
|
104
104
|
Sproutvideo::Video.delete('abc123')
|
105
105
|
```
|
106
|
+
|
107
|
+
##Signed Embed Codes
|
108
|
+
You can use this convenince method to sign an embed code
|
109
|
+
```ruby
|
110
|
+
Sproutvideo::Video.signed_embed_code('abc123') #sign a base embed code with no other options
|
111
|
+
Sproutvideo::Video.signed_embed_code('abc123', {'type' => 'hd'}) #set parameters for the embed code such as changing the default video type to HD
|
112
|
+
Sproutvideo::Video.signed_embed_code('abc123', {}, 1368127991) #set a specific expiration time for the signed embed code. (By default the expiration time is set to 5 minutes from the time the signed embed code was generated).
|
113
|
+
Sproutvideo::Video.signed_embed_code('abc123', {}, nil, 'https') #Use https instead of http
|
114
|
+
```
|
115
|
+
|
106
116
|
# Tags
|
107
117
|
The following methods are available: `list`, `create`, `details`, `update`, `delete`.
|
108
118
|
|
@@ -345,5 +355,4 @@ Sproutvideo::Analytics.engagement_sessions('abc123', :page => 3, :per_page => 40
|
|
345
355
|
# Copyright
|
346
356
|
|
347
357
|
Copyright (c) 2012 SproutVideo. See LICENSE.txt for
|
348
|
-
further details.
|
349
|
-
|
358
|
+
further details.
|
data/lib/sproutvideo/version.rb
CHANGED
data/lib/sproutvideo/video.rb
CHANGED
@@ -25,5 +25,38 @@ module Sproutvideo
|
|
25
25
|
def self.destroy(video_id, options={})
|
26
26
|
delete("/videos/#{video_id}", options)
|
27
27
|
end
|
28
|
+
|
29
|
+
def self.signed_embed_code(video_id, params={}, expires=nil, protocol='http')
|
30
|
+
#get video
|
31
|
+
resp = get("/videos/#{video_id}")
|
32
|
+
token = resp.body[:security_token]
|
33
|
+
|
34
|
+
host = 'videos.sproutvideo.com'
|
35
|
+
path = "/embed/#{video_id}/#{token}"
|
36
|
+
string_to_sign = "GET\n"
|
37
|
+
string_to_sign << "#{host}\n"
|
38
|
+
string_to_sign << "#{path}\n"
|
39
|
+
|
40
|
+
expires = Time.now.to_i + 300 unless expires
|
41
|
+
|
42
|
+
params = params.merge('expires' => expires)
|
43
|
+
|
44
|
+
url_params = ""
|
45
|
+
actual_url_params = ""
|
46
|
+
params.sort_by{|k,_|k}.each do |key, value|
|
47
|
+
value = value.to_s.strip
|
48
|
+
url_params << "&#{key}=#{CGI::unescape(value)}"
|
49
|
+
actual_url_params << "&#{key}=#{value}"
|
50
|
+
end
|
51
|
+
|
52
|
+
string_to_sign << "#{url_params}"
|
53
|
+
|
54
|
+
digest = OpenSSL::Digest::Digest.new('sha1')
|
55
|
+
b64_hmac = [OpenSSL::HMAC.digest(digest, Sproutvideo.api_key, string_to_sign)].pack("m").strip
|
56
|
+
signature = CGI.escape(b64_hmac)
|
57
|
+
|
58
|
+
"#{protocol}://#{host}#{path}?signature=#{signature}#{actual_url_params}"
|
59
|
+
end
|
60
|
+
|
28
61
|
end
|
29
62
|
end
|
@@ -111,4 +111,48 @@ describe Sproutvideo::Video do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
+
describe "#signed_embed_code" do
|
115
|
+
before(:each) do
|
116
|
+
@video_id = 1
|
117
|
+
@url = "#{Sproutvideo.base_url}/videos/#{@video_id}"
|
118
|
+
@msg = mock(:code => 200, :to_s => '{"security_token":"abc123"}')
|
119
|
+
@digest = OpenSSL::Digest::Digest.new('sha1')
|
120
|
+
OpenSSL::Digest::Digest.stub!(:new).and_return(@digest)
|
121
|
+
time = Time.now
|
122
|
+
Time.stub!(:now).and_return(time)
|
123
|
+
@expires_time = time.to_i+300
|
124
|
+
string_to_sign = "GET\nvideos.sproutvideo.com\n/embed/1/abc123\n&expires=#{@expires_time}"
|
125
|
+
@signature = CGI::escape([OpenSSL::HMAC.digest(@digest, @api_key, string_to_sign)].pack("m").strip)
|
126
|
+
RestClient.stub!(:get).and_return(@msg)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should get the video" do
|
130
|
+
RestClient.should_receive(:get).with(
|
131
|
+
@url,
|
132
|
+
{'SproutVideo-Api-Key' => @api_key, :params => {}}).and_return(@msg)
|
133
|
+
Sproutvideo::Video.signed_embed_code(@video_id)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should sign the embed code" do
|
137
|
+
Sproutvideo::Video.signed_embed_code(@video_id).should == "http://videos.sproutvideo.com/embed/1/abc123?signature=#{@signature}&expires=#{@expires_time}"
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should set the expires time if passed in" do
|
141
|
+
expires_time = 1368127991
|
142
|
+
string_to_sign = "GET\nvideos.sproutvideo.com\n/embed/1/abc123\n&expires=#{expires_time}"
|
143
|
+
signature = CGI::escape([OpenSSL::HMAC.digest(@digest, @api_key, string_to_sign)].pack("m").strip)
|
144
|
+
Sproutvideo::Video.signed_embed_code(@video_id, {}, 1368127991).should == "http://videos.sproutvideo.com/embed/1/abc123?signature=#{signature}&expires=#{expires_time}"
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should use the protocol that's passed in" do
|
148
|
+
Sproutvideo::Video.signed_embed_code(@video_id, {}, nil, 'https').should == "https://videos.sproutvideo.com/embed/1/abc123?signature=#{@signature}&expires=#{@expires_time}"
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should sign other parameters too!" do
|
152
|
+
string_to_sign = "GET\nvideos.sproutvideo.com\n/embed/1/abc123\n&expires=#{@expires_time}&type=hd"
|
153
|
+
@signature = CGI::escape([OpenSSL::HMAC.digest(@digest, @api_key, string_to_sign)].pack("m").strip)
|
154
|
+
Sproutvideo::Video.signed_embed_code(@video_id, {'type' => 'hd'}).should == "http://videos.sproutvideo.com/embed/1/abc123?signature=#{@signature}&expires=#{@expires_time}&type=hd"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
114
158
|
end
|
data/sproutvideo-rb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "sproutvideo-rb"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["SproutVideo"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-05-08"
|
13
13
|
s.description = "SproutVideo API Client"
|
14
14
|
s.email = "support@sproutvideo.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
|
|
49
49
|
s.homepage = "http://github.com/sproutvideo/sproutvideo-rb"
|
50
50
|
s.licenses = ["MIT"]
|
51
51
|
s.require_paths = ["lib"]
|
52
|
-
s.rubygems_version = "1.8.
|
52
|
+
s.rubygems_version = "1.8.25"
|
53
53
|
s.summary = "SproutVideo API Client"
|
54
54
|
|
55
55
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sproutvideo-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 1.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- SproutVideo
|
@@ -15,9 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-
|
18
|
+
date: 2013-05-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
+
name: rest-client
|
22
|
+
prerelease: false
|
21
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
22
24
|
none: false
|
23
25
|
requirements:
|
@@ -27,11 +29,11 @@ dependencies:
|
|
27
29
|
segments:
|
28
30
|
- 0
|
29
31
|
version: "0"
|
30
|
-
prerelease: false
|
31
32
|
type: :runtime
|
32
|
-
name: rest-client
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
+
name: multi_json
|
36
|
+
prerelease: false
|
35
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
36
38
|
none: false
|
37
39
|
requirements:
|
@@ -41,11 +43,11 @@ dependencies:
|
|
41
43
|
segments:
|
42
44
|
- 0
|
43
45
|
version: "0"
|
44
|
-
prerelease: false
|
45
46
|
type: :runtime
|
46
|
-
name: multi_json
|
47
47
|
version_requirements: *id002
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
prerelease: false
|
49
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
50
52
|
none: false
|
51
53
|
requirements:
|
@@ -57,11 +59,11 @@ dependencies:
|
|
57
59
|
- 8
|
58
60
|
- 0
|
59
61
|
version: 2.8.0
|
60
|
-
prerelease: false
|
61
62
|
type: :development
|
62
|
-
name: rspec
|
63
63
|
version_requirements: *id003
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
|
+
name: rdoc
|
66
|
+
prerelease: false
|
65
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
66
68
|
none: false
|
67
69
|
requirements:
|
@@ -72,11 +74,11 @@ dependencies:
|
|
72
74
|
- 3
|
73
75
|
- 12
|
74
76
|
version: "3.12"
|
75
|
-
prerelease: false
|
76
77
|
type: :development
|
77
|
-
name: rdoc
|
78
78
|
version_requirements: *id004
|
79
79
|
- !ruby/object:Gem::Dependency
|
80
|
+
name: bundler
|
81
|
+
prerelease: false
|
80
82
|
requirement: &id005 !ruby/object:Gem::Requirement
|
81
83
|
none: false
|
82
84
|
requirements:
|
@@ -88,11 +90,11 @@ dependencies:
|
|
88
90
|
- 0
|
89
91
|
- 0
|
90
92
|
version: 1.0.0
|
91
|
-
prerelease: false
|
92
93
|
type: :development
|
93
|
-
name: bundler
|
94
94
|
version_requirements: *id005
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
|
+
name: jeweler
|
97
|
+
prerelease: false
|
96
98
|
requirement: &id006 !ruby/object:Gem::Requirement
|
97
99
|
none: false
|
98
100
|
requirements:
|
@@ -104,11 +106,11 @@ dependencies:
|
|
104
106
|
- 8
|
105
107
|
- 3
|
106
108
|
version: 1.8.3
|
107
|
-
prerelease: false
|
108
109
|
type: :development
|
109
|
-
name: jeweler
|
110
110
|
version_requirements: *id006
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
+
name: rcov
|
113
|
+
prerelease: false
|
112
114
|
requirement: &id007 !ruby/object:Gem::Requirement
|
113
115
|
none: false
|
114
116
|
requirements:
|
@@ -118,9 +120,7 @@ dependencies:
|
|
118
120
|
segments:
|
119
121
|
- 0
|
120
122
|
version: "0"
|
121
|
-
prerelease: false
|
122
123
|
type: :development
|
123
|
-
name: rcov
|
124
124
|
version_requirements: *id007
|
125
125
|
description: SproutVideo API Client
|
126
126
|
email: support@sproutvideo.com
|
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
189
|
requirements: []
|
190
190
|
|
191
191
|
rubyforge_project:
|
192
|
-
rubygems_version: 1.8.
|
192
|
+
rubygems_version: 1.8.25
|
193
193
|
signing_key:
|
194
194
|
specification_version: 3
|
195
195
|
summary: SproutVideo API Client
|