opentok 0.0.72 → 0.0.73

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
2
4
  Bundler::GemHelper.install_tasks
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
@@ -9,53 +9,28 @@ module OpenTok
9
9
  class Archive
10
10
  attr_accessor :archive_id, :archive_title, :resources, :timeline
11
11
 
12
- def initialize(archive_id, archive_title, resources, timeline, apiUrl, token)
12
+ def initialize(archive_id, archive_title, resources, timeline, api_url, token)
13
13
  @archive_id = archive_id
14
14
  @archive_title = archive_title
15
15
  @resources = resources
16
16
  @timeline = timeline
17
- @apiUrl = apiUrl
17
+ @api_url = api_url
18
18
  @token = token
19
19
  end
20
20
 
21
- def do_request(api_url, token)
22
- url = URI.parse(api_url)
23
- req = Net::HTTP::Get.new(url.path)
24
-
25
- req.add_field 'X-TB-TOKEN-AUTH', token
26
-
27
- http = Net::HTTP.new(url.host, url.port)
28
- http.use_ssl = true if @apiUrl.start_with?("https")
29
- res = http.start {|http| http.request(req)}
30
- case res
31
- when Net::HTTPSuccess, Net::HTTPRedirection
32
- return res.read_body
33
- else
34
- res.error!
35
- end
36
- rescue Net::HTTPExceptions
37
- raise
38
- raise OpenTokException.new 'Unable to create fufill request: ' + $!
39
- rescue NoMethodError
40
- raise
41
- raise OpenTokException.new 'Unable to create a fufill request at this time: ' + $1
42
- end
43
-
44
- def download_archive_url(video_id)
45
- doc = do_request "#{@apiUrl}/archive/url/#{@archive_id}/#{video_id}"
46
- if not doc.get_elements('Errors').empty?
47
- raise OpenTokException.new doc.get_elements('Errors')[0].get_elements('error')[0].children.to_s
48
- end
49
- doc
21
+ def do_request(path, token)
22
+ OpenTok::Request.new(@api_url, token).fetch(path)
50
23
  end
51
24
 
52
- def downloadArchiveURL(video_id, token="")
25
+ def download_archive_url(video_id, token="")
53
26
  if token==""
54
- return "#{@apiUrl}/archive/url/#{@archive_id}/#{video_id}"
27
+ # this token check supports previous implementation of download_archive_url
28
+ return "#{@api_url}/archive/url/#{@archive_id}/#{video_id}"
55
29
  else
56
- return do_request "#{@apiUrl}/archive/url/#{@archive_id}/#{video_id}", token
30
+ return do_request "/archive/url/#{@archive_id}/#{video_id}", token
57
31
  end
58
32
  end
33
+ alias_method :downloadArchiveURL, :download_archive_url
59
34
 
60
35
  def self.parse_manifest(manifest, apiUrl, token)
61
36
  archive_id = manifest.attributes['archiveid']
@@ -6,11 +6,8 @@
6
6
 
7
7
  =end
8
8
 
9
- require 'cgi'
10
9
  require 'openssl'
11
10
  require 'base64'
12
- require 'uri'
13
- require 'net/https'
14
11
  require 'rexml/document'
15
12
 
16
13
  DIGEST = OpenSSL::Digest::Digest.new('sha1')
@@ -24,7 +21,7 @@ module OpenTok
24
21
  # * +MULTIPLEXER_SWITCHTYPE+ integer
25
22
  # * +MULTIPLEXER_SWITCHTIMEOUT+ integer
26
23
  # * +P2P_PREFERENCE+ string
27
- class SessionPropertyConstants
24
+ module SessionPropertyConstants
28
25
  ECHOSUPPRESSION_ENABLED = "echoSuppression.enabled" #Boolean
29
26
  MULTIPLEXER_NUMOUTPUTSTREAMS = "multiplexer.numOutputStreams" #Integer
30
27
  MULTIPLEXER_SWITCHTYPE = "multiplexer.switchType" #Integer
@@ -37,7 +34,7 @@ module OpenTok
37
34
  # * +SUBSCRIBER+ Can only subscribe
38
35
  # * +PUBLISHER+ Can publish, subscribe, and signal
39
36
  # * +MODERATOR+ Can do the above along with forceDisconnect and forceUnpublish
40
- class RoleConstants
37
+ module RoleConstants
41
38
  SUBSCRIBER = "subscriber" #Can only subscribe
42
39
  PUBLISHER = "publisher" #Can publish, subscribe, and signal
43
40
  MODERATOR = "moderator" #Can do the above along with forceDisconnect and forceUnpublish
@@ -52,7 +49,7 @@ module OpenTok
52
49
  #
53
50
  # The first two attributes are required; +parnter_id+ and +partner_secret+ are the api-key and secret
54
51
  # that are provided to you.
55
- #
52
+ #
56
53
  # You can also pass in optional options;
57
54
  # * +:api_url+ sets the location of the api (staging or production)
58
55
  def initialize(partner_id, partner_secret, options = nil)
@@ -74,15 +71,12 @@ module OpenTok
74
71
 
75
72
  # Generate token for the given session_id. The options you can provide are;
76
73
  # * +:session_id+ (required) generate a token for the provided session
