sproutvideo-rb 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -105,12 +105,31 @@ Sproutvideo::Video.delete('abc123')
105
105
  ```
106
106
 
107
107
  ##Signed Embed Codes
108
- You can use this convenince method to sign an embed code
108
+ You can use this convenience method to sign an embed code. It will return the embed code URL which can be used to build an iframe embed code.
109
+ `Sproutvideo::Video.signed_embed_code(video_id, security_token, query_parameters, expiration_time, protocol)`
110
+
111
+ ###Parameters
112
+ video_id - _String_ (_Required_)
113
+ : The id of the video for which you're generating the signed embed code
114
+
115
+ security_token - _String_ (_Required_)
116
+ : The security token of the video for which you're generatingn the signed embed code
117
+
118
+ query_parameteres - _Hash_ (_Optional_)
119
+ : A hash of query parameters to be passed to the embed code. Example: `{'type' => 'hd', 'autoplay' => true}`
120
+
121
+ expiration_time - _Integer_ (_Optional_)
122
+ : The number of seconds from the Epoc that this signed embed code should expire. This defaults to 5 minutes from the time the signed embed code was generated.
123
+
124
+ protocol - _String_ (_Optional_)
125
+ : `http` or `https`. Defaults to `http`
126
+
127
+ ###Examples
109
128
  ```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
129
+ Sproutvideo::Video.signed_embed_code('abc123','def456') #sign a base embed code with no other options
130
+ Sproutvideo::Video.signed_embed_code('abc123','def456', {'type' => 'hd'}) #set parameters for the embed code such as changing the default video type to HD
131
+ Sproutvideo::Video.signed_embed_code('abc123','def456', {}, 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).
132
+ Sproutvideo::Video.signed_embed_code('abc123','def456', {}, nil, 'https') #Use https instead of http
114
133
  ```
115
134
 
116
135
  # Tags
@@ -1,3 +1,3 @@
1
1
  module Sproutvideo
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
@@ -26,13 +26,9 @@ module Sproutvideo
26
26
  delete("/videos/#{video_id}", options)
27
27
  end
28
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
-
29
+ def self.signed_embed_code(video_id, security_token, params={}, expires=nil, protocol='http')
34
30
  host = 'videos.sproutvideo.com'
35
- path = "/embed/#{video_id}/#{token}"
31
+ path = "/embed/#{video_id}/#{security_token}"
36
32
  string_to_sign = "GET\n"
37
33
  string_to_sign << "#{host}\n"
38
34
  string_to_sign << "#{path}\n"
@@ -114,8 +114,7 @@ describe Sproutvideo::Video do
114
114
  describe "#signed_embed_code" do
115
115
  before(:each) do
116
116
  @video_id = 1
117
- @url = "#{Sproutvideo.base_url}/videos/#{@video_id}"
118
- @msg = mock(:code => 200, :to_s => '{"security_token":"abc123"}')
117
+ @security_token = 'abc123'
119
118
  @digest = OpenSSL::Digest::Digest.new('sha1')
120
119
  OpenSSL::Digest::Digest.stub!(:new).and_return(@digest)
121
120
  time = Time.now
@@ -123,35 +122,27 @@ describe Sproutvideo::Video do
123
122
  @expires_time = time.to_i+300
124
123
  string_to_sign = "GET\nvideos.sproutvideo.com\n/embed/1/abc123\n&expires=#{@expires_time}"
125
124
  @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
125
  end
135
126
 
136
127
  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}"
128
+ Sproutvideo::Video.signed_embed_code(@video_id, @security_token).should == "http://videos.sproutvideo.com/embed/1/abc123?signature=#{@signature}&expires=#{@expires_time}"
138
129
  end
139
130
 
140
131
  it "should set the expires time if passed in" do
141
132
  expires_time = 1368127991
142
133
  string_to_sign = "GET\nvideos.sproutvideo.com\n/embed/1/abc123\n&expires=#{expires_time}"
143
134
  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}"
135
+ Sproutvideo::Video.signed_embed_code(@video_id, @security_token, {}, 1368127991).should == "http://videos.sproutvideo.com/embed/1/abc123?signature=#{signature}&expires=#{expires_time}"
145
136
  end
146
137
 
147
138
  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}"
139
+ Sproutvideo::Video.signed_embed_code(@video_id, @security_token,{}, nil, 'https').should == "https://videos.sproutvideo.com/embed/1/abc123?signature=#{@signature}&expires=#{@expires_time}"
149
140
  end
150
141
 
151
142
  it "should sign other parameters too!" do
152
143
  string_to_sign = "GET\nvideos.sproutvideo.com\n/embed/1/abc123\n&expires=#{@expires_time}&type=hd"
153
144
  @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"
145
+ Sproutvideo::Video.signed_embed_code(@video_id, @security_token,{'type' => 'hd'}).should == "http://videos.sproutvideo.com/embed/1/abc123?signature=#{@signature}&expires=#{@expires_time}&type=hd"
155
146
  end
156
147
  end
157
148
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "sproutvideo-rb"
8
- s.version = "1.3.0"
8
+ s.version = "1.3.1"
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-05-08"
12
+ s.date = "2013-05-09"
13
13
  s.description = "SproutVideo API Client"
14
14
  s.email = "support@sproutvideo.com"
15
15
  s.extra_rdoc_files = [
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 0
10
- version: 1.3.0
9
+ - 1
10
+ version: 1.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - SproutVideo
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-05-08 00:00:00 Z
18
+ date: 2013-05-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client