opentok 0.0.9 → 0.0.72
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +1 -11
- data/LICENCE +19 -0
- data/README.md +28 -36
- data/Rakefile +0 -5
- data/lib/monkey_patches.rb +34 -0
- data/lib/open_tok/archive.rb +34 -13
- data/lib/open_tok/open_tok_sdk.rb +70 -36
- data/lib/open_tok/version.rb +1 -1
- data/lib/opentok.rb +13 -6
- data/opentok.gemspec +1 -6
- data/spec/opentok_spec.rb +139 -85
- data/spec/spec_helper.rb +1 -14
- metadata +6 -79
- data/LICENSE +0 -7
- data/lib/open_tok/request.rb +0 -57
- data/lib/open_tok/utils.rb +0 -19
- data/spec/cassettes/archives.yml +0 -83
- data/spec/cassettes/invalidSession.yml +0 -41
- data/spec/cassettes/session.yml +0 -46
- data/spec/cassettes/stitchArchive.yml +0 -42
data/CHANGES
CHANGED
@@ -1,15 +1,5 @@
|
|
1
1
|
= Change Log
|
2
2
|
|
3
|
-
== Version 0.0.8
|
4
|
-
|
5
|
-
* Removed references to the staging environment as it no longer exists
|
6
|
-
|
7
|
-
== Version 0.0.73
|
8
|
-
|
9
|
-
* Added stitchArchive functionality
|
10
|
-
* Updated Test Cases ( thanks to https://github.com/rlivsey )
|
11
|
-
* Download Archive duplication and error catching ( thanks to https://github.com/muescha )
|
12
|
-
|
13
3
|
== Version 0.0.5
|
14
4
|
|
15
5
|
* Added connection_data to generate token method (thanks to https://github.com/jonmumm)
|
@@ -30,4 +20,4 @@
|
|
30
20
|
|
31
21
|
== Version 0.0.1
|
32
22
|
|
33
|
-
Initial version
|
23
|
+
Initial version
|
data/LICENCE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2011 TokBox, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -12,22 +12,29 @@ gem 'opentok'
|
|
12
12
|
|
13
13
|
To install as a regular gem just type `gem install opentok`
|
14
14
|
|
15
|
-
|
15
|
+
# Requirements
|
16
16
|
|
17
|
-
You need an api-key and secret. Request them at <http://www.tokbox.com/opentok/tools/js/apikey>.
|
17
|
+
You need an api-key and secret. Request them at <http://www.tokbox.com/opentok/tools/js/apikey>.
|
18
18
|
|
19
19
|
# OpenTokSDK
|
20
20
|
|
21
21
|
In order to use any of the server side functions, you must first create an `OpenTokSDK` object with your developer credentials.
|
22
|
+
|
22
23
|
`OpenTokSDK` takes 2-3 parameters:
|
23
24
|
> key (string) - Given to you when you register
|
24
25
|
> secret (string) - Given to you when you register
|
26
|
+
> Production (Boolean) - OPTIONAL. Puts your app in staging or production environment. Default value is `false`
|
27
|
+
For more information about production apps, check out <http://www.tokbox.com/opentok/api/tools/js/launch>
|
28
|
+
|
25
29
|
|
26
30
|
<pre>
|
27
|
-
# Creating an OpenTok Object
|
31
|
+
# Creating an OpenTok Object in Staging Environment
|
28
32
|
API_KEY = '' # should be a string
|
29
33
|
API_SECRET = '' # should be a string
|
30
34
|
OTSDK = OpenTok::OpenTokSDK.new API_KEY, API_SECRET
|
35
|
+
|
36
|
+
# Creating an OpenTok Object in Production Environment
|
37
|
+
OTSDK = OpenTok::OpenTokSDK.new API_KEY, API_SECRET, true
|
31
38
|
</pre>
|
32
39
|
|
33
40
|
|
@@ -59,56 +66,41 @@ With the generated sessionId, you can start generating tokens for each user.
|
|
59
66
|
token = OTSDK.generateToken :session_id => session, :role => OpenTok::RoleConstants::PUBLISHER, :connection_data => "username=Bob,level=4"
|
60
67
|
</pre>
|
61
68
|
|
62
|
-
|
63
|
-
To Download archived video, you must have an Archive ID which you get from the javascript library
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
>
|
71
|
-
{:code=>201, :message=>"Successfully Created", :location=>response["location"]}
|
72
|
-
{:code=>202, :message=>"Processing"}
|
73
|
-
{:code=>403, :message=>"Invalid Credentials"}
|
74
|
-
{:code=>404, :message=>"Archive Does Not Exist"}
|
75
|
-
{:code=>500, :message=>"Server Error"}
|
76
|
-
|
77
|
-
Example:
|
78
|
-
<pre>
|
79
|
-
result = OTSDK.stitchArchive archive_id
|
80
|
-
if result[:code] == 201
|
81
|
-
return result[:location]
|
82
|
-
end
|
83
|
-
</pre>
|
69
|
+
### Downloading Archive Videos
|
70
|
+
To Download archived video, you must have an Archive ID which you get from the javascript library
|
71
|
+
|
72
|
+
#### Quick Overview of the javascript library: <http://www.tokbox.com/opentok/api/tools/js/documentation/api/Session.html#createArchive>
|
73
|
+
1. Create an event listener on `archiveCreated` event: `session.addEventListener('archiveCreated', archiveCreatedHandler);`
|
74
|
+
2. Create an archive: `archive = session.createArchive(...);`
|
75
|
+
3. When archive is successfully created `archiveCreatedHandler` would be triggered. An Archive object containing `archiveId` property is passed into your function. Save this in your database, this archiveId is what you use to reference the archive for playbacks and download videos
|
76
|
+
4. After your archive has been created, you can start recording videos into it by calling `session.startRecording(archive)`
|
77
|
+
Optionally, you can also use the standalone archiving, which means that each archive would have only 1 video: <http://www.tokbox.com/opentok/api/tools/js/documentation/api/RecorderManager.html>
|
84
78
|
|
85
|
-
|
79
|
+
### Get Archive Manifest
|
86
80
|
With your **moderator token** and OpentokSDK Object, you can generate OpenTokArchive Object, which contains information for all videos in the Archive
|
87
|
-
`
|
81
|
+
`get_archive_manifest()` takes in 2 parameters: **archiveId** and **moderator token**
|
88
82
|
> archive_id (string) - REQUIRED.
|
89
|
-
>
|
90
|
-
> **returns** an `OpenTokArchive` object.
|
91
|
-
The *resources* property of this object is array of `OpenTokArchiveVideoResource` objects, and each `OpenTokArchiveVideoResource` object represents a video in the archive.
|
83
|
+
> **returns** an `OpenTokArchive` object. The *resources* property of this object is array of `OpenTokArchiveVideoResource` objects, and each `OpenTokArchiveVideoResource` object represents a video in the archive.
|
92
84
|
|
93
85
|
Example:(Make sure you have the OpentokSDK Object)
|
94
86
|
<pre>
|
95
|
-
@token = '
|
87
|
+
@token = 'moderator_token'
|
96
88
|
@archiveId = '5f74aee5-ab3f-421b-b124-ed2a698ee939' #Obtained from Javascript Library
|
97
|
-
otArchive = OTSDK.
|
89
|
+
otArchive = OTSDK.get_archive_manifest(@archiveId, @token)
|
98
90
|
</pre>
|
99
91
|
|
100
|
-
|
101
|
-
`OpenTokArchive.resources` is an array of `OpenTokArchiveVideoResource` objects. OpenTokArchiveVideoResource has `getId()` method that returns the
|
92
|
+
### Get video ID
|
93
|
+
`OpenTokArchive.resources` is an array of `OpenTokArchiveVideoResource` objects. OpenTokArchiveVideoResource has `getId()` method that returns the videoId
|
102
94
|
`getId()` will return the video ID (a String)
|
103
95
|
|
104
96
|
Example:
|
105
97
|
<pre>
|
106
|
-
otArchive = OTSDK.
|
98
|
+
otArchive = OTSDK.get_archive_manifest(@archiveId, @token)
|
107
99
|
otVideoResource = otArchive.resources[0]
|
108
100
|
videoId = otVideoResource.getId()
|
109
101
|
</pre>
|
110
102
|
|
111
|
-
|
103
|
+
### Get Download Url
|
112
104
|
`OpenTokArchive` has `downloadArchiveURL` that will return an url string for downloading the video in the archive. You must call this function every time you want the file, because this url expires after 24 hours
|
113
105
|
> video_id (string) - REQUIRED
|
114
106
|
> token (string) - REQUIRED
|
data/Rakefile
CHANGED
@@ -0,0 +1,34 @@
|
|
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
|
data/lib/open_tok/archive.rb
CHANGED
@@ -9,32 +9,53 @@ 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,
|
12
|
+
def initialize(archive_id, archive_title, resources, timeline, apiUrl, token)
|
13
13
|
@archive_id = archive_id
|
14
14
|
@archive_title = archive_title
|
15
15
|
@resources = resources
|
16
16
|
@timeline = timeline
|
17
|
-
@
|
17
|
+
@apiUrl = apiUrl
|
18
18
|
@token = token
|
19
19
|
end
|
20
20
|
|
21
|
-
def do_request(
|
22
|
-
|
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
|
23
50
|
end
|
24
51
|
|
25
|
-
def
|
52
|
+
def downloadArchiveURL(video_id, token="")
|
26
53
|
if token==""
|
27
|
-
#
|
28
|
-
return "#{@api_url}/archive/url/#{@archive_id}/#{video_id}"
|
54
|
+
return "#{@apiUrl}/archive/url/#{@archive_id}/#{video_id}"
|
29
55
|
else
|
30
|
-
|
31
|
-
if doc.split("http").length < 2
|
32
|
-
raise OpenTokException.new doc.get_elements('Errors')[0].get_elements('error')[0].children.to_s
|
33
|
-
end
|
34
|
-
return doc
|
56
|
+
return do_request "#{@apiUrl}/archive/url/#{@archive_id}/#{video_id}", token
|
35
57
|
end
|
36
58
|
end
|
37
|
-
alias_method :downloadArchiveURL, :download_archive_url
|
38
59
|
|
39
60
|
def self.parse_manifest(manifest, apiUrl, token)
|
40
61
|
archive_id = manifest.attributes['archiveid']
|
@@ -6,8 +6,11 @@
|
|
6
6
|
|
7
7
|
=end
|
8
8
|
|
9
|
+
require 'cgi'
|
9
10
|
require 'openssl'
|
10
11
|
require 'base64'
|
12
|
+
require 'uri'
|
13
|
+
require 'net/https'
|
11
14
|
require 'rexml/document'
|
12
15
|
|
13
16
|
DIGEST = OpenSSL::Digest::Digest.new('sha1')
|
@@ -21,7 +24,7 @@ module OpenTok
|
|
21
24
|
# * +MULTIPLEXER_SWITCHTYPE+ integer
|
22
25
|
# * +MULTIPLEXER_SWITCHTIMEOUT+ integer
|
23
26
|
# * +P2P_PREFERENCE+ string
|
24
|
-
|
27
|
+
class SessionPropertyConstants
|
25
28
|
ECHOSUPPRESSION_ENABLED = "echoSuppression.enabled" #Boolean
|
26
29
|
MULTIPLEXER_NUMOUTPUTSTREAMS = "multiplexer.numOutputStreams" #Integer
|
27
30
|
MULTIPLEXER_SWITCHTYPE = "multiplexer.switchType" #Integer
|
@@ -34,7 +37,7 @@ module OpenTok
|
|
34
37
|
# * +SUBSCRIBER+ Can only subscribe
|
35
38
|
# * +PUBLISHER+ Can publish, subscribe, and signal
|
36
39
|
# * +MODERATOR+ Can do the above along with forceDisconnect and forceUnpublish
|
37
|
-
|
40
|
+
class RoleConstants
|
38
41
|
SUBSCRIBER = "subscriber" #Can only subscribe
|
39
42
|
PUBLISHER = "publisher" #Can publish, subscribe, and signal
|
40
43
|
MODERATOR = "moderator" #Can do the above along with forceDisconnect and forceUnpublish
|
@@ -49,20 +52,37 @@ module OpenTok
|
|
49
52
|
#
|
50
53
|
# The first two attributes are required; +parnter_id+ and +partner_secret+ are the api-key and secret
|
51
54
|
# that are provided to you.
|
52
|
-
|
55
|
+
#
|
56
|
+
# You can also pass in optional options;
|
57
|
+
# * +:api_url+ sets the location of the api (staging or production)
|
58
|
+
def initialize(partner_id, partner_secret, options = nil)
|
53
59
|
@partner_id = partner_id
|
54
60
|
@partner_secret = partner_secret.strip
|
55
|
-
|
61
|
+
|
62
|
+
if options.is_a?(::Hash)
|
63
|
+
# user input hash parameter
|
64
|
+
@api_url = options[:api_url] || API_URL
|
65
|
+
else
|
66
|
+
# use input true/false for parameter
|
67
|
+
@api_url = (options ? API_URL_PROD : API_URL)
|
68
|
+
end
|
69
|
+
|
70
|
+
unless @api_url
|
71
|
+
@api_url = API_URL
|
72
|
+
end
|
56
73
|
end
|
57
74
|
|
58
75
|
# Generate token for the given session_id. The options you can provide are;
|
59
76
|
# * +:session_id+ (required) generate a token for the provided session
|
60
|
-
# * +:create_time+
|
77
|
+
# * +:create_time+
|
61
78
|
# * +: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.
|
62
79
|
# * +:role+ (optional) Added in OpenTok v0.91.5. This defines the role the user will have. There are three roles: subscriber, publisher, and moderator.
|
63
80
|
# * +:connection_data+ (optional) Added in OpenTok v0.91.20. A string containing metadata describing the connection.
|
64
81
|
#
|
65
82
|
# 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
|
66
86
|
def generate_token(opts = {})
|
67
87
|
{ :session_id => nil, :create_time => nil, :expire_time => nil, :role => nil, :connection_data => nil }.merge!(opts)
|
68
88
|
|
@@ -84,7 +104,7 @@ module OpenTok
|
|
84
104
|
if not opts[:expire_time].nil?
|
85
105
|
raise OpenTokException.new 'Expire time must be a number' if not opts[:expire_time].is_a?(Numeric)
|
86
106
|
raise OpenTokException.new 'Expire time must be in the future' if opts[:expire_time] < Time.now.to_i
|
87
|
-
raise OpenTokException.new 'Expire time must be in the next
|
107
|
+
raise OpenTokException.new 'Expire time must be in the next 7 days' if opts[:expire_time] > (Time.now.to_i + 604800)
|
88
108
|
data_params[:expire_time] = opts[:expire_time].to_i
|
89
109
|
end
|
90
110
|
|
@@ -93,18 +113,23 @@ module OpenTok
|
|
93
113
|
data_params[:connection_data] = opts[:connection_data]
|
94
114
|
end
|
95
115
|
|
96
|
-
data_string =
|
116
|
+
data_string = data_params.urlencode
|
97
117
|
|
98
118
|
sig = sign_string(data_string, @partner_secret)
|
99
|
-
meta_string =
|
119
|
+
meta_string = {
|
120
|
+
:partner_id => @partner_id,
|
121
|
+
:sig => sig
|
122
|
+
}.urlencode
|
100
123
|
|
101
124
|
@@TOKEN_SENTINEL + Base64.encode64(meta_string + ":" + data_string).gsub("\n", '')
|
102
125
|
end
|
103
|
-
alias_method :generateToken, :generate_token
|
104
126
|
|
105
127
|
# 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@.
|
106
128
|
#
|
107
129
|
# 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
|
108
133
|
def create_session(location='', opts={})
|
109
134
|
opts.merge!({:partner_id => @partner_id, :location=>location})
|
110
135
|
doc = do_request("/session/create", opts)
|
@@ -113,12 +138,14 @@ module OpenTok
|
|
113
138
|
end
|
114
139
|
OpenTok::Session.new(doc.root.get_elements('Session')[0].get_elements('session_id')[0].children[0].to_s)
|
115
140
|
end
|
116
|
-
alias_method :createSession, :create_session
|
117
141
|
|
118
142
|
# 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)
|
119
143
|
# 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
|
120
147
|
def get_archive_manifest(archive_id, token)
|
121
|
-
# TODO: verify that token is MODERATOR token
|
148
|
+
# TODO: verify that token is MODERATOR token, Staging and production
|
122
149
|
|
123
150
|
doc = do_request("/archive/getmanifest/#{archive_id}", {}, token)
|
124
151
|
if not doc.get_elements('Errors').empty?
|
@@ -126,37 +153,44 @@ module OpenTok
|
|
126
153
|
end
|
127
154
|
OpenTok::Archive.parse_manifest(doc.get_elements('manifest')[0], @api_url, token)
|
128
155
|
end
|
129
|
-
alias_method :getArchiveManifest, :get_archive_manifest
|
130
|
-
|
131
|
-
def stitchArchive(aid)
|
132
|
-
stitchURL = "/hl/archive/#{aid}/stitch"
|
133
|
-
request = OpenTok::Request.new(@api_url, nil, @partner_id, @partner_secret)
|
134
|
-
response = request.sendRequest(stitchURL, {test:'none'})
|
135
|
-
case response.code
|
136
|
-
when '201'
|
137
|
-
return {:code=>201, :message=>"Successfully Created", :location=>response["location"]}
|
138
|
-
when '202'
|
139
|
-
return {:code=>202, :message=>"Processing"}
|
140
|
-
when '403'
|
141
|
-
return {:code=>403, :message=>"Invalid Credentials"}
|
142
|
-
when '404'
|
143
|
-
return {:code=>404, :message=>"Archive Does Not Exist"}
|
144
|
-
else
|
145
|
-
return {:code=>500, :message=>"Server Error"}
|
146
|
-
end
|
147
|
-
return {}
|
148
|
-
end
|
149
|
-
alias_method :stitch, :stitchArchive
|
150
156
|
|
151
157
|
protected
|
152
158
|
def sign_string(data, secret)
|
153
159
|
OpenSSL::HMAC.hexdigest(DIGEST, secret, data)
|
154
160
|
end
|
155
161
|
|
156
|
-
def do_request(
|
157
|
-
|
158
|
-
|
159
|
-
|
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
|
160
193
|
end
|
161
194
|
end
|
162
195
|
end
|
196
|
+
|
data/lib/open_tok/version.rb
CHANGED
data/lib/opentok.rb
CHANGED
@@ -2,20 +2,27 @@
|
|
2
2
|
OpenTok Ruby Library
|
3
3
|
http://www.tokbox.com/
|
4
4
|
|
5
|
-
Copyright 2010 -
|
5
|
+
Copyright 2010 - 2011, TokBox, Inc.
|
6
6
|
|
7
|
-
Last modified:
|
7
|
+
Last modified: 2011-02-17
|
8
8
|
=end
|
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
|
12
17
|
|
13
|
-
|
14
|
-
API_URL = "https://api.opentok.com"
|
18
|
+
Net::HTTP.version_1_2 # to make sure version 1.2 is used
|
15
19
|
|
20
|
+
VERSION = "tbrb-v0.91.2011-02-17"
|
21
|
+
API_URL = "https://staging.tokbox.com/hl"
|
22
|
+
API_URL_PROD = 'https://api.opentok.com/hl'
|
23
|
+
|
24
|
+
require 'monkey_patches'
|
16
25
|
require 'open_tok/exception'
|
17
|
-
require 'open_tok/utils'
|
18
|
-
require 'open_tok/request'
|
19
26
|
require 'open_tok/open_tok_sdk'
|
20
27
|
require 'open_tok/session'
|
21
28
|
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", "
|
10
|
+
s.email = ["stijn@skylight.be", "karmenblake@gmail.com", "Song Zheng"]
|
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,9 +18,4 @@ 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"
|
26
21
|
end
|
data/spec/opentok_spec.rb
CHANGED
@@ -1,126 +1,180 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
let(:host) { 'localhost' }
|
3
|
+
class TestOpentokSDK < OpenTok::OpenTokSDK
|
4
|
+
def do_request(api_url, params, token=nil)
|
5
|
+
super
|
6
|
+
end
|
7
|
+
end
|
9
8
|
|
10
|
-
|
9
|
+
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
|
11
17
|
|
12
18
|
describe "test Initializers" do
|
13
|
-
it "should
|
14
|
-
opentok = OpenTok::OpenTokSDK.new api_key, api_secret
|
15
|
-
opentok.api_url.should eq
|
19
|
+
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
|
16
22
|
end
|
17
|
-
|
18
|
-
|
19
|
-
opentok
|
20
|
-
opentok.api_url
|
23
|
+
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
|
21
28
|
end
|
22
|
-
|
23
|
-
|
24
|
-
opentok
|
25
|
-
|
29
|
+
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
|
32
|
+
end
|
33
|
+
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
|
26
36
|
end
|
27
37
|
end
|
28
38
|
|
29
39
|
describe "Generate Sessions" do
|
30
|
-
|
31
|
-
|
32
|
-
|
40
|
+
before :all do
|
41
|
+
@opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
|
42
|
+
end
|
33
43
|
|
34
44
|
it "should generate valid session" do
|
35
|
-
session = opentok.create_session host
|
45
|
+
session = @opentok.create_session @host
|
36
46
|
session.to_s.should match(/\A[0-9A-z_-]{40,}\Z/)
|
37
47
|
end
|
38
|
-
|
39
48
|
it "should generate valid session camelCase" do
|
40
|
-
session = opentok.createSession host
|
41
|
-
session.to_s.should match(/\A[0-9A-z_-]{40,}\Z/)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should generate valid p2p session" do
|
45
|
-
# Creating Session object with p2p enabled
|
46
|
-
sessionProperties = {OpenTok::SessionPropertyConstants::P2P_PREFERENCE => "enabled"} # or disabled
|
47
|
-
session = opentok.createSession( @location, sessionProperties )
|
49
|
+
session = @opentok.createSession @host
|
48
50
|
session.to_s.should match(/\A[0-9A-z_-]{40,}\Z/)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
52
|
-
describe "
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
expect{
|
58
|
-
session = invalidOT.create_session host
|
59
|
-
}.to raise_error OpenTok::OpenTokException
|
54
|
+
describe "Generate Tokens" do
|
55
|
+
before :all do
|
56
|
+
@opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
|
57
|
+
@session = @opentok.createSession @host
|
60
58
|
end
|
61
|
-
end
|
62
59
|
|
63
|
-
describe "Generate Tokens" do
|
64
|
-
let(:opentok) { OpenTok::OpenTokSDK.new api_key, api_secret }
|
65
|
-
let(:session) { opentok.createSession host }
|
66
60
|
it "should generate valid token" do
|
67
|
-
token = opentok.generate_token({:session_id => session, :role=>OpenTok::RoleConstants::MODERATOR})
|
68
|
-
token.should match(/(T1==)+[0-9A-z_]+/)
|
61
|
+
@token = @opentok.generate_token({:session_id => @session, :role=>OpenTok::RoleConstants::MODERATOR})
|
62
|
+
@token.should match(/(T1==)+[0-9A-z_]+/)
|
69
63
|
end
|
70
64
|
it "should generate valid token camelCase" do
|
71
|
-
token = opentok.generateToken({:session_id => session, :role=>OpenTok::RoleConstants::MODERATOR})
|
72
|
-
token.should match(/(T1==)+[0-9A-z_]+/)
|
73
|
-
end
|
74
|
-
it "should be able to set parameters in token" do
|
75
|
-
token = opentok.generate_token :session_id => session, :role=> OpenTok::RoleConstants::PUBLISHER, :connection_data => "username=Bob,level=4"
|
76
|
-
str = token[4..token.length]
|
77
|
-
decoded = Base64.decode64(str)
|
78
|
-
decoded.should match(/publisher.*username.*Bob.*level.*4/)
|
65
|
+
@token = @opentok.generateToken({:session_id => @session, :role=>OpenTok::RoleConstants::MODERATOR})
|
66
|
+
@token.should match(/(T1==)+[0-9A-z_]+/)
|
79
67
|
end
|
80
68
|
end
|
81
69
|
|
70
|
+
end
|
82
71
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
72
|
+
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
|
89
83
|
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
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
|
93
91
|
|
94
|
-
it "should
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
92
|
+
it "should be possible to valid a OpenTokSDK object with a valid key and secret" do
|
93
|
+
@opentok.should be_instance_of TestOpentokSDK
|
94
|
+
end
|
95
|
+
|
96
|
+
it "a new OpenTokSDK object should point to the staging environment by default" do
|
97
|
+
@opentok.api_url.should eq @api_production_url
|
99
98
|
end
|
100
99
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
100
|
+
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
|
107
|
+
|
108
|
+
it "should have archive resources" do
|
109
|
+
otArchive = @opentok.getArchiveManifest(@archiveId, @token)
|
110
|
+
otArchiveResource = otArchive.resources[0]
|
111
|
+
vid = otArchiveResource.getId()
|
112
|
+
vid.should match(/[0-9A-z=]+/)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should return download url" do
|
116
|
+
otArchive = @opentok.get_archive_manifest(@archiveId, @token)
|
117
|
+
otArchiveResource = otArchive.resources[0]
|
118
|
+
vid = otArchiveResource.getId()
|
119
|
+
url = otArchive.downloadArchiveURL(vid)
|
120
|
+
url.start_with?('http').should eq true
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should return file url" do
|
124
|
+
otArchive = @opentok.get_archive_manifest(@archiveId, @token)
|
125
|
+
otArchiveResource = otArchive.resources[0]
|
126
|
+
vid = otArchiveResource.getId()
|
127
|
+
url = otArchive.downloadArchiveURL(vid, @token)
|
128
|
+
url.start_with?('http').should eq true
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
describe "Session creation" do
|
135
|
+
it "should raise an exception with an invalid key and secret" do
|
136
|
+
opentok = OpenTok::OpenTokSDK.new 0, ''
|
137
|
+
|
138
|
+
expect{
|
139
|
+
session = opentok.create_session @host
|
140
|
+
}.to raise_error OpenTok::OpenTokException
|
107
141
|
end
|
142
|
+
|
108
143
|
end
|
109
144
|
|
110
|
-
describe "
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
145
|
+
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
|
+
|
151
|
+
it "should be possible to create a token" do
|
152
|
+
token = @opentok.generate_token :session_id => @valid_session.to_s
|
153
|
+
|
154
|
+
token.should match(/\A[0-9A-z=]+\Z/)
|
155
|
+
end
|
156
|
+
|
157
|
+
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"
|
118
159
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
160
|
+
str = token[4..token.length]
|
161
|
+
decoded = Base64.decode64(str)
|
162
|
+
|
163
|
+
decoded.should match(/publisher.*username.*Bob.*level.*4/)
|
123
164
|
end
|
124
165
|
end
|
125
166
|
|
167
|
+
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
|
172
|
+
|
173
|
+
# it "If token does not have moderator role, raise error" do
|
174
|
+
# token = @opentok.generate_token(:session_id=>@valid_session)
|
175
|
+
# expect{
|
176
|
+
# @opentok.get_archive_manifest("", token)
|
177
|
+
# }.to raise_error OpenTok::OpenTokException
|
178
|
+
# end
|
179
|
+
end
|
126
180
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,2 @@
|
|
1
|
+
require 'I18n'
|
1
2
|
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.
|
4
|
+
version: 0.0.72
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,72 +11,8 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
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'
|
14
|
+
date: 2012-08-14 00:00:00.000000000 Z
|
15
|
+
dependencies: []
|
80
16
|
description: OpenTok is an API from TokBox that enables websites to weave live group
|
81
17
|
video communication into their online experience. With OpenTok you have the freedom
|
82
18
|
and flexibility to create the most engaging web experience for your users. OpenTok
|
@@ -85,7 +21,7 @@ description: OpenTok is an API from TokBox that enables websites to weave live g
|
|
85
21
|
email:
|
86
22
|
- stijn@skylight.be
|
87
23
|
- karmenblake@gmail.com
|
88
|
-
-
|
24
|
+
- Song Zheng
|
89
25
|
executables: []
|
90
26
|
extensions: []
|
91
27
|
extra_rdoc_files: []
|
@@ -93,7 +29,7 @@ files:
|
|
93
29
|
- .gitignore
|
94
30
|
- CHANGES
|
95
31
|
- Gemfile
|
96
|
-
-
|
32
|
+
- LICENCE
|
97
33
|
- README.md
|
98
34
|
- Rakefile
|
99
35
|
- doc/CHANGES.html
|
@@ -144,21 +80,16 @@ files:
|
|
144
80
|
- doc/rdoc.css
|
145
81
|
- doc/spec/opentok_spec_rb.html
|
146
82
|
- doc/spec/spec_helper_rb.html
|
83
|
+
- lib/monkey_patches.rb
|
147
84
|
- lib/open_tok/archive.rb
|
148
85
|
- lib/open_tok/archive_timeline_event.rb
|
149
86
|
- lib/open_tok/archive_video_resource.rb
|
150
87
|
- lib/open_tok/exception.rb
|
151
88
|
- lib/open_tok/open_tok_sdk.rb
|
152
|
-
- lib/open_tok/request.rb
|
153
89
|
- lib/open_tok/session.rb
|
154
|
-
- lib/open_tok/utils.rb
|
155
90
|
- lib/open_tok/version.rb
|
156
91
|
- lib/opentok.rb
|
157
92
|
- opentok.gemspec
|
158
|
-
- spec/cassettes/archives.yml
|
159
|
-
- spec/cassettes/invalidSession.yml
|
160
|
-
- spec/cassettes/session.yml
|
161
|
-
- spec/cassettes/stitchArchive.yml
|
162
93
|
- spec/opentok_spec.rb
|
163
94
|
- spec/spec_helper.rb
|
164
95
|
homepage: https://github.com/opentok/Opentok-Ruby-SDK
|
@@ -186,9 +117,5 @@ signing_key:
|
|
186
117
|
specification_version: 3
|
187
118
|
summary: OpenTok gem
|
188
119
|
test_files:
|
189
|
-
- spec/cassettes/archives.yml
|
190
|
-
- spec/cassettes/invalidSession.yml
|
191
|
-
- spec/cassettes/session.yml
|
192
|
-
- spec/cassettes/stitchArchive.yml
|
193
120
|
- spec/opentok_spec.rb
|
194
121
|
- spec/spec_helper.rb
|
data/LICENSE
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 TokBox, Inc.
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
-
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
-
The software complies with Terms of Service for the OpenTok platform described in http://www.tokbox.com/termsofservice
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/open_tok/request.rb
DELETED
@@ -1,57 +0,0 @@
|
|
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
|
data/lib/open_tok/utils.rb
DELETED
@@ -1,19 +0,0 @@
|
|
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
|
data/spec/cassettes/archives.yml
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: get
|
5
|
-
uri: https://api.opentok.com/archive/getmanifest/200567af-0726-4e93-883b-fe0426d6310a
|
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==cGFydG5lcl9pZD00NTk3ODImc2lnPWVjNjA1YTZhNzI5MDk5MzU5NTI1YWM2ZTczNDY1ZTQ3MzEwMWFkY2Q6cm9sZT1tb2RlcmF0b3Imc2Vzc2lvbl9pZD0xX01YNDBOVGszT0RKLU1USTNMakF1TUM0eGZsUjFaU0JUWlhBZ01EUWdNVFE2TlRNNk1ESWdVRVJVSURJd01USi1NQzQxTWpFeE9ERXpmZyZjcmVhdGVfdGltZT0xMzQ2ODAxMjQ1Jm5vbmNlPTAuMjUwMTIwMTEyNzkzODkwMjQ=
|
16
|
-
response:
|
17
|
-
status:
|
18
|
-
code: 200
|
19
|
-
message: OK
|
20
|
-
headers:
|
21
|
-
Server:
|
22
|
-
- nginx
|
23
|
-
Date:
|
24
|
-
- Tue, 04 Sep 2012 23:27:13 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
|
-
- '510'
|
35
|
-
body:
|
36
|
-
encoding: US-ASCII
|
37
|
-
string: ! "<manifest version=\"0.1\" archiveid=\"200567af-0726-4e93-883b-fe0426d6310a\"
|
38
|
-
title=\"1346797109799\">\n <resources>\n <video id=\"bbf108c9-7237-49ae-9057-2ccdb71cf675\"
|
39
|
-
length=\"18734\" name=\"\"/>\n <video id=\"3f0d3ec6-4a41-4cc5-9e38-f9e6375ba5fd\"
|
40
|
-
length=\"18743\" name=\"\"/>\n </resources>\n <timeline>\n <event
|
41
|
-
type=\"PLAY\" id=\"3f0d3ec6-4a41-4cc5-9e38-f9e6375ba5fd\" offset=\"1255\"
|
42
|
-
data=\"\" />\n <event type=\"PLAY\" id=\"bbf108c9-7237-49ae-9057-2ccdb71cf675\"
|
43
|
-
offset=\"1263\" data=\"\" />\n </timeline>\n</manifest>\n\n\n"
|
44
|
-
http_version:
|
45
|
-
recorded_at: Tue, 04 Sep 2012 23:27:25 GMT
|
46
|
-
- request:
|
47
|
-
method: get
|
48
|
-
uri: https://api.opentok.com/archive/url/200567af-0726-4e93-883b-fe0426d6310a/bbf108c9-7237-49ae-9057-2ccdb71cf675
|
49
|
-
body:
|
50
|
-
encoding: US-ASCII
|
51
|
-
string: ''
|
52
|
-
headers:
|
53
|
-
Accept:
|
54
|
-
- ! '*/*'
|
55
|
-
User-Agent:
|
56
|
-
- Ruby
|
57
|
-
X-Tb-Token-Auth:
|
58
|
-
- T1==cGFydG5lcl9pZD00NTk3ODImc2lnPTU2MDY5Y2VmMTAzY2M4YTUzY2RlNTZlZTAzNzdjODIyNTk0MTU5MzM6cm9sZT1tb2RlcmF0b3Imc2Vzc2lvbl9pZD0xX01YNDBOVGszT0RKLU1USTNMakF1TUM0eGZsUjFaU0JUWlhBZ01EUWdNVFE2TlRNNk1ESWdVRVJVSURJd01USi1NQzQxTWpFeE9ERXpmZyZjcmVhdGVfdGltZT0xMzQ2ODAxMjQ1Jm5vbmNlPTAuNDY2MDM2NDg4Nzc5NDgy
|
59
|
-
response:
|
60
|
-
status:
|
61
|
-
code: 200
|
62
|
-
message: OK
|
63
|
-
headers:
|
64
|
-
Server:
|
65
|
-
- nginx
|
66
|
-
Date:
|
67
|
-
- Tue, 04 Sep 2012 23:27:13 GMT
|
68
|
-
Content-Type:
|
69
|
-
- text/html; charset=utf-8
|
70
|
-
Connection:
|
71
|
-
- keep-alive
|
72
|
-
Pragma:
|
73
|
-
- no-cache
|
74
|
-
Cache-Control:
|
75
|
-
- no-cache
|
76
|
-
Content-Length:
|
77
|
-
- '229'
|
78
|
-
body:
|
79
|
-
encoding: US-ASCII
|
80
|
-
string: https://s3.amazonaws.com/tokbox.com.production/459782/200567af-0726-4e93-883b-fe0426d6310a/bbf108c9-7237-49ae-9057-2ccdb71cf675.flv?Signature=Hn7ti7U2yG8tehW1ypD1R%2FGUvrg%3D&Expires=1346804833&AWSAccessKeyId=AKIAI6LQCPIXYVWCQV6Q
|
81
|
-
http_version:
|
82
|
-
recorded_at: Tue, 04 Sep 2012 23:27:25 GMT
|
83
|
-
recorded_with: VCR 2.2.4
|
@@ -1,41 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: post
|
5
|
-
uri: https://api.opentok.com/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: 200
|
21
|
-
message: OK
|
22
|
-
headers:
|
23
|
-
Server:
|
24
|
-
- nginx
|
25
|
-
Date:
|
26
|
-
- Tue, 04 Sep 2012 23:27:12 GMT
|
27
|
-
Content-Type:
|
28
|
-
- text/plain; charset=UTF-8
|
29
|
-
Transfer-Encoding:
|
30
|
-
- chunked
|
31
|
-
Connection:
|
32
|
-
- keep-alive
|
33
|
-
body:
|
34
|
-
encoding: US-ASCII
|
35
|
-
string: ! '<Errors><error code="403"><notAuthorized message="The API secret
|
36
|
-
did not match, Invalid credentials passed"/></error></Errors>
|
37
|
-
|
38
|
-
'
|
39
|
-
http_version:
|
40
|
-
recorded_at: Tue, 04 Sep 2012 23:27:24 GMT
|
41
|
-
recorded_with: VCR 2.2.4
|
data/spec/cassettes/session.yml
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: post
|
5
|
-
uri: https://api.opentok.com/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
|
-
- Tue, 04 Sep 2012 23:27:12 GMT
|
27
|
-
Content-Type:
|
28
|
-
- text/xml; charset=utf-8
|
29
|
-
Connection:
|
30
|
-
- keep-alive
|
31
|
-
Pragma:
|
32
|
-
- no-cache
|
33
|
-
Cache-Control:
|
34
|
-
- no-cache
|
35
|
-
Access-Control-Allow-Origin:
|
36
|
-
- ! '*'
|
37
|
-
Content-Length:
|
38
|
-
- '294'
|
39
|
-
body:
|
40
|
-
encoding: US-ASCII
|
41
|
-
string: ! "<Sessions>\n <Session>\n <session_id>2_MX40NTk3ODJ-fjIwMTItMDktMDQgMjM6Mjc6MTIuNzY3ODY5KzAwOjAwfjAuNTQzNTEwNTE4NjQxfg</session_id>\n
|
42
|
-
\ <partner_id>459782</partner_id>\n <create_dt>2012-09-04 23:27:12.767869+00:00</create_dt>\n
|
43
|
-
\ <session_status></session_status>\n </Session>\n</Sessions>\n"
|
44
|
-
http_version:
|
45
|
-
recorded_at: Tue, 04 Sep 2012 23:27:24 GMT
|
46
|
-
recorded_with: VCR 2.2.4
|
@@ -1,42 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: post
|
5
|
-
uri: https://api.opentok.com/hl/archive/200567af-0726-4e93-883b-fe0426d6310a/stitch
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: test=none
|
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: 201
|
21
|
-
message: Created
|
22
|
-
headers:
|
23
|
-
Server:
|
24
|
-
- nginx
|
25
|
-
Date:
|
26
|
-
- Tue, 04 Sep 2012 23:27:14 GMT
|
27
|
-
Content-Type:
|
28
|
-
- text/plain
|
29
|
-
Connection:
|
30
|
-
- keep-alive
|
31
|
-
Location:
|
32
|
-
- https://tokbox.com.production.s3.amazonaws.com/459782%2F200567af-0726-4e93-883b-fe0426d6310a%2Fstitch.mp4?Expires=1346887634&AWSAccessKeyId=AKIAI6LQCPIXYVWCQV6Q&Signature=6%2BihfyAJiQGjmf%2FHV1BGCe14rr8%3D
|
33
|
-
X-Tb-Host:
|
34
|
-
- oms407-oak.tokbox.com
|
35
|
-
Content-Length:
|
36
|
-
- '0'
|
37
|
-
body:
|
38
|
-
encoding: US-ASCII
|
39
|
-
string: ''
|
40
|
-
http_version:
|
41
|
-
recorded_at: Tue, 04 Sep 2012 23:27:26 GMT
|
42
|
-
recorded_with: VCR 2.2.4
|