77
- # * +:create_time+
74
+ # * +:create_time+
78
75
  # * +:expire_time+ (optional) The time when the token will expire, defined as an integer value for a Unix timestamp (in seconds). If you do not specify this value, tokens expire in 24 hours after being created.
79
76
  # * +:role+ (optional) Added in OpenTok v0.91.5. This defines the role the user will have. There are three roles: subscriber, publisher, and moderator.
80
77
  # * +:connection_data+ (optional) Added in OpenTok v0.91.20. A string containing metadata describing the connection.
81
78
  #
82
79
  # See http://www.tokbox.com/opentok/tools/documentation/overview/token_creation.html for more information on all options.
83
- def generateToken(opts={})
84
- generate_token(opts)
85
- end
86
80
  def generate_token(opts = {})
87
81
  { :session_id => nil, :create_time => nil, :expire_time => nil, :role => nil, :connection_data => nil }.merge!(opts)
88
82
 
@@ -113,23 +107,18 @@ module OpenTok
113
107
  data_params[:connection_data] = opts[:connection_data]
114
108
  end
115
109
 
116
- data_string = data_params.urlencode
110
+ data_string = OpenTok::Utils.urlencode_hash(data_params)
117
111
 
118
112
  sig = sign_string(data_string, @partner_secret)
119
- meta_string = {
120
- :partner_id => @partner_id,
121
- :sig => sig
122
- }.urlencode
113
+ meta_string = OpenTok::Utils.urlencode_hash(:partner_id => @partner_id, :sig => sig)
123
114
 
124
115
  @@TOKEN_SENTINEL + Base64.encode64(meta_string + ":" + data_string).gsub("\n", '')
125
116
  end
117
+ alias_method :generateToken, :generate_token
126
118
 
127
119
  # Generates a new OpenTok::Session and set it's session_id, situating it in TokBox's global network near the IP of the specified @location@.
128
120
  #
129
121
  # See http://www.tokbox.com/opentok/tools/documentation/overview/session_creation.html for more information
130
- def createSession(location='', opts={})
131
- create_session(location, opts)
132
- end
133
122
  def create_session(location='', opts={})
134
123
  opts.merge!({:partner_id => @partner_id, :location=>location})
135
124
  doc = do_request("/session/create", opts)
@@ -138,12 +127,10 @@ module OpenTok
138
127
  end
139
128
  OpenTok::Session.new(doc.root.get_elements('Session')[0].get_elements('session_id')[0].children[0].to_s)
140
129
  end
130
+ alias_method :createSession, :create_session
141
131
 
142
132
  # This method takes two parameters. The first parameter is the +archive_id+ of the archive that contains the video (a String). The second parameter is the +token+ (a String)
143
133
  # The method returns an +OpenTok::Archive+ object. The resources property of this object is an array of OpenTok::ArchiveVideoResource objects. Each OpenTok::ArchiveVideoResource object represents a video in the archive.
144
- def getArchiveManifest(archive_id, token)
145
- get_archive_manifest(archive_id, token)
146
- end
147
134
  def get_archive_manifest(archive_id, token)
148
135
  # TODO: verify that token is MODERATOR token, Staging and production
149
136
 
@@ -153,44 +140,37 @@ module OpenTok
153
140
  end
154
141
  OpenTok::Archive.parse_manifest(doc.get_elements('manifest')[0], @api_url, token)
155
142
  end
143
+ alias_method :getArchiveManifest, :get_archive_manifest
144
+
145
+ def stitchArchive(aid)
146
+ stitchURL = "/archive/#{aid}/stitch"
147
+ request = OpenTok::Request.new(@api_url, nil, @partner_id, @partner_secret)
148
+ response = request.sendRequest(stitchURL, {test:'none'})
149
+ case response.code
150
+ when '201'
151
+ return {:code=>201, :message=>"Successfully Created", :location=>response["location"]}
152
+ when '202'
153
+ return {:code=>202, :message=>"Processing"}
154
+ when '403'
155
+ return {:code=>403, :message=>"Invalid Credentials"}
156
+ when '404'
157
+ return {:code=>404, :message=>"Archive Does Not Exist"}
158
+ else
159
+ return {:code=>500, :message=>"Server Error"}
160
+ end
161
+ return {}
162
+ end
163
+ alias_method :stitch, :get_archive_manifest
156
164
 
157
165
  protected
158
166
  def sign_string(data, secret)
159
167
  OpenSSL::HMAC.hexdigest(DIGEST, secret, data)
160
168
  end
161
169
 
