opentok 0.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +16 -2
  3. data/.travis.yml +6 -0
  4. data/.yardopts +1 -0
  5. data/CONTRIBUTING.md +47 -0
  6. data/DEVELOPING.md +91 -0
  7. data/LICENSE +19 -5
  8. data/README.md +170 -53
  9. data/Rakefile +10 -5
  10. data/doc/OpenTok.html +411 -0
  11. data/doc/OpenTok/Archive.html +1320 -0
  12. data/doc/OpenTok/ArchiveList.html +216 -0
  13. data/doc/OpenTok/Archives.html +1028 -0
  14. data/doc/OpenTok/Client.html +695 -0
  15. data/doc/OpenTok/OpenTok.html +1046 -0
  16. data/doc/OpenTok/OpenTokArchiveError.html +142 -0
  17. data/doc/OpenTok/OpenTokAuthenticationError.html +143 -0
  18. data/doc/OpenTok/OpenTokError.html +138 -0
  19. data/doc/OpenTok/Session.html +665 -0
  20. data/doc/OpenTok/TokenGenerator.html +204 -0
  21. data/doc/OpenTok/TokenGenerator/ClassMethods.html +187 -0
  22. data/doc/README.md +15 -0
  23. data/doc/_index.html +182 -0
  24. data/doc/class_list.html +54 -0
  25. data/doc/css/common.css +1 -0
  26. data/doc/css/full_list.css +57 -0
  27. data/doc/css/style.css +339 -0
  28. data/doc/file.README.html +87 -0
  29. data/doc/file_list.html +56 -0
  30. data/doc/frames.html +26 -0
  31. data/doc/index.html +87 -0
  32. data/doc/js/app.js +219 -0
  33. data/doc/js/full_list.js +178 -0
  34. data/doc/js/jquery.js +4 -0
  35. data/doc/method_list.html +227 -0
  36. data/doc/top-level-namespace.html +112 -0
  37. data/lib/opentok.rb +3 -14
  38. data/lib/opentok/archive.rb +92 -0
  39. data/lib/opentok/archive_list.rb +17 -0
  40. data/lib/opentok/archives.rb +120 -0
  41. data/lib/opentok/client.rb +125 -0
  42. data/lib/opentok/constants.rb +5 -0
  43. data/lib/opentok/exceptions.rb +10 -0
  44. data/lib/opentok/opentok.rb +174 -0
  45. data/lib/opentok/session.rb +76 -0
  46. data/lib/opentok/token_generator.rb +101 -0
  47. data/lib/opentok/version.rb +4 -0
  48. data/opentok.gemspec +29 -22
  49. data/sample/Archiving/Gemfile +4 -0
  50. data/sample/Archiving/README.md +212 -0
  51. data/sample/Archiving/archiving_sample.rb +80 -0
  52. data/sample/Archiving/public/css/sample.css +22 -0
  53. data/sample/Archiving/public/img/archiving-off.png +0 -0
  54. data/sample/Archiving/public/img/archiving-on-idle.png +0 -0
  55. data/sample/Archiving/public/img/archiving-on-message.png +0 -0
  56. data/sample/Archiving/public/js/host.js +37 -0
  57. data/sample/Archiving/public/js/participant.js +13 -0
  58. data/sample/Archiving/views/history.erb +65 -0
  59. data/sample/Archiving/views/host.erb +69 -0
  60. data/sample/Archiving/views/index.erb +48 -0
  61. data/sample/Archiving/views/layout.erb +29 -0
  62. data/sample/Archiving/views/participant.erb +55 -0
  63. data/sample/HelloWorld/Gemfile +4 -0
  64. data/sample/HelloWorld/README.md +123 -0
  65. data/sample/HelloWorld/hello_world.rb +27 -0
  66. data/sample/HelloWorld/public/js/helloworld.js +32 -0
  67. data/sample/HelloWorld/views/index.erb +21 -0
  68. data/spec/cassettes/OpenTok_Archives/should_create_archives.yml +48 -0
  69. data/spec/cassettes/OpenTok_Archives/should_create_named_archives.yml +49 -0
  70. data/spec/cassettes/OpenTok_Archives/should_delete_an_archive_by_id.yml +32 -0
  71. data/spec/cassettes/OpenTok_Archives/should_find_archives_by_id.yml +46 -0
  72. data/spec/cassettes/OpenTok_Archives/should_stop_archives.yml +48 -0
  73. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_all_archives.yml +104 -0
  74. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_archives_with_an_offset.yml +71 -0
  75. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_count_number_of_archives.yml +60 -0
  76. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_part_of_the_archives_when_using_offset_and_count.yml +82 -0
  77. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_default_sessions.yml +39 -0
  78. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions.yml +39 -0
  79. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions_with_a_location_hint.yml +39 -0
  80. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions.yml +39 -0
  81. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions_for_invalid_media_modes.yml +39 -0
  82. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions_with_a_location_hint.yml +39 -0
  83. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_sessions_with_a_location_hint.yml +39 -0
  84. data/spec/matchers/token.rb +48 -0
  85. data/spec/opentok/archives_spec.rb +91 -0
  86. data/spec/opentok/opentok_spec.rb +144 -0
  87. data/spec/opentok/session_spec.rb +71 -0
  88. data/spec/shared/opentok_generates_tokens.rb +62 -0
  89. data/spec/shared/session_generates_tokens.rb +63 -0
  90. data/spec/spec_helper.rb +6 -7
  91. metadata +197 -59
  92. data/.rspec +0 -3
  93. data/CHANGES +0 -33
  94. data/doc/reference.md +0 -122
  95. data/lib/open_tok/archive.rb +0 -53
  96. data/lib/open_tok/archive_timeline_event.rb +0 -22
  97. data/lib/open_tok/archive_video_resource.rb +0 -28
  98. data/lib/open_tok/exception.rb +0 -50
  99. data/lib/open_tok/open_tok_sdk.rb +0 -198
  100. data/lib/open_tok/request.rb +0 -63
  101. data/lib/open_tok/role_constants.rb +0 -18
  102. data/lib/open_tok/session.rb +0 -25
  103. data/lib/open_tok/session_property_constants.rb +0 -30
  104. data/lib/open_tok/utils.rb +0 -10
  105. data/lib/open_tok/version.rb +0 -5
  106. data/sample/sample.rb +0 -26
  107. data/spec/cassettes/archives.yml +0 -83
  108. data/spec/cassettes/deleteArchive.yml +0 -91
  109. data/spec/cassettes/invalidSession.yml +0 -41
  110. data/spec/cassettes/session.yml +0 -46
  111. data/spec/cassettes/stitchArchive.yml +0 -42
  112. data/spec/opentok_exception_spec.rb +0 -38
  113. data/spec/opentok_spec.rb +0 -135
