opentok 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,9 @@
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
+
3
7
  == Version 0.0.5
4
8
 
5
9
  * Added connection_data to generate token method (thanks to https://github.com/jonmumm)
@@ -0,0 +1,85 @@
1
+ # Opentok
2
+
3
+ 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. Check out <http://www.tokbox.com/> and <http://www.tokbox.com/opentok/tools/js/gettingstarted> for more information.
4
+
5
+ This is the official Opentok rubygem.
6
+
7
+ ## Installation
8
+
9
+ To install using bundler, add Opentok to your `gemfile` and run `bundle install`:
10
+ <pre>
11
+ gem 'opentok'
12
+ </pre>
13
+
14
+ To install as a regular gem just type `gem install opentok`
15
+
16
+ ## How to use
17
+
18
+ ### API-key and secret
19
+
20
+ Request your api-key and secret at <http://www.tokbox.com/opentok/tools/js/apikey>. You can use the staging environment for testing. The gem uses this staging environment by default.
21
+
22
+ ### OpenTokSDK
23
+
24
+ In order to use any of the server side functions, you must first create an `OpenTokSDK` object with your developer credentials.
25
+ You must pass in your *Key* and *Secret*. If your app is in production, you must also pass in a hash containing `api_url`
26
+ For more information about production apps, check out <http://www.tokbox.com/opentok/api/tools/js/launch>
27
+
28
+ Example: ( Staging )
29
+ <pre>
30
+ @api_key = '' # should be a string
31
+ @api_secret = '' # should be a string
32
+ @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
33
+ </pre>
34
+
35
+ Example: ( Production )
36
+ <pre>
37
+ @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret, :api_url => 'https://api.opentok.com/hl'
38
+ </pre>
39
+
40
+ ### Creating Sessions
41
+ Use your `OpenTokSDK` object to create `session_id`
42
+ `create_session` takes 1-2 parameters:
43
+ > location (string) - give Opentok a hint on where you are running your application
44
+ > properties (object) - OPTIONAL. Set peer to peer as `enabled` or `disabled`
45
+
46
+ Example: P2P disabled by default
47
+ <pre>
48
+ @location = 'localhost'
49
+ session_id = @opentok.create_session(@location)
50
+ </pre>
51
+
52
+ Example: P2P enabled
53
+ <pre>
54
+ session_properties = {OpenTok::SessionPropertyConstants::P2P_PREFERENCE => "enabled"} # or disabled
55
+ session_id = @opentok.create_session( @location, session_properties )
56
+ </pre>
57
+
58
+ ### Generating Token
59
+ With the generated session_id, you can start generating tokens for each user.
60
+ `generate_token` takes in hash with 1-4 properties:
61
+ > session_id (string) - required
62
+ > role (string) - OPTIONAL. subscriber, publisher, or moderator
63
+ > expire_time (int) - OPTIONAL. Time when token will expire in unix timestamp
64
+ > connection_data (string) - OPTIONAL. Metadata to store data (names, user id, etc)
65
+
66
+ Example:
67
+ <pre>
68
+ token = @opentok.generate_token :session_id => session, :role => OpenTok::RoleConstants::PUBLISHER, :connection_data => "username=Bob,level=4"
69
+ </pre>
70
+
71
+ ### Downloading Archive Videos
72
+ To Download archives, first you must first create a token that has a **moderator** role
73
+
74
+ ### Get Archive Manifest
75
+ `get_archive_manifest()` takes in 2 parameters: **archiveId** and **moderator token**
76
+ > **returns** an `OpenTokArchive`. The *resources* property of this object is array of `OpenTokArchiveVideoResource`, and each `OpenTokArchiveVideoResource` object represents a video in the archive.
77
+
78
+ ### Get video ID
79
+ With your `OpenTokArchive` object, call `getId()`
80
+ `getId()` will return the video ID (a String)
81
+
82
+ ### Get Download Url
83
+ `downloadArchiveURL` takes 1 parameters: `video ID` and returns download URL for the video
84
+
85
+
@@ -2,7 +2,7 @@
2
2
  OpenTok Ruby Library
3
3
  http://www.tokbox.com/
4
4
 
5
- Copyright 2010, TokBox, Inc.
5
+ Copyright 2010 - 2011, TokBox, Inc.
6
6
 
7
7
  Last modified: 2011-02-17
8
8
  =end
@@ -0,0 +1,40 @@
1
+ =begin
2
+ OpenTok Ruby Library v0.90.0
3
+ http://www.tokbox.com/
4
+
5
+ Copyright 2010 - 2011, TokBox, Inc.
6
+ =end
7
+
8
+ module OpenTok
9
+ class Archive
10
+ attr_accessor :archive_id, :archive_title, :resources, :timeline
11
+
12
+ def initialize(archive_id, archive_title, resources, timeline)
13
+ @archive_id = archive_id
14
+ @archive_title = archive_title
15
+ @resources = resources
16
+ @timeline = timeline
17
+ end
18
+
19
+ def download_archive_url(video_id)
20
+ "#{API_URL}/archive/url/#{@archive_id}/#{video_id}"
21
+ end
22
+
23
+ def self.parse_manifest(manifest)
24
+ archive_id = manifest.attributes['archiveid']
25
+ archive_title = manifest.attributes['title']
26
+
27
+ resources = []
28
+ manifest.get_elements("resources")[0].get_elements("video").each do |video|
29
+ resources << OpenTok::ArchiveVideoResource.parseXML(video)
30
+ end
31
+
32
+ timeline = []
33
+ manifest.get_elements("timeline")[0].get_elements("event").each do |event|
34
+ timeline << OpenTok::ArchiveTimelineEvent.parseXML(event)
35
+ end
36
+
37
+ OpenTok::Archive.new(archive_id, archive_title, resources, timeline)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,22 @@
1
+ =begin
2
+ OpenTok Ruby Library v0.90.0
3
+ http://www.tokbox.com/
4
+
5
+ Copyright 2010 - 2011, TokBox, Inc.
6
+ =end
7
+
8
+ module OpenTok
9
+ class ArchiveTimelineEvent
10
+ attr_accessor :event_type, :resource_id, :offset
11
+
12
+ def initialize(event_type, resource_id, offset)
13
+ @event_type = event_type
14
+ @resource_id = resource_id
15
+ @offset = offset
16
+ end
17
+
18
+ def self.parseXML(timeline_item)
19
+ OpenTok::ArchiveTimelineEvent.new(timeline_item.attributes['type'], timeline_item.attributes['id'], timeline_item.attributes['offset'])
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ =begin
2
+ OpenTok Ruby Library v0.90.0
3
+ http://www.tokbox.com/
4
+
5
+ Copyright 2010 - 2011, TokBox, Inc.
6
+ =end
7
+
8
+ module OpenTok
9
+ class ArchiveVideoResource
10
+ attr_reader :type
11
+ attr_accessor :id, :length
12
+
13
+ def initialize(id, length)
14
+ @id = id
15
+ @type = "video"
16
+ @length = length
17
+ end
18
+
19
+ def self.parseXML(video_resource_item)
20
+ OpenTok::ArchiveVideoResource.new(video_resource_item.attributes['id'], video_resource_item.attributes['length'])
21
+ end
22
+ end
23
+
24
+ end
@@ -2,7 +2,7 @@
2
2
  OpenTok Ruby Library
3
3
  http://www.tokbox.com/
4
4
 
5
- Copyright 2010, TokBox, Inc.
5
+ Copyright 2010 - 2011, TokBox, Inc.
6
6
 
7
7
  =end
8
8
 
@@ -12,5 +12,4 @@ module OpenTok
12
12
  class OpenTokException < RuntimeError
13
13
  end
14
14
 
15
- end
16
-
15
+ end
@@ -2,7 +2,7 @@
2
2
  OpenTok Ruby Library
3
3
  http://www.tokbox.com/
4
4
 
5
- Copyright 2010, TokBox, Inc.
5
+ Copyright 2010 - 2011, TokBox, Inc.
6
6
 
7
7
  =end
8
8
 
@@ -17,25 +17,36 @@ DIGEST = OpenSSL::Digest::Digest.new('sha1')
17
17
 
18
18
  module OpenTok
19
19
 
20
+ # SessionPropertyConstants
21
+ #
22
+ # * +ECHOSUPPRESSION_ENABLED+ boolean
23
+ # * +MULTIPLEXER_NUMOUTPUTSTREAMS+ integer
24
+ # * +MULTIPLEXER_SWITCHTYPE+ integer
25
+ # * +MULTIPLEXER_SWITCHTIMEOUT+ integer
26
+ # * +P2P_PREFERENCE+ string
20
27
  class SessionPropertyConstants
21
- ECHOSUPPRESSION_ENABLED = "echoSuppression.enabled"; #Boolean
22
- MULTIPLEXER_NUMOUTPUTSTREAMS = "multiplexer.numOutputStreams"; #Integer
23
- MULTIPLEXER_SWITCHTYPE = "multiplexer.switchType"; #Integer
24
- MULTIPLEXER_SWITCHTIMEOUT = "multiplexer.switchTimeout"; #Integer
25
- P2P_PREFERENCE = "p2p.preference"; #String
28
+ ECHOSUPPRESSION_ENABLED = "echoSuppression.enabled" #Boolean
29
+ MULTIPLEXER_NUMOUTPUTSTREAMS = "multiplexer.numOutputStreams" #Integer
30
+ MULTIPLEXER_SWITCHTYPE = "multiplexer.switchType" #Integer
31
+ MULTIPLEXER_SWITCHTIMEOUT = "multiplexer.switchTimeout" #Integer
32
+ P2P_PREFERENCE = "p2p.preference" #String
26
33
  end
27
34
 
35
+ # RoleConstants
36
+ #
37
+ # * +SUBSCRIBER+ Can only subscribe
38
+ # * +PUBLISHER+ Can publish, subscribe, and signal
39
+ # * +MODERATOR+ Can do the above along with forceDisconnect and forceUnpublish
28
40
  class RoleConstants
29
41
  SUBSCRIBER = "subscriber" #Can only subscribe
30
- PUBLISHER = "publisher" #Can publish, subscribe, and signal
31
- MODERATOR = "moderator" #Can do the above along with forceDisconnect and forceUnpublish
42
+ PUBLISHER = "publisher" #Can publish, subscribe, and signal
43
+ MODERATOR = "moderator" #Can do the above along with forceDisconnect and forceUnpublish
32
44
  end
33
45
 
34
46
  class OpenTokSDK
35
47
  attr_accessor :api_url
36
48
 
37
49
  @@TOKEN_SENTINEL = "T1=="
38
- @@SDK_VERSION = "tbruby-%s" % [ VERSION ]
39
50
 
40
51
  # Create a new OpenTokSDK object.
41
52
  #
@@ -66,12 +77,16 @@ module OpenTok
66
77
  #
67
78
  # See http://www.tokbox.com/opentok/tools/documentation/overview/token_creation.html for more information on all options.
68
79
  def generate_token(opts = {})
69
- {:session_id=>nil, :create_time=>nil, :expire_time=>nil, :role=>nil, :connection_data=>nil}.merge!(opts)
80
+ { :session_id => nil, :create_time => nil, :expire_time => nil, :role => nil, :connection_data => nil }.merge!(opts)
70
81
 
71
- create_time = opts[:create_time].nil? ? Time.now : opts[:create_time]
82
+ create_time = opts[:create_time].nil? ? Time.now : opts[:create_time]
72
83
  session_id = opts[:session_id].nil? ? '' : opts[:session_id]
73
84
  role = opts[:role].nil? ? RoleConstants::PUBLISHER : opts[:role]
74
85
 
86
+ if role != RoleConstants::SUBSCRIBER && role != RoleConstants::PUBLISHER && role != RoleConstants::MODERATOR
87
+ raise OpenTokException.new "'#{role}' is not a recognized role"
88
+ end
89
+
75
90
  data_params = {
76
91
  :role => role,
77
92
  :session_id => session_id,
@@ -80,6 +95,9 @@ module OpenTok
80
95
  }
81
96
 
82
97
  if not opts[:expire_time].nil?
98
+ raise OpenTokException.new 'Expire time must be a number' if not opts[:expire_time].is_a?(Numeric)
99
+ raise OpenTokException.new 'Expire time must be in the future' if opts[:expire_time] < Time.now.to_i
100
+ raise OpenTokException.new 'Expire time must be in the next 7 days' if opts[:expire_time] > (Time.now.to_i + 604800)
83
101
  data_params[:expire_time] = opts[:expire_time].to_i
84
102
  end
85
103
 
@@ -93,11 +111,10 @@ module OpenTok
93
111
  sig = sign_string(data_string, @partner_secret)
94
112
  meta_string = {
95
113
  :partner_id => @partner_id,
96
- :sdk_version => @@SDK_VERSION,
97
114
  :sig => sig
98
115
  }.urlencode
99
116
 
100
- @@TOKEN_SENTINEL + Base64.encode64(meta_string + ":" + data_string).gsub("\n","")
117
+ @@TOKEN_SENTINEL + Base64.encode64(meta_string + ":" + data_string).gsub("\n", '')
101
118
  end
102
119
 
103
120
  # 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@.
@@ -112,6 +129,16 @@ module OpenTok
112
129
  OpenTok::Session.new(doc.root.get_elements('Session')[0].get_elements('session_id')[0].children[0].to_s)
113
130
  end
114
131
 
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
+ # 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
+ def get_archive_manifest(archive_id, token)
135
+ doc = do_request("/archive/getmanifest/#{archive_id}", {}, token)
136
+ if not doc.get_elements('Errors').empty?
137
+ raise OpenTokException.new doc.get_elements('Errors')[0].get_elements('error')[0].children.to_s
138
+ end
139
+ OpenTok::Archive.parse_manifest(doc.get_elements('manifest')[0])
140
+ end
141
+
115
142
  protected
116
143
  def sign_string(data, secret)
117
144
  OpenSSL::HMAC.hexdigest(DIGEST, secret, data)
@@ -2,9 +2,7 @@
2
2
  OpenTok Ruby Library v0.90.0
3
3
  http://www.tokbox.com/
4
4
 
5
- Copyright 2010, TokBox, Inc.
6
-
7
- Date: November 05 14:50:00 2010
5
+ Copyright 2010 - 2011, TokBox, Inc.
8
6
  =end
9
7
 
10
8
  module OpenTok
@@ -22,4 +20,3 @@ module OpenTok
22
20
  end
23
21
  end
24
22
  end
25
-
@@ -1,3 +1,3 @@
1
1
  module Opentok
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -2,7 +2,7 @@
2
2
  OpenTok Ruby Library
3
3
  http://www.tokbox.com/
4
4
 
5
- Copyright 2010, TokBox, Inc.
5
+ Copyright 2010 - 2011, TokBox, Inc.
6
6
 
7
7
  Last modified: 2011-02-17
8
8
  =end
@@ -21,7 +21,10 @@ module OpenTok
21
21
  API_URL = "https://staging.tokbox.com/hl"
22
22
 
23
23
  require 'monkey_patches'
24
- require 'open_tok/exceptions'
24
+ require 'open_tok/exception'
25
25
  require 'open_tok/open_tok_sdk'
26
26
  require 'open_tok/session'
27
+ require 'open_tok/archive'
28
+ require 'open_tok/archive_video_resource'
29
+ require 'open_tok/archive_timeline_event'
27
30
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe OpenTok do
4
4
 
5
5
  before :all do
6
- @api_key = 459782
6
+ @api_key = '459782'
7
7
  @api_secret = 'b44c3baa32b6476d9d88e8194d0eb1c6b777f76b'
8
8
  @api_staging_url = 'https://staging.tokbox.com/hl'
9
9
  @api_production_url = 'https://api.opentok.com/hl'
@@ -60,5 +60,21 @@ describe OpenTok do
60
60
 
61
61
  token.should match(/\A[0-9A-z=]+\Z/)
62
62
  end
63
+
64
+ it "should be able to set parameters in token" do
65
+ token = @opentok.generate_token :session_id => @valid_session.to_s, :role=> OpenTok::RoleConstants::PUBLISHER, :connection_data => "username=Bob,level=4"
66
+
67
+ str = token[4..token.length]
68
+ decoded = Base64.decode64(str)
69
+
70
+ decoded.should match(/publisher.*username.*Bob.*level.*4/)
71
+ end
72
+ end
73
+
74
+ describe "Archive Download" do
75
+ before :all do
76
+ @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
77
+ @valid_session = @opentok.create_session(@host).to_s
78
+ end
63
79
  end
64
- end
80
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentok
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stijn Mathysen
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-11-30 00:00:00 Z
19
+ date: 2012-04-27 00:00:00 Z
20
20
  dependencies: []
21
21
 
22
22
  description: 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)