162
- def do_request(api_url, params, token=nil)
163
- url = URI.parse(@api_url + api_url)
164
- if not params.empty?
165
- req = Net::HTTP::Post.new(url.path)
166
- req.set_form_data(params)
167
- else
168
- req = Net::HTTP::Get.new(url.path)
169
- end
170
-
171
- if not token.nil?
172
- req.add_field 'X-TB-TOKEN-AUTH', token
173
- else
174
- req.add_field 'X-TB-PARTNER-AUTH', "#{@partner_id}:#{@partner_secret}"
175
- end
176
- http = Net::HTTP.new(url.host, url.port)
177
- http.use_ssl = true if @api_url.start_with?("https")
178
- res = http.start {|http| http.request(req)}
179
- case res
180
- when Net::HTTPSuccess, Net::HTTPRedirection
181
- # OK
182
- doc = REXML::Document.new(res.read_body)
183
- return doc
184
- else
185
- res.error!
186
- end
187
- rescue Net::HTTPExceptions
188
- raise
189
- raise OpenTokException.new 'Unable to create fufill request: ' + $!
190
- rescue NoMethodError
191
- raise
192
- raise OpenTokException.new 'Unable to create a fufill request at this time: ' + $1
170
+ def do_request(path, params, token=nil)
171
+ request = OpenTok::Request.new(@api_url, token, @partner_id, @partner_secret)
172
+ body = request.fetch(path, params)
173
+ REXML::Document.new(body)
193
174
  end
194
175
  end
195
176
  end
196
-
@@ -0,0 +1,57 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'net/https'
4
+
5
+ Net::HTTP.version_1_2 # to make sure version 1.2 is used
6
+
7
+ module OpenTok
8
+ class Request
9
+
10
+ def initialize(api_host, token, partner_id=nil, partner_secret=nil)
11
+ @api_host = api_host
12
+ @token = token
13
+ @partner_id = partner_id
14
+ @partner_secret = partner_secret
15
+ end
16
+
17
+ def sendRequest(path, params)
18
+ url = URI.parse(@api_host + path)
19
+
20
+ if params.empty?
21
+ req = Net::HTTP::Get.new(url.path)
22
+ else
23
+ req = Net::HTTP::Post.new(url.path)
24
+ req.set_form_data(params)
25
+ end
26
+
27
+ if @token
28
+ req.add_field 'X-TB-TOKEN-AUTH', @token
29
+ elsif @partner_id && @partner_secret
30
+ req.add_field 'X-TB-PARTNER-AUTH', "#{@partner_id}:#{@partner_secret}"
31
+ end
32
+
33
+ http = Net::HTTP.new(url.host, url.port)
34
+ http.use_ssl = @api_host.start_with?("https")
35
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
36
+
37
+ res = http.start {|h| h.request(req) }
38
+ return res
39
+ end
40
+
41
+ def fetch(path, params={})
42
+ res = sendRequest(path, params)
43
+
44
+ case res
45
+ when Net::HTTPSuccess, Net::HTTPRedirection
46
+ return res.read_body
47
+ else
48
+ res.error!
49
+ end
50
+
51
+ rescue Net::HTTPExceptions => e
52
+ raise OpenTokException.new "Unable to create fufill request: #{e}"
53
+ rescue NoMethodError => e
54
+ raise OpenTokException.new "Unable to create a fufill request at this time: #{e}"
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,19 @@
1
+ require 'cgi'
2
+
3
+ module OpenTok
4
+ module Utils
5
+ # would recommend using `addressable` gem instead
6
+ def self.urlencode_hash(hash)
7
+ hash.to_a.map do |name_value|
8
+ if name_value[1].is_a? Array
9
+ name_value[0] = CGI.escape name_value[0].to_s
10
+ name_value[1].map { |e| CGI.escape e.to_s }
11
+ name_value[1] = name_value[1].join "&" + name_value[0] + "="
12
+ name_value.join '='
13
+ else
14
+ name_value.map { |e| CGI.escape e.to_s }.join '='
15
+ end
16
+ end.join '&'
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Opentok
2
- VERSION = "0.0.72"
2
+ VERSION = "0.0.73"
3
3
  end
data/lib/opentok.rb CHANGED
@@ -9,20 +9,14 @@
9
9
 
10
10
  module OpenTok
11
11
  require 'rubygems'
12
- require 'net/http'
13
- require 'uri'
14
- require 'digest/md5'
15
- require 'cgi'
16
- #require 'pp' # just for debugging purposes
17
-
18
- Net::HTTP.version_1_2 # to make sure version 1.2 is used
19
12
 
20
13
  VERSION = "tbrb-v0.91.2011-02-17"
21
14
  API_URL = "https://staging.tokbox.com/hl"
22
15
  API_URL_PROD = 'https://api.opentok.com/hl'
23
-
24
- require 'monkey_patches'
16
+
25
17
  require 'open_tok/exception'
18
+ require 'open_tok/utils'
19
+ require 'open_tok/request'
26
20
  require 'open_tok/open_tok_sdk'
27
21
  require 'open_tok/session'
28
22
  require 'open_tok/archive'
data/opentok.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Opentok::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Stijn Mathysen", "Karmen Blake", "Song Zheng"]
10
- s.email = ["stijn@skylight.be", "karmenblake@gmail.com", "Song Zheng"]
10
+ s.email = ["stijn@skylight.be", "karmenblake@gmail.com", "song@tokbox.com"]
11
11
  s.homepage = "https://github.com/opentok/Opentok-Ruby-SDK"
12
12
  s.summary = %q{OpenTok gem}
13
13
  s.description = %q{OpenTok is an API from TokBox that enables websites to weave live group video communication into their online experience. With OpenTok you have the freedom and flexibility to create the most engaging web experience for your users. OpenTok is currently available as a JavaScript and ActionScript 3.0 library. This gem allows you to connect to the API from within Ruby (and Rails)}
