opentok 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +0 -4
- data/README.md +35 -6
- data/lib/open_tok/archive.rb +42 -5
- data/lib/open_tok/archive_video_resource.rb +5 -1
- data/lib/open_tok/open_tok_sdk.rb +8 -1
- data/lib/open_tok/version.rb +2 -2
- data/opentok.gemspec +1 -1
- data/spec/opentok_spec.rb +99 -12
- data/spec/spec_helper.rb +1 -1
- metadata +26 -41
data/CHANGES
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
= Change Log
|
2
2
|
|
3
|
-
== Version 0.0.6
|
4
|
-
|
5
|
-
* Thanks to Song Zheng for doing the following updates; Updated README for clarification. Also added test case to validate token parameters
|
6
|
-
|
7
3
|
== Version 0.0.5
|
8
4
|
|
9
5
|
* Added connection_data to generate token method (thanks to https://github.com/jonmumm)
|
data/README.md
CHANGED
@@ -58,7 +58,7 @@ session_id = @opentok.create_session( @location, session_properties )
|
|
58
58
|
### Generating Token
|
59
59
|
With the generated session_id, you can start generating tokens for each user.
|
60
60
|
`generate_token` takes in hash with 1-4 properties:
|
61
|
-
> session_id (string) -
|
61
|
+
> session_id (string) - REQUIRED
|
62
62
|
> role (string) - OPTIONAL. subscriber, publisher, or moderator
|
63
63
|
> expire_time (int) - OPTIONAL. Time when token will expire in unix timestamp
|
64
64
|
> connection_data (string) - OPTIONAL. Metadata to store data (names, user id, etc)
|
@@ -69,17 +69,46 @@ token = @opentok.generate_token :session_id => session, :role => OpenTok::RoleCo
|
|
69
69
|
</pre>
|
70
70
|
|
71
71
|
### Downloading Archive Videos
|
72
|
-
To Download
|
72
|
+
To Download archived video, you must have an Archive ID which you get from the javascript library
|
73
|
+
|
74
|
+
#### Quick Overview of the javascript library: <http://www.tokbox.com/opentok/api/tools/js/documentation/api/Session.html#createArchive>
|
75
|
+
1. Create an event listener on `archiveCreated` event: `session.addEventListener('archiveCreated', archiveCreatedHandler);`
|
76
|
+
2. Create an archive: `archive = session.createArchive(...);`
|
77
|
+
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
|
78
|
+
4. After your archive has been created, you can start recording videos into it by calling `session.startRecording(archive)`
|
79
|
+
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>
|
73
80
|
|
74
81
|
### Get Archive Manifest
|
82
|
+
With your **moderator token** and OpentokSDK Object, you can generate OpenTokArchive Object, which contains information for all videos in the Archive
|
75
83
|
`get_archive_manifest()` takes in 2 parameters: **archiveId** and **moderator token**
|
76
|
-
>
|
84
|
+
> archive_id (string) - REQUIRED.
|
85
|
+
> **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.
|
86
|
+
|
87
|
+
Example:(Make sure you have the OpentokSDK Object)
|
88
|
+
<pre>
|
89
|
+
@token = 'moderator_token'
|
90
|
+
@archiveId = '5f74aee5-ab3f-421b-b124-ed2a698ee939' #Obtained from Javascript Library
|
91
|
+
otArchive = @opentok.get_archive_manifest(@archiveId, @token)
|
92
|
+
</pre>
|
77
93
|
|
78
94
|
### Get video ID
|
79
|
-
|
95
|
+
`OpenTokArchive.resources` is an array of `OpenTokArchiveVideoResource` objects. OpenTokArchiveVideoResource has `getId()` method that returns the videoId
|
80
96
|
`getId()` will return the video ID (a String)
|
81
97
|
|
98
|
+
Example:
|
99
|
+
<pre>
|
100
|
+
otArchive = @opentok.get_archive_manifest(@archiveId, @token)
|
101
|
+
otVideoResource = otArchive.resources[0]
|
102
|
+
videoId = otVideoResource.getId()
|
103
|
+
</pre>
|
104
|
+
|
82
105
|
### Get Download Url
|
83
|
-
`downloadArchiveURL`
|
84
|
-
|
106
|
+
`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
|
107
|
+
> video_id (string) - REQUIRED
|
108
|
+
> token (string) - REQUIRED
|
109
|
+
> returns url string
|
85
110
|
|
111
|
+
Example:
|
112
|
+
<pre>
|
113
|
+
url = otArchive.downloadArchiveURL(video_id, token)
|
114
|
+
</pre>
|
data/lib/open_tok/archive.rb
CHANGED
@@ -9,18 +9,55 @@ 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
|
+
@apiUrl = apiUrl
|
18
|
+
@token = token
|
19
|
+
end
|
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
|
17
42
|
end
|
18
43
|
|
19
44
|
def download_archive_url(video_id)
|
20
|
-
"#{
|
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
|
50
|
+
end
|
51
|
+
|
52
|
+
def downloadArchiveURL(video_id, token="")
|
53
|
+
if token==""
|
54
|
+
return "#{@apiUrl}/archive/url/#{@archive_id}/#{video_id}"
|
55
|
+
else
|
56
|
+
return do_request "#{@apiUrl}/archive/url/#{@archive_id}/#{video_id}", token
|
57
|
+
end
|
21
58
|
end
|
22
59
|
|
23
|
-
def self.parse_manifest(manifest)
|
60
|
+
def self.parse_manifest(manifest, apiUrl, token)
|
24
61
|
archive_id = manifest.attributes['archiveid']
|
25
62
|
archive_title = manifest.attributes['title']
|
26
63
|
|
@@ -34,7 +71,7 @@ module OpenTok
|
|
34
71
|
timeline << OpenTok::ArchiveTimelineEvent.parseXML(event)
|
35
72
|
end
|
36
73
|
|
37
|
-
OpenTok::Archive.new(archive_id, archive_title, resources, timeline)
|
74
|
+
OpenTok::Archive.new(archive_id, archive_title, resources, timeline, apiUrl, token)
|
38
75
|
end
|
39
76
|
end
|
40
|
-
end
|
77
|
+
end
|
@@ -16,9 +16,13 @@ module OpenTok
|
|
16
16
|
@length = length
|
17
17
|
end
|
18
18
|
|
19
|
+
def getId
|
20
|
+
return @id
|
21
|
+
end
|
22
|
+
|
19
23
|
def self.parseXML(video_resource_item)
|
20
24
|
OpenTok::ArchiveVideoResource.new(video_resource_item.attributes['id'], video_resource_item.attributes['length'])
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
|
-
end
|
28
|
+
end
|
@@ -132,11 +132,18 @@ module OpenTok
|
|
132
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)
|
133
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.
|
134
134
|
def get_archive_manifest(archive_id, token)
|
135
|
+
# verify that token is MODERATOR token
|
136
|
+
decoder = token[4..token.length]
|
137
|
+
tokenInfo = Base64.decode64(decoder)
|
138
|
+
if not (tokenInfo.split('role=')[1].split('&')[0]==OpenTok::RoleConstants::MODERATOR)
|
139
|
+
raise OpenTokException.new("Token must be assigned role of MODERATROR")
|
140
|
+
end
|
141
|
+
|
135
142
|
doc = do_request("/archive/getmanifest/#{archive_id}", {}, token)
|
136
143
|
if not doc.get_elements('Errors').empty?
|
137
144
|
raise OpenTokException.new doc.get_elements('Errors')[0].get_elements('error')[0].children.to_s
|
138
145
|
end
|
139
|
-
OpenTok::Archive.parse_manifest(doc.get_elements('manifest')[0])
|
146
|
+
OpenTok::Archive.parse_manifest(doc.get_elements('manifest')[0], @api_url, token)
|
140
147
|
end
|
141
148
|
|
142
149
|
protected
|
data/lib/open_tok/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Opentok
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.7"
|
3
|
+
end
|
data/opentok.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Stijn Mathysen", "Karmen Blake"]
|
10
10
|
s.email = ["stijn@skylight.be", "karmenblake@gmail.com"]
|
11
|
-
s.homepage = "https://github.com/
|
11
|
+
s.homepage = "https://github.com/opentok/Opentok-Ruby-SDK"
|
12
12
|
s.summary = %q{OpenTok gem}
|
13
13
|
s.description = %q{OpenTok is a free set of APIs 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)}
|
14
14
|
|
data/spec/opentok_spec.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
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
|
+
|
3
9
|
describe OpenTok do
|
4
10
|
|
5
11
|
before :all do
|
@@ -11,23 +17,97 @@ describe OpenTok do
|
|
11
17
|
|
12
18
|
@opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
|
13
19
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
|
21
|
+
describe "Staging Environment" do
|
22
|
+
before :all do
|
23
|
+
@api_key = '14971292'
|
24
|
+
@api_secret = 'ecbe2b25afec7887bd72fe4763b87add8ce02658'
|
25
|
+
@opentok = TestOpentokSDK.new @api_key, @api_secret
|
26
|
+
@opts = {:partner_id => @api_key, :location=>@host}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be possible to valid a OpenTokSDK object with a valid key and secret" do
|
30
|
+
@opentok.should be_instance_of TestOpentokSDK
|
31
|
+
end
|
32
|
+
|
33
|
+
it "a new OpenTokSDK object should point to the staging environment by default" do
|
34
|
+
@opentok.api_url.should eq @api_staging_url
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should generate a valid session" do
|
38
|
+
session = @opentok.create_session @host
|
39
|
+
session.to_s.should match(/\A[0-9A-z_-]{40,}\Z/)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "do_request should respond with valid p2p" do
|
43
|
+
@opts.merge!({'p2p.preference' => 'enabled'})
|
44
|
+
doc = @opentok.do_request("/session/create", @opts)
|
45
|
+
doc.root.get_elements('Session')[0].get_elements('properties')[0].get_elements('p2p')[0].get_elements('preference')[0].children[0].to_s.should =='enabled'
|
46
|
+
end
|
21
47
|
end
|
22
|
-
|
23
|
-
describe "
|
24
|
-
|
25
|
-
|
26
|
-
|
48
|
+
|
49
|
+
describe "Production Environment" do
|
50
|
+
before :all do
|
51
|
+
@api_key = '11421872'
|
52
|
+
@api_secret = '296cebc2fc4104cd348016667ffa2a3909ec636f'
|
53
|
+
@opentok = TestOpentokSDK.new @api_key, @api_secret, {:api_url=>@api_production_url}
|
54
|
+
@opts = {:partner_id => @api_key, :location=>@host}
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be possible to valid a OpenTokSDK object with a valid key and secret" do
|
58
|
+
@opentok.should be_instance_of TestOpentokSDK
|
59
|
+
end
|
27
60
|
|
61
|
+
it "a new OpenTokSDK object should point to the staging environment by default" do
|
62
|
+
@opentok.api_url.should eq @api_production_url
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should generate a valid session" do
|
66
|
+
session = @opentok.create_session @host
|
28
67
|
session.to_s.should match(/\A[0-9A-z_-]{40,}\Z/)
|
29
68
|
end
|
69
|
+
|
70
|
+
it "do_request should respond with valid p2p" do
|
71
|
+
@opts.merge!({'p2p.preference' => 'enabled'})
|
72
|
+
doc = @opentok.do_request("/session/create", @opts)
|
73
|
+
doc.root.get_elements('Session')[0].get_elements('properties')[0].get_elements('p2p')[0].get_elements('preference')[0].children[0].to_s.should =='enabled'
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "Archiving downloads" do
|
77
|
+
before :all do
|
78
|
+
@session = '1_MX4xNDk3MTI5Mn5-MjAxMi0wNS0yMCAwMTowMzozMS41MDEzMDArMDA6MDB-MC40NjI0MjI4MjU1MDF-'
|
79
|
+
@opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret, {:api_url=>@api_production_url}
|
80
|
+
@token = @opentok.generate_token({:session_id => @session, :role=>OpenTok::RoleConstants::MODERATOR})
|
81
|
+
@archiveId = '5f74aee5-ab3f-421b-b124-ed2a698ee939'
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should have archive resources" do
|
85
|
+
otArchive = @opentok.get_archive_manifest(@archiveId, @token)
|
86
|
+
otArchiveResource = otArchive.resources[0]
|
87
|
+
vid = otArchiveResource.getId()
|
88
|
+
vid.should match(/[0-9A-z=]+/)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return download url" do
|
92
|
+
otArchive = @opentok.get_archive_manifest(@archiveId, @token)
|
93
|
+
otArchiveResource = otArchive.resources[0]
|
94
|
+
vid = otArchiveResource.getId()
|
95
|
+
url = otArchive.downloadArchiveURL(vid)
|
96
|
+
url.start_with?('http').should eq true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should return file url" do
|
100
|
+
otArchive = @opentok.get_archive_manifest(@archiveId, @token)
|
101
|
+
otArchiveResource = otArchive.resources[0]
|
102
|
+
vid = otArchiveResource.getId()
|
103
|
+
url = otArchive.downloadArchiveURL(vid, @token)
|
104
|
+
url.start_with?('http').should eq true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
30
109
|
|
110
|
+
describe "Session creation" do
|
31
111
|
it "should raise an exception with an invalid key and secret" do
|
32
112
|
opentok = OpenTok::OpenTokSDK.new 0, ''
|
33
113
|
|
@@ -76,5 +156,12 @@ describe OpenTok do
|
|
76
156
|
@opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
|
77
157
|
@valid_session = @opentok.create_session(@host).to_s
|
78
158
|
end
|
159
|
+
|
160
|
+
it "If token does not have moderator role, raise error" do
|
161
|
+
token = @opentok.generate_token(:session_id=>@valid_session)
|
162
|
+
expect{
|
163
|
+
@opentok.get_archive_manifest("", token)
|
164
|
+
}.to raise_error OpenTok::OpenTokException
|
165
|
+
end
|
79
166
|
end
|
80
167
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'I18n'
|
2
|
-
require File.dirname(__FILE__) + '/../lib/opentok.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/opentok.rb'
|
metadata
CHANGED
@@ -1,35 +1,29 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentok
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 6
|
10
|
-
version: 0.0.6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Stijn Mathysen
|
14
9
|
- Karmen Blake
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
date: 2012-04-27 00:00:00 Z
|
13
|
+
date: 2012-05-31 00:00:00.000000000 Z
|
20
14
|
dependencies: []
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
description: OpenTok is a free set of APIs from TokBox that enables websites to weave
|
16
|
+
live group video communication into their online experience. With OpenTok you have
|
17
|
+
the freedom and flexibility to create the most engaging web experience for your
|
18
|
+
users. OpenTok is currently available as a JavaScript and ActionScript 3.0 library.
|
19
|
+
This gem allows you to connect to the API from within Ruby (and Rails)
|
20
|
+
email:
|
24
21
|
- stijn@skylight.be
|
25
22
|
- karmenblake@gmail.com
|
26
23
|
executables: []
|
27
|
-
|
28
24
|
extensions: []
|
29
|
-
|
30
25
|
extra_rdoc_files: []
|
31
|
-
|
32
|
-
files:
|
26
|
+
files:
|
33
27
|
- .gitignore
|
34
28
|
- CHANGES
|
35
29
|
- Gemfile
|
@@ -96,39 +90,30 @@ files:
|
|
96
90
|
- opentok.gemspec
|
97
91
|
- spec/opentok_spec.rb
|
98
92
|
- spec/spec_helper.rb
|
99
|
-
homepage: https://github.com/
|
93
|
+
homepage: https://github.com/opentok/Opentok-Ruby-SDK
|
100
94
|
licenses: []
|
101
|
-
|
102
95
|
post_install_message:
|
103
96
|
rdoc_options: []
|
104
|
-
|
105
|
-
require_paths:
|
97
|
+
require_paths:
|
106
98
|
- lib
|
107
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
100
|
none: false
|
109
|
-
requirements:
|
110
|
-
- -
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
|
113
|
-
|
114
|
-
- 0
|
115
|
-
version: "0"
|
116
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
106
|
none: false
|
118
|
-
requirements:
|
119
|
-
- -
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
|
122
|
-
segments:
|
123
|
-
- 0
|
124
|
-
version: "0"
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
125
111
|
requirements: []
|
126
|
-
|
127
112
|
rubyforge_project: opentok
|
128
|
-
rubygems_version: 1.8.
|
113
|
+
rubygems_version: 1.8.21
|
129
114
|
signing_key:
|
130
115
|
specification_version: 3
|
131
116
|
summary: OpenTok gem
|
132
|
-
test_files:
|
117
|
+
test_files:
|
133
118
|
- spec/opentok_spec.rb
|
134
119
|
- spec/spec_helper.rb
|