@@ -1,53 +0,0 @@
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, api_url, token)
13
- @archive_id = archive_id
14
- @archive_title = archive_title
15
- @resources = resources
16
- @timeline = timeline
17
- @api_url = api_url
18
- @token = token
19
- end
20
-
21
- def do_request(path, token)
22
- Request.new(@api_url, token).fetch(path)
23
- end
24
-
25
- def download_archive_url(video_id, token="")
26
- if token.empty?
27
- # this token check supports previous implementation of download_archive_url
28
- "#{@api_url}/archive/url/#{@archive_id}/#{video_id}"
29
- else
30
- do_request "/archive/url/#{@archive_id}/#{video_id}", token
31
- end
32
- end
33
-
34
- alias_method :downloadArchiveURL, :download_archive_url
35
-
36
- def self.parse_manifest(manifest, api_url, token)
37
- archive_id = manifest.attributes['archiveid']
38
- archive_title = manifest.attributes['title']
39
-
40
- resources = []
41
- manifest.get_elements('resources')[0].get_elements('video').each do |video|
42
- resources << ArchiveVideoResource.parseXML(video)
43
- end
44
-
45
- timeline = []
46
- manifest.get_elements('timeline')[0].get_elements('event').each do |event|
47
- timeline << ArchiveTimelineEvent.parseXML(event)
48
- end
49
-
50
- Archive.new archive_id, archive_title, resources, timeline, api_url, token
51
- end
52
- end
53
- end
@@ -1,22 +0,0 @@
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
@@ -1,28 +0,0 @@
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 getId
20
- return @id
21
- end
22
-
23
- def self.parseXML(video_resource_item)
24
- ArchiveVideoResource.new video_resource_item.attributes['id'], video_resource_item.attributes['length']
25
- end
26
- end
27
-
28
- end
@@ -1,50 +0,0 @@
1
- =begin
2
- OpenTok Ruby Library
3
- http://www.tokbox.com/
4
-
5
- Copyright 2010 - 2011, TokBox, Inc.
6
-
7
- =end
8
-
9
- module OpenTok
10
-
11
- # The exception that gets thrown when an invalid api-key and/or secret is given.
12
- class OpenTokException < RuntimeError
13
-
14
- def initialize(message)
15
- @mesasge = message
16
- end
17
-
18
- class << self
19
- def inherited(subclass)
20
- exceptions << subclass
21
- end
22
-
23
- def exceptions
24
- @exceptions ||= []
25
- end
26
-
27
- ##
28
- # Generates the relevant exception instance based on the XML error data received
29
- def from_error(error)
30
- child = error.get_elements('Errors')[0].get_elements('error')[0]
31
- exception ||= self
32
- message = child.children.empty? ? '' : child.children[0].attributes['message']
33
- exception.new message
34
- end
35
-
36
- # To be overriden by subclasses
37
- def http_code
38
- '000'
39
- end
40
- end
41
-
42
- end
43
-
44
- class OpenTokNotFound < OpenTokException
45
- def self.http_code
46
- '404'
47
- end
48
- end
49
-
50
- end
@@ -1,198 +0,0 @@
1
- =begin
2
- OpenTok Ruby Library
3
- http://www.tokbox.com/
4
-
5
- Copyright 2010 - 2011, TokBox, Inc.
6
-
7
- =end
8
-
9
- require 'openssl'
10
- require 'base64'
11
- require 'rexml/document'
12
-
13
- DIGEST = OpenSSL::Digest::Digest.new 'sha1'
14
-
15
- module OpenTok
16
-
17
- autoload :Archive , 'open_tok/archive'
18
- autoload :ArchiveVideoResource , 'open_tok/archive_video_resource'
19
- autoload :ArchiveTimelineEvent , 'open_tok/archive_timeline_event'
20
- autoload :OpenTokException , 'open_tok/exception'
21
- autoload :Request , 'open_tok/request'
22
- autoload :RoleConstants , 'open_tok/role_constants'
23
- autoload :Session , 'open_tok/session'
24
- autoload :SessionPropertyConstants, 'open_tok/session_property_constants'
25
- autoload :Utils , 'open_tok/utils'
26
-
27
- class OpenTokSDK
28
- attr_reader :api_url
29
-
30
- TOKEN_SENTINEL = "T1=="
31
-
32
- ##
33
- # Create a new OpenTok REST API client
34
- #
35
- # @param [String] API Key, developer identifier
36
- # @param [String] API Secret, developer identifier
37
- # @param [String] back_support @deprecated
38
- # @param [String] OpenTok endpoint, production by default
39
- def initialize(partner_id, partner_secret, back_support = '', api_url = OpenTok::API_URL)
40
- @partner_id = partner_id.to_s()
41
- @partner_secret = partner_secret
42
- @api_url = api_url
43
- end
44
-
45
- ##
46
- # Generate token for the given session_id
47
- #
48
- # @param [Hash] opts the options to create a token with.
49
- # @option opts [String] :session_id (mandatory) generate a token for the provided session
50
- # @option opts [String] :create_time (optional)
51
- # @option opts [String] :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.
52
- # @option opts [String] :role (optional) Added in OpenTok v0.91.5. This defines the role the user will have. There are three roles: subscriber, publisher, and moderator.
53
- # @option opts [String] :connection_data (optional) Added in OpenTok v0.91.20. A string containing metadata describing the connection.
54
- # See http://www.tokbox.com/opentok/tools/documentation/overview/token_creation.html for more information on all options.
55
- def generate_token(opts = {})
56
- create_time = opts.fetch(:create_time, Time.now)
57
- session_id = opts.fetch(:session_id, '').to_s
58
-
59
- # check validity of session_id
60
- if !session_id || session_id.to_s.length == ""
61
- raise "Null or empty session ID is not valid"
62
- end
63
-
64
- begin
65
- subSessionId = session_id[2..session_id.length]
66
- subSessionId = subSessionId.sub("-","+").sub("_","/")
67
- decodedSessionId = Base64.decode64(subSessionId).split("~")
68
- (0..4).each do |n|
69
- if decodedSessionId and decodedSessionId.length > 1
70
- break
71
- end
72
- subSessionId = subSessionId+"="
73
- end
74
- unless decodedSessionId[1] == @partner_id
75
- raise "An invalid session ID was passed"
76
- end
77
- rescue Exception => e
78
- raise "An invalid session ID was passed"
79
- end
80
-
81
-
82
- role = opts.fetch(:role, RoleConstants::PUBLISHER)
83
-
84
- RoleConstants.is_valid?(role) or raise OpenTokException.new "'#{role}' is not a recognized role"
85
-
86
- data_params = {
87
- :role => role,
88
- :session_id => session_id.is_a?(Session) ? session_id.session_id : session_id,
89
- :create_time => create_time.to_i,
90
- :nonce => rand
91
- }
92
-
93
- unless opts[:expire_time].nil?
94
- opts[:expire_time].is_a?(Numeric) or raise OpenTokException.new 'Expire time must be a number'
95
- opts[:expire_time] < Time.now.to_i and raise OpenTokException.new 'Expire time must be in the future'
96
- opts[:expire_time] > (Time.now.to_i + 2592000) and raise OpenTokException.new 'Expire time must be in the next 30 days'
97
- data_params[:expire_time] = opts[:expire_time].to_i
98
- end
99
-
100
- unless opts[:connection_data].nil?
101
- opts[:connection_data].length > 1000 and raise OpenTokException.new 'Connection data must be less than 1000 characters'
102
- data_params[:connection_data] = opts[:connection_data]
103
- end
104
-
105
- data_string = Utils.urlencode_hash(data_params)
106
-
107
- sig = sign_string data_string, @partner_secret
108
- meta_string = Utils.urlencode_hash(:partner_id => @partner_id, :sig => sig)
109
-
110
- TOKEN_SENTINEL + Base64.encode64(meta_string + ":" + data_string).gsub("\n", '')
111
- end
112
-
113
- alias_method :generateToken, :generate_token
114
-
115
- ##
116
- # Generates a new OpenTok::Session and set it's session_id,
117
- # situating it in TokBox's global network near the IP of the specified @location@.
118
- #
119
- # param: location
120
- # param: opts: valid
121
- #
122
- # See http://www.tokbox.com/opentok/tools/documentation/overview/session_creation.html for more information
123
- def create_session(location='', opts={})
124
- opts.merge!({:location => location})
125
- doc = do_request '/session/create', opts
126
-
127
- unless doc.get_elements('Errors').empty?
128
- raise OpenTokException.new doc.get_elements('Errors')[0].get_elements('error')[0].children.to_s
129
- end
130
- Session.new doc.root.get_elements('Session')[0].get_elements('session_id')[0].children[0].to_s
131
- end
132
-
133
- alias_method :createSession, :create_session
134
-
135
- ##
136
- # Download an OpenTok archive manifest.
137
- # The archive manifest contains video IDs for each recorded stream in the archive.
138
- #
139
- # @param [String] archive identifier
140
- # @param [String] token
141
- #
142
- # @return [OpenTok::Archive]
143
- def get_archive_manifest(archive_id, token)
144
- # TODO: verify that token is MODERATOR token
145
- doc = do_request "/archive/getmanifest/#{archive_id}", {}, token
146
- if doc.get_elements('Errors').empty?
147
- Archive.parse_manifest doc.get_elements('manifest')[0], @api_url, token
148
- else
149
- raise OpenTokException.new doc.get_elements('Errors')[0].get_elements('error')[0].children.to_s
150
- end
151
- end
152
-
153
- alias_method :getArchiveManifest, :get_archive_manifest
154
-
155
- def delete_archive(archive_id, token)
156
- doc = do_request "/archive/delete/#{archive_id}", {:test => 'none'}, token
157
- errors = doc.get_elements('Errors')
158
- if doc.get_elements('Errors').empty?
159
- true
160
- else
161
- raise OpenTokException.from_error doc
162
- end
163
- end
164
-
165
- alias_method :deleteArchive, :delete_archive
166
-
167
- def stitchArchive(archive_id)
168
- request = Request.new(@api_url, nil, @partner_id, @partner_secret)
169
- response = request.sendRequest("/archive/#{archive_id}/stitch", {:test => 'none'})
170
- case response.code
171
- when '201'
172
- return {:code=>201, :message=>"Successfully Created", :location=>response["location"]}
173
- when '202'
174
- return {:code=>202, :message=>"Processing"}
175
- when '403'
176
- return {:code=>403, :message=>"Invalid Credentials"}
177
- when '404'
178
- return {:code=>404, :message=>"Archive Does Not Exist"}
179
- else
180
- return {:code=>500, :message=>"Server Error"}
181
- end
182
- end
183
-
184
- alias_method :stitch, :stitchArchive
185
-
186
- protected
187
-
188
- def sign_string(data, secret)
189
- OpenSSL::HMAC.hexdigest(DIGEST, secret, data)
190
- end
191
-
192
- def do_request(path, params, token=nil)
193
- request = Request.new @api_url, token, @partner_id, @partner_secret
194
- body = request.fetch path, params
195
- REXML::Document.new body
196
- end
197
- end
198
- end
@@ -1,63 +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.nil? || 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
- req = set_headers(req)
28
-
29
- http = Net::HTTP.new(url.host, url.port)
30
- http.use_ssl = @api_host.start_with?("https")
31
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
32
-
33
- http.start {|h| h.request(req) }
34
- end
35
-
36
- def fetch(path, params={})
37
- res = sendRequest path, params
38
-
39
- case res
40
- when Net::HTTPSuccess, Net::HTTPRedirection
41
- return res.read_body
42
- else
43
- res.error!
44
- end
45
-
46
- rescue Net::HTTPExceptions => e
47
- raise OpenTokException.new "Unable to create fufill request: #{e}"
48
- rescue NoMethodError => e
49
- raise OpenTokException.new "Unable to create a fufill request at this time: #{e}"
50
- end
51
-
52
- private
53
-
54
- def set_headers(req)
55
- if @token
56
- req.add_field 'X-TB-TOKEN-AUTH', @token
57
- elsif @partner_id && @partner_secret
58
- req.add_field 'X-TB-PARTNER-AUTH', "#{@partner_id}:#{@partner_secret}"
59
- end
60
- req
61
- end
62
- end
63
- end
@@ -1,18 +0,0 @@
1
- module OpenTok
2
-
3
- # * +SUBSCRIBER+ Can only subscribe
4
- # * +PUBLISHER+ Can publish, subscribe, and signal
5
- # * +MODERATOR+ Can do the above along with forceDisconnect and forceUnpublish
6
- module RoleConstants
7
- SUBSCRIBER = "subscriber" # Can only subscribe
8
- PUBLISHER = "publisher" # Can publish, subscribe, and signal
9
- MODERATOR = "moderator" # Can do the above along with forceDisconnect and forceUnpublish
10
-
11
- class << self
12
- def is_valid?(role)
13
- role == SUBSCRIBER || role == PUBLISHER || role == MODERATOR
14
- end
15
- end
16
- end
17
-
18
- end
@@ -1,25 +0,0 @@
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
-
10
- ##
11
- # The session object that contains the session_id
12
- class Session
13
- attr_reader :session_id
14
- attr_reader :created_at
15
-
16
- def initialize(session_id, create_dt=nil)
17
- @session_id = session_id
18
- @created_at = create_dt
19
- end
20
-
21
- def to_s
22
- @session_id
23
- end
24
- end
25
- end