@@ -18,4 +18,9 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "rspec"
24
+ s.add_development_dependency "webmock"
25
+ s.add_development_dependency "vcr"
21
26
  end
@@ -0,0 +1,81 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.opentok.com/hl/archive/getmanifest/5f74aee5-ab3f-421b-b124-ed2a698ee939
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ X-Tb-Token-Auth:
15
+ - T1==cGFydG5lcl9pZD0xMTQyMTg3MiZzaWc9YTVlNWY3YjA1ZTZjMzE1NDdmZmIxNzE5NWQ0MGQxYzdiYTRlZjQ3NTpyb2xlPW1vZGVyYXRvciZzZXNzaW9uX2lkPTFfTVg0eE5EazNNVEk1TW41LU1qQXhNaTB3TlMweU1DQXdNVG93TXpvek1TNDFNREV6TURBck1EQTZNREItTUM0ME5qSTBNakk0TWpVMU1ERi0mY3JlYXRlX3RpbWU9MTM0NTEzNTg1MyZub25jZT0wLjUwODk3Nzg4NjYxNTIyODg=
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Thu, 16 Aug 2012 16:50:54 GMT
25
+ Content-Type:
26
+ - text/xml; charset=utf-8
27
+ Connection:
28
+ - keep-alive
29
+ Pragma:
30
+ - no-cache
31
+ Cache-Control:
32
+ - no-cache
33
+ Content-Length:
34
+ - '345'
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ! "<manifest version=\"0.1\" archiveid=\"5f74aee5-ab3f-421b-b124-ed2a698ee939\"
38
+ title=\"Song Test Archive\">\n <resources>\n <video id=\"4b7227de-3b3f-45a7-a2dd-bffe6bf62085\"
39
+ length=\"5118\" name=\"\"/>\n </resources>\n <timeline>\n <event
40
+ type=\"PLAY\" id=\"4b7227de-3b3f-45a7-a2dd-bffe6bf62085\" offset=\"1625\"
41
+ data=\"\" />\n </timeline>\n</manifest>\n\n\n"
42
+ http_version:
43
+ recorded_at: Thu, 16 Aug 2012 16:50:54 GMT
44
+ - request:
45
+ method: get
46
+ uri: https://api.opentok.com/hl/archive/url/5f74aee5-ab3f-421b-b124-ed2a698ee939/4b7227de-3b3f-45a7-a2dd-bffe6bf62085
47
+ body:
48
+ encoding: US-ASCII
49
+ string: ''
50
+ headers:
51
+ Accept:
52
+ - ! '*/*'
53
+ User-Agent:
54
+ - Ruby
55
+ X-Tb-Token-Auth:
56
+ - T1==cGFydG5lcl9pZD0xMTQyMTg3MiZzaWc9Mjk0ZjM4NzkwMjY3OTIxOTI1MjdiYjAzM2M1ZmNkNDhkNGFmMGRlZTpyb2xlPW1vZGVyYXRvciZzZXNzaW9uX2lkPTFfTVg0eE5EazNNVEk1TW41LU1qQXhNaTB3TlMweU1DQXdNVG93TXpvek1TNDFNREV6TURBck1EQTZNREItTUM0ME5qSTBNakk0TWpVMU1ERi0mY3JlYXRlX3RpbWU9MTM0NTEzNTg1NCZub25jZT0wLjc0MDc2NjMyNTg0NTYzNTE=
57
+ response:
58
+ status:
59
+ code: 200
60
+ message: OK
61
+ headers:
62
+ Server:
63
+ - nginx
64
+ Date:
65
+ - Thu, 16 Aug 2012 16:50:55 GMT
66
+ Content-Type:
67
+ - text/html; charset=utf-8
68
+ Connection:
69
+ - keep-alive
70
+ Pragma:
71
+ - no-cache
72
+ Cache-Control:
73
+ - no-cache
74
+ Content-Length:
75
+ - '229'
76
+ body:
77
+ encoding: US-ASCII
78
+ string: https://s3.amazonaws.com/tokbox.com.production/11421872/5f74aee5-ab3f-421b-b124-ed2a698ee939/4b7227de-3b3f-45a7-a2dd-bffe6bf62085.flv?Signature=OTlzzfyKuNiukuyVcEaKP0pf8lU%3D&Expires=1345139455&AWSAccessKeyId=AKIAI6LQCPIXYVWCQV6Q
79
+ http_version:
80
+ recorded_at: Thu, 16 Aug 2012 16:50:55 GMT
81
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://staging.tokbox.com/hl/session/create
6
+ body:
7
+ encoding: US-ASCII
8
+ string: partner_id=459782&location=127.0.0.1
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ X-Tb-Partner-Auth:
17
+ - 459782:b44c3baa32b6476d9d88e8194d0eb1c6b777f76b
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Thu, 16 Aug 2012 16:49:56 GMT
27
+ Content-Type:
28
+ - text/xml
29
+ Connection:
30
+ - keep-alive
31
+ Access-Control-Allow-Origin:
32
+ - ! '*'
33
+ X-Tb-Host:
34
+ - stage301-sat.tokbox.com
35
+ Content-Length:
36
+ - '282'
37
+ body:
38
+ encoding: US-ASCII
39
+ string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>2_MX40NTk3ODJ-MTI3LjAuMC4xflRodSBBdWcgMTYgMDk6NDk6NTYgUERUIDIwMTJ-MC41MDk2NDYyfg</session_id><partner_id>459782</partner_id><create_dt>Thu
40
+ Aug 16 09:49:56 PDT 2012</create_dt></Session></sessions>
41
+ http_version:
42
+ recorded_at: Thu, 16 Aug 2012 16:49:56 GMT
43
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://staging.tokbox.com/hl/session/create
6
+ body:
7
+ encoding: US-ASCII
8
+ string: partner_id=459782&location=127.0.0.1
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ X-Tb-Partner-Auth:
17
+ - 459782:b44c3baa32b6476d9d88e8194d0eb1c6b777f76b
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Thu, 16 Aug 2012 16:50:16 GMT
27
+ Content-Type:
28
+ - text/xml
29
+ Connection:
30
+ - keep-alive
31
+ Access-Control-Allow-Origin:
32
+ - ! '*'
33
+ X-Tb-Host:
34
+ - stage301-sat.tokbox.com
35
+ Content-Length:
36
+ - '282'
37
+ body:
38
+ encoding: US-ASCII
39
+ string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>2_MX40NTk3ODJ-MTI3LjAuMC4xflRodSBBdWcgMTYgMDk6NTA6MTYgUERUIDIwMTJ-MC42MjI3MTA4fg</session_id><partner_id>459782</partner_id><create_dt>Thu
40
+ Aug 16 09:50:16 PDT 2012</create_dt></Session></sessions>
41
+ http_version:
42
+ recorded_at: Thu, 16 Aug 2012 16:50:16 GMT
43
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://staging.tokbox.com/hl/session/create
6
+ body:
7
+ encoding: US-ASCII
8
+ string: partner_id=0&location=localhost
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ X-Tb-Partner-Auth:
17
+ - ! '0:'
18
+ response:
19
+ status:
20
+ code: 403
21
+ message: Forbidden
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Thu, 16 Aug 2012 16:51:18 GMT
27
+ Content-Type:
28
+ - text/plain; charset=iso-8859-1
29
+ Connection:
30
+ - keep-alive
31
+ Content-Length:
32
+ - '0'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ''
36
+ http_version:
37
+ recorded_at: Thu, 16 Aug 2012 16:51:18 GMT
38
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://staging.tokbox.com/hl/session/create
6
+ body:
7
+ encoding: US-ASCII
8
+ string: partner_id=459782&location=localhost
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ X-Tb-Partner-Auth:
17
+ - 459782:b44c3baa32b6476d9d88e8194d0eb1c6b777f76b
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Thu, 16 Aug 2012 16:51:48 GMT
27
+ Content-Type:
28
+ - text/xml
29
+ Connection:
30
+ - keep-alive
31
+ Access-Control-Allow-Origin:
32
+ - ! '*'
33
+ X-Tb-Host:
34
+ - stage301-sat.tokbox.com
35
+ Content-Length:
36
+ - '268'
37
+ body:
38
+ encoding: US-ASCII
39
+ string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX40NTk3ODJ-flRodSBBdWcgMTYgMDk6NTE6NDggUERUIDIwMTJ-MC43NjEzNDN-</session_id><partner_id>459782</partner_id><create_dt>Thu
40
+ Aug 16 09:51:48 PDT 2012</create_dt></Session></sessions>
41
+ http_version:
42
+ recorded_at: Thu, 16 Aug 2012 16:51:48 GMT
43
+ recorded_with: VCR 2.2.4
data/spec/opentok_spec.rb CHANGED
@@ -1,161 +1,157 @@
1
1
  require 'spec_helper'