@@ -34,7 +34,7 @@ files:
34
34
  - CHANGES
35
35
  - Gemfile
36
36
  - LICENCE
37
- - README.textile
37
+ - README.md
38
38
  - Rakefile
39
39
  - doc/CHANGES.html
40
40
  - doc/Gemfile.html
@@ -85,7 +85,10 @@ files:
85
85
  - doc/spec/opentok_spec_rb.html
86
86
  - doc/spec/spec_helper_rb.html
87
87
  - lib/monkey_patches.rb
88
- - lib/open_tok/exceptions.rb
88
+ - lib/open_tok/archive.rb
89
+ - lib/open_tok/archive_timeline_event.rb
90
+ - lib/open_tok/archive_video_resource.rb
91
+ - lib/open_tok/exception.rb
89
92
  - lib/open_tok/open_tok_sdk.rb
90
93
  - lib/open_tok/session.rb
91
94
  - lib/open_tok/version.rb
@@ -122,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
125
  requirements: []
123
126
 
124
127
  rubyforge_project: opentok
125
- rubygems_version: 1.8.3
128
+ rubygems_version: 1.8.10
126
129
  signing_key:
127
130
  specification_version: 3
128
131
  summary: OpenTok gem
@@ -1,43 +0,0 @@
1
- h1. Opentok
2
-
3
- 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. Check out http://www.tokbox.com/ and http://www.tokbox.com/opentok/tools/js/gettingstarted for more information.
4
-
5
- This is the official Opentok rubygem.
6
-
7
- h2. Installation
8
-
9
- To install using bundler, add Opentok to you @gemfile@ and run `bundle install`:
10
-
11
- <pre>
12
- gem 'opentok'
13
- </pre>
14
-
15
- To install as a regular gem just type `gem install opentok`
16
-
17
- h2. How it works
18
-
19
- h3. API-key and secret
20
-
21
- Request your api-key and secret at http://www.tokbox.com/opentok/tools/js/apikey. You can use the staging environment for testing. The gem uses this staging environment by default.
22
-
23
- h3. Create a session
24
-
25
- With the following code, you can generate a valid @session_id@.
26
- <pre>
27
- @api_key = 0 # should be a number
28
- @api_secret = '' # should be a string
29
- @location = 'localhost' # give Opentok a hint on where you are running your application
30
-
31
- @opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret
32
-
33
- @session_id = @opentok.create_session(@host)
34
- </pre>
35
-
36
- h3. Create tokens
37
-
38
- With the generated session_id, you can start generating tokens for each user.
39
- <pre>
40
- @opentok.generate_token :session_id => "#{@session_id}"
41
- </pre>
42
-
43
- Typically you would create one @session_id@ and store it (in e.g. a setting) and share that @session_id@ between all users.