2
2
 
3
- class TestOpentokSDK < OpenTok::OpenTokSDK
4
- def do_request(api_url, params, token=nil)
5
- super
6
- end
7
- end
8
-
9
3
  describe "Functionality Test" do
10
- before :all do
11
- @api_key = '459782'
12
- @api_secret = 'b44c3baa32b6476d9d88e8194d0eb1c6b777f76b'
13
- @host = '127.0.0.1'
14
- @api_staging_url = 'https://staging.tokbox.com/hl'
15
- @api_production_url = 'https://api.opentok.com/hl'
16
- end
4
+
5
+ let(:api_key) { '459782' }
6
+ let(:api_secret) { 'b44c3baa32b6476d9d88e8194d0eb1c6b777f76b' }
7
+ let(:host) { '127.0.0.1' }
8
+ let(:api_staging_url) { 'https://staging.tokbox.com/hl' }
9
+ let(:api_production_url) { 'https://api.opentok.com/hl' }
17
10
 
18
11
  describe "test Initializers" do
19
12
  it "should set staging URL with no options" do
20
- @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
21
- @opentok.api_url.should eq @api_staging_url
13
+ opentok = OpenTok::OpenTokSDK.new api_key, api_secret
14
+ opentok.api_url.should eq api_staging_url
22
15
  end
16
+
23
17
  it "should be possible to set the api url as an option" do
24
- opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret, :api_url => @api_production_url
25
- opentok.api_url.should eq @api_production_url
26
- opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret, :api_url => @api_staging_url
27
- opentok.api_url.should eq @api_staging_url
18
+ opentok = OpenTok::OpenTokSDK.new api_key, api_secret, :api_url => api_production_url
19
+ opentok.api_url.should eq api_production_url
20
+ opentok = OpenTok::OpenTokSDK.new api_key, api_secret, :api_url => api_staging_url
21
+ opentok.api_url.should eq api_staging_url
28
22
  end
23
+
29
24
  it "should set staging URL with option false" do
30
- @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret, false
31
- @opentok.api_url.should eq @api_staging_url
25
+ opentok = OpenTok::OpenTokSDK.new api_key, api_secret, false
26
+ opentok.api_url.should eq api_staging_url
32
27
  end
28
+
33
29
  it "should set production URL with option true" do
34
- @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret, true
35
- @opentok.api_url.should eq @api_production_url
30
+ opentok = OpenTok::OpenTokSDK.new api_key, api_secret, true
31
+ opentok.api_url.should eq api_production_url
36
32
  end
37
33
  end
38
34
 
39
35
  describe "Generate Sessions" do
40
- before :all do
41
- @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
42
- end
36
+ use_vcr_cassette "generate_sessions"
37
+
38
+ let(:opentok) { OpenTok::OpenTokSDK.new api_key, api_secret }
43
39
 
44
40
  it "should generate valid session" do
45
- session = @opentok.create_session @host
41
+ session = opentok.create_session host
46
42
  session.to_s.should match(/\A[0-9A-z_-]{40,}\Z/)
47
43
  end
44
+
48
45
  it "should generate valid session camelCase" do
49
- session = @opentok.createSession @host
46
+ session = opentok.createSession host
50
47
  session.to_s.should match(/\A[0-9A-z_-]{40,}\Z/)
51
48
  end
52
49
  end
53
50
 
54
51
  describe "Generate Tokens" do
55
- before :all do
56
- @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
57
- @session = @opentok.createSession @host
58
- end
52
+ use_vcr_cassette "generate_tokens"
53
+
54
+ let(:opentok) { OpenTok::OpenTokSDK.new api_key, api_secret }
55
+ let(:session) { opentok.createSession host }
59
56
 
60
57
  it "should generate valid token" do
61
- @token = @opentok.generate_token({:session_id => @session, :role=>OpenTok::RoleConstants::MODERATOR})
62
- @token.should match(/(T1==)+[0-9A-z_]+/)
58
+ token = opentok.generate_token({:session_id => session, :role=>OpenTok::RoleConstants::MODERATOR})
59
+ token.should match(/(T1==)+[0-9A-z_]+/)
63
60
  end
61
+
64
62
  it "should generate valid token camelCase" do
65
- @token = @opentok.generateToken({:session_id => @session, :role=>OpenTok::RoleConstants::MODERATOR})
66
- @token.should match(/(T1==)+[0-9A-z_]+/)
63
+ token = opentok.generateToken({:session_id => session, :role=>OpenTok::RoleConstants::MODERATOR})
64
+ token.should match(/(T1==)+[0-9A-z_]+/)
67
65
  end
68
66
  end
69
67
 
70
68
  end
71
69
 
72
70
  describe OpenTok do
73
-
74
- before :all do
75
- @api_key = '459782'
76
- @api_secret = 'b44c3baa32b6476d9d88e8194d0eb1c6b777f76b'
77
- @api_staging_url = 'https://staging.tokbox.com/hl'
78
- @api_production_url = 'https://api.opentok.com/hl'
79
- @host = 'localhost'
80
-
81
- @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
82
- end
71
+
72
+ let(:api_key) { '459782' }
73
+ let(:api_secret) { 'b44c3baa32b6476d9d88e8194d0eb1c6b777f76b' }
74
+ let(:api_staging_url) { 'https://staging.tokbox.com/hl' }
75
+ let(:api_production_url) { 'https://api.opentok.com/hl' }
76
+ let(:host) { 'localhost' }
77
+
78
+ let(:opentok) { OpenTok::OpenTokSDK.new api_key, api_secret }
83
79
 
84
80
  describe "Production Environment" do
85
- before :all do
86
- @api_key = '11421872'
87
- @api_secret = '296cebc2fc4104cd348016667ffa2a3909ec636f'
88
- @opentok = TestOpentokSDK.new @api_key, @api_secret, {:api_url=>@api_production_url}
89
- @opts = {:partner_id => @api_key, :location=>@host}
90
- end
81
+
82
+ let(:api_key) { '11421872' }
83
+ let(:api_secret) { '296cebc2fc4104cd348016667ffa2a3909ec636f' }
84
+ let(:opentok) { OpenTok::OpenTokSDK.new api_key, api_secret, {:api_url=>api_production_url} }
85
+ let(:opts) { {:partner_id => api_key, :location=>host} }
91
86
 
92
87
  it "should be possible to valid a OpenTokSDK object with a valid key and secret" do
93
- @opentok.should be_instance_of TestOpentokSDK
88
+ opentok.should be_instance_of OpenTok::OpenTokSDK
94
89
  end
95
-
90
+
96
91
  it "a new OpenTokSDK object should point to the staging environment by default" do
97
- @opentok.api_url.should eq @api_production_url
92
+ opentok.api_url.should eq api_production_url
98
93
  end
99
94
 
100
95
  describe "Archiving downloads" do
101
- before :all do
102
- @session = '1_MX4xNDk3MTI5Mn5-MjAxMi0wNS0yMCAwMTowMzozMS41MDEzMDArMDA6MDB-MC40NjI0MjI4MjU1MDF-'
103
- @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret, {:api_url=>@api_production_url}
104
- @token = @opentok.generateToken({:session_id => @session, :role=>OpenTok::RoleConstants::MODERATOR})
105
- @archiveId = '5f74aee5-ab3f-421b-b124-ed2a698ee939'
106
- end
96
+ use_vcr_cassette "archiving_downloads"
97
+
98
+ let(:session) { '1_MX4xNDk3MTI5Mn5-MjAxMi0wNS0yMCAwMTowMzozMS41MDEzMDArMDA6MDB-MC40NjI0MjI4MjU1MDF-' }
99
+ let(:opentok) { OpenTok::OpenTokSDK.new api_key, api_secret, {:api_url=>api_production_url} }
100
+ let(:token) { opentok.generateToken({:session_id => session, :role=>OpenTok::RoleConstants::MODERATOR}) }
101
+ let(:archiveId) { '5f74aee5-ab3f-421b-b124-ed2a698ee939' }
107
102
 
108
103
  it "should have archive resources" do
109
- otArchive = @opentok.getArchiveManifest(@archiveId, @token)
104
+ otArchive = opentok.getArchiveManifest(archiveId, token)
110
105
  otArchiveResource = otArchive.resources[0]
111
106
  vid = otArchiveResource.getId()
112
107
  vid.should match(/[0-9A-z=]+/)
113
108
  end
114
109
 
115
110
  it "should return download url" do
116
- otArchive = @opentok.get_archive_manifest(@archiveId, @token)
111
+ otArchive = opentok.get_archive_manifest(archiveId, token)
117
112
  otArchiveResource = otArchive.resources[0]
118
113
  vid = otArchiveResource.getId()
119
- url = otArchive.downloadArchiveURL(vid)
114
+ url = otArchive.downloadArchiveURL(vid, token)
120
115
  url.start_with?('http').should eq true
121
116
  end
122
117
 
123
118
  it "should return file url" do
124
- otArchive = @opentok.get_archive_manifest(@archiveId, @token)
119
+ otArchive = opentok.get_archive_manifest(archiveId, token)
125
120
  otArchiveResource = otArchive.resources[0]
126
121
  vid = otArchiveResource.getId()
127
- url = otArchive.downloadArchiveURL(vid, @token)
122
+ url = otArchive.downloadArchiveURL(vid, token)
128
123
  url.start_with?('http').should eq true
129
124
  end
130
125
  end
131
126
  end
132
-
133
-
127
+
128
+
134
129
  describe "Session creation" do
130
+ use_vcr_cassette "session_creation"
131
+
135
132
  it "should raise an exception with an invalid key and secret" do
136
133
  opentok = OpenTok::OpenTokSDK.new 0, ''
137
-
134
+
138
135
  expect{
139
- session = opentok.create_session @host
136
+ session = opentok.create_session host
140
137
  }.to raise_error OpenTok::OpenTokException
141
138
  end
142
-
139
+
143
140
  end
144
141
 
145
142
  describe "Token creation" do
146
- before :all do
147
- @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
148
- @valid_session = @opentok.create_session(@host).to_s
149
- end
150
-
143
+ use_vcr_cassette "token_creation"
144
+
145
+ let(:valid_session) { opentok.create_session(host).to_s }
146
+
151
147
  it "should be possible to create a token" do
152
- token = @opentok.generate_token :session_id => @valid_session.to_s
153
-
148
+ token = opentok.generate_token :session_id => valid_session
149
+
154
150
  token.should match(/\A[0-9A-z=]+\Z/)
155
151
  end
156
152
 
157
153
  it "should be able to set parameters in token" do
158
- token = @opentok.generate_token :session_id => @valid_session.to_s, :role=> OpenTok::RoleConstants::PUBLISHER, :connection_data => "username=Bob,level=4"
154
+ token = opentok.generate_token :session_id => valid_session, :role=> OpenTok::RoleConstants::PUBLISHER, :connection_data => "username=Bob,level=4"
159
155
 
160
156
  str = token[4..token.length]
161
157
  decoded = Base64.decode64(str)
@@ -165,16 +161,26 @@ describe OpenTok do
165
161
  end
166
162
 
167
163
  describe "Archive Download" do
168
- before :all do
169
- @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
170
- @valid_session = @opentok.create_session(@host).to_s
171
- end
164
+ use_vcr_cassette "archive_download"
165
+
166
+ let(:valid_session) { opentok.create_session(host).to_s }
172
167
 
173
168
  # it "If token does not have moderator role, raise error" do
174
- # token = @opentok.generate_token(:session_id=>@valid_session)
169
+ # token = opentok.generate_token(:session_id=>valid_session)
175
170
  # expect{
176
- # @opentok.get_archive_manifest("", token)
171
+ # opentok.get_archive_manifest("", token)
177
172
  # }.to raise_error OpenTok::OpenTokException
178
173
  # end
179
174
  end
175
+
176
+ describe "stitch api" do
177
+ use_vcr_cassette "archive_stitch"
178
+ it "should return stich url" do
179
+ OTKey = ENV['TB_KEY'] # Enter you OpenTok Key Here
180
+ OTSecret = ENV['TB_SECRET'] # Enter your OpenTok Secret Here
181
+ OTSDK = OpenTok::OpenTokSDK.new OTKey, OTSecret, true
182
+ a = OTSDK.stitchArchive("9cf9b35d-3c2f-432c-96b9-dbdf848ecf33")
183
+ a[:code].should == 202
184
+ end
185
+ end
180
186
  end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,15 @@
1
- require 'I18n'
2
1
  require File.dirname(__FILE__) + '/../lib/opentok.rb'
2
+
3
+ require 'vcr'
4
+ require 'webmock'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = 'spec/cassettes'
8
+ c.hook_into :webmock
9
+ c.default_cassette_options = { :record => :new_episodes }
10
+ c.allow_http_connections_when_no_cassette=true
11
+ end
12
+
13
+ RSpec.configure do |c|
14
+ c.extend VCR::RSpec::Macros
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.72
4
+ version: 0.0.73
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,8 +11,72 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-08-14 00:00:00.000000000 Z
15
- dependencies: []
14
+ date: 2012-08-21 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rake
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: webmock
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: vcr
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
16
80
  description: OpenTok is an API from TokBox that enables websites to weave live group
17
81
  video communication into their online experience. With OpenTok you have the freedom
18
82
  and flexibility to create the most engaging web experience for your users. OpenTok
@@ -21,7 +85,7 @@ description: OpenTok is an API from TokBox that enables websites to weave live g
21
85
  email:
22
86
  - stijn@skylight.be
23
87
  - karmenblake@gmail.com
24
- - Song Zheng
88
+ - song@tokbox.com
25
89
  executables: []
26
90
  extensions: []
27
91
  extra_rdoc_files: []
@@ -80,16 +144,22 @@ files:
80
144
  - doc/rdoc.css
81
145
  - doc/spec/opentok_spec_rb.html
82
146
  - doc/spec/spec_helper_rb.html
83
- - lib/monkey_patches.rb
84
147
  - lib/open_tok/archive.rb
85
148
  - lib/open_tok/archive_timeline_event.rb
86
149
  - lib/open_tok/archive_video_resource.rb
87
150
  - lib/open_tok/exception.rb
88
151
  - lib/open_tok/open_tok_sdk.rb
152
+ - lib/open_tok/request.rb
89
153
  - lib/open_tok/session.rb
154
+ - lib/open_tok/utils.rb
90
155
  - lib/open_tok/version.rb
91
156
  - lib/opentok.rb
92
157
  - opentok.gemspec
158
+ - spec/cassettes/archiving_downloads.yml
159
+ - spec/cassettes/generate_sessions.yml
160
+ - spec/cassettes/generate_tokens.yml
161
+ - spec/cassettes/session_creation.yml
162
+ - spec/cassettes/token_creation.yml
93
163
  - spec/opentok_spec.rb
94
164
  - spec/spec_helper.rb
95
165
  homepage: https://github.com/opentok/Opentok-Ruby-SDK
@@ -117,5 +187,10 @@ signing_key:
117
187
  specification_version: 3
118
188
  summary: OpenTok gem
119
189
  test_files:
190
+ - spec/cassettes/archiving_downloads.yml
191
+ - spec/cassettes/generate_sessions.yml
192
+ - spec/cassettes/generate_tokens.yml
193
+ - spec/cassettes/session_creation.yml
194
+ - spec/cassettes/token_creation.yml
120
195
  - spec/opentok_spec.rb
121
196
  - spec/spec_helper.rb
@@ -1,34 +0,0 @@
1
- =begin
2
- OpenTok Ruby Library
3
- http://www.tokbox.com/
4
-
5
- Copyright 2010 - 2011, TokBox, Inc.
6
-
7
- Last modified: 2011-02-17
8
- =end
9
-
10
- class Hash
11
-
12
- # Adding a urlencode method to the hash class for easy querstring generation
13
- def urlencode
14
- to_a.map do |name_value|
15
- if name_value[1].is_a? Array
16
- name_value[0] = CGI.escape name_value[0].to_s
17
- name_value[1].map { |e| CGI.escape e.to_s }
18
- name_value[1] = name_value[1].join "&" + name_value[0] + "="
19
- name_value.join '='
20
- else
21
- name_value.map { |e| CGI.escape e.to_s }.join '='
22
- end
23
- end.join '&'
24
- end
25
- end
26
-
27
- class Net::HTTP
28
- alias_method :old_initialize, :initialize
29
- def initialize(*args)
30
- old_initialize(*args)
31
- @ssl_context = OpenSSL::SSL::SSLContext.new
32
- @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
33
- end
34
- end