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
@@ -0,0 +1,1046 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Class: OpenTok::OpenTok
8
+
9
+ &mdash; Documentation by YARD 0.8.7.4
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '../';
20
+ framesUrl = "../frames.html#!OpenTok/OpenTok.html";
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="../_index.html">Index (O)</a> &raquo;
35
+ <span class='title'><span class='object_link'><a href="../OpenTok.html" title="OpenTok (module)">OpenTok</a></span></span>
36
+ &raquo;
37
+ <span class="title">OpenTok</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="../class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="../method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="../file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Class: OpenTok::OpenTok
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+ <dt class="r1">Inherits:</dt>
75
+ <dd class="r1">
76
+ <span class="inheritName">Object</span>
77
+
78
+ <ul class="fullTree">
79
+ <li>Object</li>
80
+
81
+ <li class="next">OpenTok::OpenTok</li>
82
+
83
+ </ul>
84
+ <a href="#" class="inheritanceTree">show all</a>
85
+
86
+ </dd>
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+ <dt class="r2 last">Defined in:</dt>
97
+ <dd class="r2 last">lib/opentok/opentok.rb</dd>
98
+
99
+ </dl>
100
+ <div class="clear"></div>
101
+
102
+ <h2>Overview</h2><div class="docstring">
103
+ <div class="discussion">
104
+
105
+ <p>Contains methods for creating OpenTok sessions, generating tokens, and
106
+ working with archives.</p>
107
+
108
+ <p>To create a new OpenTok object, call the OpenTok constructor with your
109
+ OpenTok API key and the API secret from the OpenTok dashboard (<a
110
+ href="https://dashboard.tokbox.com">dashboard.tokbox.com</a>). Do not
111
+ publicly share your API secret. You will use it with the OpenTok
112
+ constructor (only on your web server) to create OpenTok sessions.</p>
113
+
114
+
115
+ </div>
116
+ </div>
117
+ <div class="tags">
118
+
119
+
120
+ </div>
121
+ <h2>Constant Summary</h2>
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+ <h2>
132
+ Instance Method Summary
133
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
134
+ </h2>
135
+
136
+ <ul class="summary">
137
+
138
+ <li class="public ">
139
+ <span class="summary_signature">
140
+
141
+ <a href="#archives-instance_method" title="#archives (instance method)">- (Object) <strong>archives</strong> </a>
142
+
143
+
144
+
145
+ </span>
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+ <span class="summary_desc"><div class='inline'>
156
+ <p>An Archives object, which lets you work with OpenTok 2.0 archives.</p>
157
+ </div></span>
158
+
159
+ </li>
160
+
161
+
162
+ <li class="public ">
163
+ <span class="summary_signature">
164
+
165
+ <a href="#create_session-instance_method" title="#create_session (instance method)">- (Session) <strong>create_session</strong>(opts = {}) </a>
166
+
167
+
168
+
169
+ </span>
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+ <span class="summary_desc"><div class='inline'>
180
+ <p>Creates a new OpenTok session and returns the session ID, which uniquely
181
+ identifies the session.</p>
182
+ </div></span>
183
+
184
+ </li>
185
+
186
+
187
+ <li class="public ">
188
+ <span class="summary_signature">
189
+
190
+ <a href="#generate_token-instance_method" title="#generate_token (instance method)">- (String) <strong>generate_token</strong>(options) </a>
191
+
192
+
193
+
194
+ </span>
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+ <span class="summary_desc"><div class='inline'>
205
+ <p>Generates a token for a given session.</p>
206
+ </div></span>
207
+
208
+ </li>
209
+
210
+
211
+ <li class="public ">
212
+ <span class="summary_signature">
213
+
214
+ <a href="#initialize-instance_method" title="#initialize (instance method)">- (OpenTok) <strong>initialize</strong>(api_key, api_secret, api_url = ::OpenTok::API_URL) </a>
215
+
216
+
217
+
218
+ </span>
219
+
220
+
221
+ <span class="note title constructor">constructor</span>
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+ <span class="summary_desc"><div class='inline'>
231
+ <p>Create a new OpenTok object.</p>
232
+ </div></span>
233
+
234
+ </li>
235
+
236
+
237
+ </ul>
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+ <div id="constructor_details" class="method_details_list">
247
+ <h2>Constructor Details</h2>
248
+
249
+ <div class="method_details first">
250
+ <h3 class="signature first" id="initialize-instance_method">
251
+
252
+ - (<tt><span class='object_link'><a href="" title="OpenTok::OpenTok (class)">OpenTok</a></span></tt>) <strong>initialize</strong>(api_key, api_secret, api_url = ::OpenTok::API_URL)
253
+
254
+
255
+
256
+
257
+
258
+ </h3><div class="docstring">
259
+ <div class="discussion">
260
+
261
+ <p>Create a new OpenTok object.</p>
262
+
263
+
264
+ </div>
265
+ </div>
266
+ <div class="tags">
267
+ <p class="tag_title">Parameters:</p>
268
+ <ul class="param">
269
+
270
+ <li>
271
+
272
+ <span class='name'>api_key</span>
273
+
274
+
275
+ <span class='type'>(<tt>String</tt>)</span>
276
+
277
+
278
+
279
+ &mdash;
280
+ <div class='inline'>
281
+ <p>Your OpenTok API key. See the OpenTok dashboard (<a
282
+ href="https://dashboard.tokbox.com">dashboard.tokbox.com</a>).</p>
283
+ </div>
284
+
285
+ </li>
286
+
287
+ <li>
288
+
289
+ <span class='name'>api_secret</span>
290
+
291
+
292
+ <span class='type'>(<tt>String</tt>)</span>
293
+
294
+
295
+
296
+ &mdash;
297
+ <div class='inline'>
298
+ <p>Your OpenTok API key.</p>
299
+ </div>
300
+
301
+ </li>
302
+
303
+ <li>
304
+
305
+ <span class='name'>api_url</span>
306
+
307
+
308
+ <span class='type'>(<tt>String</tt>)</span>
309
+
310
+
311
+ <em class="default">(defaults to: <tt>::OpenTok::API_URL</tt>)</em>
312
+
313
+
314
+ &mdash;
315
+ <div class='inline'>
316
+ <p>Do not set this parameter. It is for internal use by TokBox.</p>
317
+ </div>
318
+
319
+ </li>
320
+
321
+ </ul>
322
+
323
+
324
+ </div><table class="source_code">
325
+ <tr>
326
+ <td>
327
+ <pre class="lines">
328
+
329
+
330
+ 67
331
+ 68
332
+ 69
333
+ 70
334
+ 71
335
+ 72
336
+ 73</pre>
337
+ </td>
338
+ <td>
339
+ <pre class="code"><span class="info file"># File 'lib/opentok/opentok.rb', line 67</span>
340
+
341
+ <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_api_secret'>api_secret</span> <span class='comma'>,</span> <span class='id identifier rubyid_api_url'>api_url</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>OpenTok</span><span class='op'>::</span><span class='const'>API_URL</span><span class='rparen'>)</span>
342
+ <span class='ivar'>@api_key</span> <span class='op'>=</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='rparen'>)</span>
343
+ <span class='ivar'>@api_secret</span> <span class='op'>=</span> <span class='id identifier rubyid_api_secret'>api_secret</span>
344
+ <span class='comment'># TODO: do we really need a copy of this in the instance or should we overwrite the module
345
+ </span> <span class='comment'># constant so that other objects can access the same copy?
346
+ </span> <span class='ivar'>@api_url</span> <span class='op'>=</span> <span class='id identifier rubyid_api_url'>api_url</span>
347
+ <span class='kw'>end</span></pre>
348
+ </td>
349
+ </tr>
350
+ </table>
351
+ </div>
352
+
353
+ </div>
354
+
355
+
356
+ <div id="instance_method_details" class="method_details_list">
357
+ <h2>Instance Method Details</h2>
358
+
359
+
360
+ <div class="method_details first">
361
+ <h3 class="signature first" id="archives-instance_method">
362
+
363
+ - (<tt>Object</tt>) <strong>archives</strong>
364
+
365
+
366
+
367
+
368
+
369
+ </h3><div class="docstring">
370
+ <div class="discussion">
371
+
372
+ <p>An Archives object, which lets you work with OpenTok 2.0 archives.</p>
373
+
374
+
375
+ </div>
376
+ </div>
377
+ <div class="tags">
378
+
379
+
380
+ </div><table class="source_code">
381
+ <tr>
382
+ <td>
383
+ <pre class="lines">
384
+
385
+
386
+ 163
387
+ 164
388
+ 165</pre>
389
+ </td>
390
+ <td>
391
+ <pre class="code"><span class="info file"># File 'lib/opentok/opentok.rb', line 163</span>
392
+
393
+ <span class='kw'>def</span> <span class='id identifier rubyid_archives'>archives</span>
394
+ <span class='ivar'>@archives</span> <span class='op'>||=</span> <span class='const'>Archives</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_client'>client</span>
395
+ <span class='kw'>end</span></pre>
396
+ </td>
397
+ </tr>
398
+ </table>
399
+ </div>
400
+
401
+ <div class="method_details ">
402
+ <h3 class="signature " id="create_session-instance_method">
403
+
404
+ - (<tt><span class='object_link'><a href="Session.html" title="OpenTok::Session (class)">Session</a></span></tt>) <strong>create_session</strong>(opts = {})
405
+
406
+
407
+
408
+
409
+
410
+ </h3><div class="docstring">
411
+ <div class="discussion">
412
+
413
+ <p>Creates a new OpenTok session and returns the session ID, which uniquely
414
+ identifies the session.</p>
415
+
416
+ <p>For example, when using the OpenTok JavaScript library, use the session ID
417
+ when calling the OT.initSession()&lt;/a&gt; method (to initialize an
418
+ OpenTok session).</p>
419
+
420
+ <p>OpenTok sessions do not expire. However, authentication tokens do expire
421
+ (see the generateToken() method). Also note that sessions cannot explicitly
422
+ be destroyed.</p>
423
+
424
+ <p>A session ID string can be up to 255 characters long.</p>
425
+
426
+ <p>Calling this method results in an OpenTokException in the event of an
427
+ error. Check the error message for details.</p>
428
+
429
+ <p>You can also create a session using the OpenTok REST API (see <a
430
+ href="http://www.tokbox.com/opentok/api/#session_id_production">www.tokbox.com/opentok/api/#session_id_production</a>)
431
+ or the OpenTok dashboard (see <a
432
+ href="https://dashboard.tokbox.com/projects">dashboard.tokbox.com/projects</a>).</p>
433
+
434
+
435
+ </div>
436
+ </div>
437
+ <div class="tags">
438
+ <p class="tag_title">Parameters:</p>
439
+ <ul class="param">
440
+
441
+ <li>
442
+
443
+ <span class='name'>opts</span>
444
+
445
+
446
+ <span class='type'>(<tt>Hash</tt>)</span>
447
+
448
+
449
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
450
+
451
+
452
+ &mdash;
453
+ <div class='inline'>
454
+ <p>(Optional) This hash defines options for the session.</p>
455
+ </div>
456
+
457
+ </li>
458
+
459
+ </ul>
460
+
461
+
462
+
463
+
464
+ <p class="tag_title">Options Hash (<tt>opts</tt>):</p>
465
+ <ul class="option">
466
+
467
+ <li>
468
+ <span class="name">:media_mode</span>
469
+ <span class="type">(<tt>String</tt>)</span>
470
+ <span class="default">
471
+
472
+ </span>
473
+
474
+ &mdash; <div class='inline'>
475
+ <p>Determines whether the session will transmit streams the using OpenTok
476
+ Media Router (<tt>:routed</tt>) or not (<tt>:relayed</tt>). By default,
477
+ sessions use the OpenTok Media Router.</p>
478
+
479
+ <p>With the <tt>mediaMode</tt> property set to <tt>:routed</tt>, the session
480
+ will use the <a href="http://tokbox.com/#multiparty" target="_parent" title="OpenTok Media Router">OpenTok Media Router</a>. The
481
+ OpenTok Media Router provides the following benefits:</p>
482
+ <ul><li>
483
+ <p>The OpenTok Media Router can decrease bandwidth usage in multiparty
484
+ sessions. (When the <tt>mediaMode</tt> property is set to
485
+ <tt>:relayed</tt>, each client must send a separate audio-video stream to
486
+ each client subscribing to it.)</p>
487
+ </li><li>
488
+ <p>The OpenTok Media Router can improve the quality of the user experience
489
+ through <a href="http://tokbox.com/#iqc" target="_parent" title="Intelligent Quality Control">Intelligent Quality Control</a>. With
490
+ Intelligent Quality Control, if a client’s connectivity degrades to a
491
+ degree that it does not support video for a stream it’s subscribing to, the
492
+ video is dropped on that client (without affecting other clients), and the
493
+ client receives audio only. If the client’s connectivity improves, the
494
+ video returns.</p>
495
+ </li><li>
496
+ <p>The OpenTok Media Router supports the <a href="http://tokbox.com/platform/archiving" target="_parent" title="archiving">archiving</a> feature, which lets you record, save, and retrieve OpenTok
497
+ sessions.</p>
498
+ </li></ul>
499
+
500
+ <p>With the <tt>mediaMode</tt> property set to <tt>:relayed</tt>, the session
501
+ will attempt to transmit streams directly between clients. If clients
502
+ cannot connect due to firewall restrictions, the session uses the OpenTok
503
+ TURN server to relay audio-video streams.</p>
504
+
505
+ <p>You will be billed for streamed minutes if you use the OpenTok Media Router
506
+ or if the session uses the OpenTok TURN server to relay streams. For
507
+ information on pricing, see the <a href="http://www.tokbox.com/pricing" target="_parent" title="OpenTok pricing page">OpenTok pricing page</a>.</p>
508
+ </div>
509
+
510
+ </li>
511
+
512
+ <li>
513
+ <span class="name">:location</span>
514
+ <span class="type">(<tt>String</tt>)</span>
515
+ <span class="default">
516
+
517
+ </span>
518
+
519
+ &mdash; <div class='inline'>
520
+ <p>An IP address that the OpenTok servers will use to situate the session in
521
+ its global network. If you do not set a location hint, the OpenTok servers
522
+ will be based on the first client connecting to the session.</p>
523
+ </div>
524
+
525
+ </li>
526
+
527
+ </ul>
528
+
529
+
530
+ <p class="tag_title">Returns:</p>
531
+ <ul class="return">
532
+
533
+ <li>
534
+
535
+
536
+ <span class='type'>(<tt><span class='object_link'><a href="Session.html" title="OpenTok::Session (class)">Session</a></span></tt>)</span>
537
+
538
+
539
+
540
+ &mdash;
541
+ <div class='inline'>
542
+ <p>The Session object. The session_id property of the object is the session
543
+ ID.</p>
544
+ </div>
545
+
546
+ </li>
547
+
548
+ </ul>
549
+
550
+ </div><table class="source_code">
551
+ <tr>
552
+ <td>
553
+ <pre class="lines">
554
+
555
+
556
+ 130
557
+ 131
558
+ 132
559
+ 133
560
+ 134
561
+ 135
562
+ 136
563
+ 137
564
+ 138
565
+ 139
566
+ 140
567
+ 141
568
+ 142
569
+ 143
570
+ 144
571
+ 145
572
+ 146
573
+ 147
574
+ 148
575
+ 149
576
+ 150
577
+ 151
578
+ 152
579
+ 153
580
+ 154
581
+ 155
582
+ 156
583
+ 157
584
+ 158
585
+ 159
586
+ 160</pre>
587
+ </td>
588
+ <td>
589
+ <pre class="code"><span class="info file"># File 'lib/opentok/opentok.rb', line 130</span>
590
+
591
+ <span class='kw'>def</span> <span class='id identifier rubyid_create_session'>create_session</span><span class='lparen'>(</span><span class='id identifier rubyid_opts'>opts</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
592
+
593
+ <span class='comment'># normalize opts so all keys are symbols and only include valid_opts
594
+ </span> <span class='id identifier rubyid_valid_opts'>valid_opts</span> <span class='op'>=</span> <span class='lbracket'>[</span> <span class='symbol'>:media_mode</span><span class='comma'>,</span> <span class='symbol'>:location</span> <span class='rbracket'>]</span>
595
+ <span class='id identifier rubyid_opts'>opts</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_inject'>inject</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='comma'>,</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span><span class='op'>|</span>
596
+ <span class='kw'>if</span> <span class='id identifier rubyid_valid_opts'>valid_opts</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span> <span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
597
+ <span class='id identifier rubyid_m'>m</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_v'>v</span>
598
+ <span class='kw'>end</span>
599
+ <span class='id identifier rubyid_m'>m</span>
600
+ <span class='kw'>end</span>
601
+
602
+ <span class='comment'># keep opts around for Session constructor, build REST params
603
+ </span> <span class='id identifier rubyid_params'>params</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_clone'>clone</span>
604
+
605
+ <span class='comment'># anything other than :relayed sets the REST param to &quot;disabled&quot;, in which case we force
606
+ </span> <span class='comment'># opts to be :routed. if we were more strict we could raise an error when the value isn't
607
+ </span> <span class='comment'># either :relayed or :routed
608
+ </span> <span class='kw'>if</span> <span class='id identifier rubyid_params'>params</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:media_mode</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='symbol'>:relayed</span>
609
+ <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>p2p.preference</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>enabled</span><span class='tstring_end'>&quot;</span></span>
610
+ <span class='kw'>else</span>
611
+ <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>p2p.preference</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>disabled</span><span class='tstring_end'>&quot;</span></span>
612
+ <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:media_mode</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='symbol'>:routed</span>
613
+ <span class='kw'>end</span>
614
+ <span class='comment'># location is optional, but it has to be an IP address if specified at all
615
+ </span> <span class='kw'>unless</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:location</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
616
+ <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>location must be an IPv4 address</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:location</span><span class='rbracket'>]</span> <span class='op'>=~</span> <span class='const'>Resolv</span><span class='op'>::</span><span class='const'>IPv4</span><span class='op'>::</span><span class='const'>Regex</span>
617
+ <span class='kw'>end</span>
618
+
619
+ <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_create_session'>create_session</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='rparen'>)</span>
620
+ <span class='const'>Session</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_api_secret'>api_secret</span><span class='comma'>,</span> <span class='id identifier rubyid_response'>response</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sessions</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Session</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>session_id</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span>
621
+ <span class='kw'>end</span></pre>
622
+ </td>
623
+ </tr>
624
+ </table>
625
+ </div>
626
+
627
+ <div class="method_details ">
628
+ <h3 class="signature " id="generate_token-instance_method">
629
+
630
+ - (<tt>String</tt>) <strong>generate_token</strong>(options)
631
+
632
+
633
+
634
+
635
+
636
+ </h3><div class="docstring">
637
+ <div class="discussion">
638
+
639
+ <p>Generates a token for a given session.</p>
640
+
641
+
642
+ </div>
643
+ </div>
644
+ <div class="tags">
645
+ <p class="tag_title">Parameters:</p>
646
+ <ul class="param">
647
+
648
+ <li>
649
+
650
+ <span class='name'>sessioin_id</span>
651
+
652
+
653
+ <span class='type'>(<tt>String</tt>)</span>
654
+
655
+
656
+
657
+ &mdash;
658
+ <div class='inline'>
659
+ <p>The session ID of the session to be accessed by the client using the token.</p>
660
+ </div>
661
+
662
+ </li>
663
+
664
+ <li>
665
+
666
+ <span class='name'>options</span>
667
+
668
+
669
+ <span class='type'>(<tt>Hash</tt>)</span>
670
+
671
+
672
+
673
+ &mdash;
674
+ <div class='inline'>
675
+ <p>A hash defining options for the token.</p>
676
+ </div>
677
+
678
+ </li>
679
+
680
+ </ul>
681
+
682
+
683
+
684
+
685
+ <p class="tag_title">Options Hash (<tt>options</tt>):</p>
686
+ <ul class="option">
687
+
688
+ <li>
689
+ <span class="name">:role</span>
690
+ <span class="type">(<tt>String</tt>)</span>
691
+ <span class="default">
692
+
693
+ </span>
694
+
695
+ &mdash; <div class='inline'>
696
+ <p>The role for the token. Set this to one of the following values:</p>
697
+ <ul><li>
698
+ <p><tt>:subscriber</tt> -- A subscriber can only subscribe to streams.</p>
699
+ </li><li>
700
+ <p><tt>:publisher</tt> -- A publisher can publish streams, subscribe to
701
+ streams, and signal. (This is the default value if you do not specify a
702
+ role.)</p>
703
+ </li><li>
704
+ <p><tt>:moderator</tt> -- In addition to the privileges granted to a
705
+ publisher, in clients using the OpenTok.js 2.2 library, a moderator can
706
+ call the <tt>forceUnpublish()</tt> and <tt>forceDisconnect()</tt> method of
707
+ the Session object.</p>
708
+ </li></ul>
709
+ </div>
710
+
711
+ </li>
712
+
713
+ <li>
714
+ <span class="name">:expire_time</span>
715
+ <span class="type">(<tt>integer</tt>)</span>
716
+ <span class="default">
717
+
718
+ </span>
719
+
720
+ &mdash; <div class='inline'>
721
+ <p>The expiration time, in seconds since the UNIX epoch. Pass in 0 to use the
722
+ default expiration time of 24 hours after the token creation time. The
723
+ maximum expiration time is 30 days after the creation time.</p>
724
+ </div>
725
+
726
+ </li>
727
+
728
+ <li>
729
+ <span class="name">:data</span>
730
+ <span class="type">(<tt>String</tt>)</span>
731
+ <span class="default">
732
+
733
+ </span>
734
+
735
+ &mdash; <div class='inline'>
736
+ <p>A string containing connection metadata describing the end-user. For
737
+ example, you can pass the user ID, name, or other data describing the
738
+ end-user. The length of the string is limited to 1000 characters. This data
739
+ cannot be updated once it is set.</p>
740
+ </div>
741
+
742
+ </li>
743
+
744
+ </ul>
745
+
746
+
747
+ <p class="tag_title">Returns:</p>
748
+ <ul class="return">
749
+
750
+ <li>
751
+
752
+
753
+ <span class='type'>(<tt>String</tt>)</span>
754
+
755
+
756
+
757
+ &mdash;
758
+ <div class='inline'>
759
+ <p>The token string.</p>
760
+ </div>
761
+
762
+ </li>
763
+
764
+ </ul>
765
+
766
+ </div><table class="source_code">
767
+ <tr>
768
+ <td>
769
+ <pre class="lines">
770
+
771
+
772
+ 47
773
+ 48
774
+ 49
775
+ 50
776
+ 51
777
+ 52
778
+ 53
779
+ 54
780
+ 55
781
+ 56
782
+ 57
783
+ 58
784
+ 59
785
+ 60
786
+ 61
787
+ 62
788
+ 63
789
+ 64
790
+ 65
791
+ 66
792
+ 67
793
+ 68
794
+ 69
795
+ 70
796
+ 71
797
+ 72
798
+ 73
799
+ 74
800
+ 75
801
+ 76
802
+ 77
803
+ 78
804
+ 79
805
+ 80
806
+ 81
807
+ 82
808
+ 83
809
+ 84
810
+ 85
811
+ 86
812
+ 87
813
+ 88
814
+ 89
815
+ 90
816
+ 91
817
+ 92
818
+ 93
819
+ 94
820
+ 95
821
+ 96
822
+ 97
823
+ 98
824
+ 99
825
+ 100
826
+ 101
827
+ 102
828
+ 103
829
+ 104
830
+ 105
831
+ 106
832
+ 107
833
+ 108
834
+ 109
835
+ 110
836
+ 111
837
+ 112
838
+ 113
839
+ 114
840
+ 115
841
+ 116
842
+ 117
843
+ 118
844
+ 119
845
+ 120
846
+ 121
847
+ 122
848
+ 123
849
+ 124
850
+ 125
851
+ 126
852
+ 127
853
+ 128
854
+ 129
855
+ 130
856
+ 131
857
+ 132
858
+ 133
859
+ 134
860
+ 135
861
+ 136
862
+ 137
863
+ 138
864
+ 139
865
+ 140
866
+ 141
867
+ 142
868
+ 143
869
+ 144
870
+ 145
871
+ 146
872
+ 147
873
+ 148
874
+ 149
875
+ 150
876
+ 151
877
+ 152
878
+ 153
879
+ 154
880
+ 155
881
+ 156
882
+ 157
883
+ 158
884
+ 159
885
+ 160
886
+ 161
887
+ 162
888
+ 163
889
+ 164
890
+ 165
891
+ 166
892
+ 167
893
+ 168
894
+ 169
895
+ 170
896
+ 171
897
+ 172
898
+ 173</pre>
899
+ </td>
900
+ <td>
901
+ <pre class="code"><span class="info file"># File 'lib/opentok/opentok.rb', line 47</span>
902
+
903
+ <span class='kw'>class</span> <span class='const'>OpenTok</span>
904
+
905
+ <span class='id identifier rubyid_include'>include</span> <span class='const'>TokenGenerator</span>
906
+ <span class='id identifier rubyid_generates_tokens'>generates_tokens</span><span class='lparen'>(</span><span class='lbrace'>{</span>
907
+ <span class='symbol'>:api_key</span> <span class='op'>=&gt;</span> <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_instance'>instance</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_api_key'>api_key</span> <span class='rbrace'>}</span><span class='comma'>,</span>
908
+ <span class='symbol'>:api_secret</span> <span class='op'>=&gt;</span> <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_instance'>instance</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_api_secret'>api_secret</span> <span class='rbrace'>}</span>
909
+ <span class='rbrace'>}</span><span class='rparen'>)</span>
910
+
911
+ <span class='comment'># @private
912
+ </span> <span class='comment'># don't want these to be mutable, may cause bugs related to inconsistency since these values are
913
+ </span> <span class='comment'># cached in objects that this can create
914
+ </span> <span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:api_key</span><span class='comma'>,</span> <span class='symbol'>:api_secret</span><span class='comma'>,</span> <span class='symbol'>:api_url</span>
915
+
916
+ <span class='comment'>##
917
+ </span> <span class='comment'># Create a new OpenTok object.
918
+ </span> <span class='comment'>#
919
+ </span> <span class='comment'># @param [String] api_key Your OpenTok API key. See the OpenTok dashboard
920
+ </span> <span class='comment'># (https://dashboard.tokbox.com).
921
+ </span> <span class='comment'># @param [String] api_secret Your OpenTok API key.
922
+ </span> <span class='comment'># @param [String] api_url Do not set this parameter. It is for internal use by TokBox.
923
+ </span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_api_secret'>api_secret</span> <span class='comma'>,</span> <span class='id identifier rubyid_api_url'>api_url</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>OpenTok</span><span class='op'>::</span><span class='const'>API_URL</span><span class='rparen'>)</span>
924
+ <span class='ivar'>@api_key</span> <span class='op'>=</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='rparen'>)</span>
925
+ <span class='ivar'>@api_secret</span> <span class='op'>=</span> <span class='id identifier rubyid_api_secret'>api_secret</span>
926
+ <span class='comment'># TODO: do we really need a copy of this in the instance or should we overwrite the module
927
+ </span> <span class='comment'># constant so that other objects can access the same copy?
928
+ </span> <span class='ivar'>@api_url</span> <span class='op'>=</span> <span class='id identifier rubyid_api_url'>api_url</span>
929
+ <span class='kw'>end</span>
930
+
931
+ <span class='comment'># Creates a new OpenTok session and returns the session ID, which uniquely identifies
932
+ </span> <span class='comment'># the session.
933
+ </span> <span class='comment'>#
934
+ </span> <span class='comment'># For example, when using the OpenTok JavaScript library, use the session ID when calling the
935
+ </span> <span class='comment'># OT.initSession()&lt;/a&gt; method (to initialize an OpenTok session).
936
+ </span> <span class='comment'>#
937
+ </span> <span class='comment'># OpenTok sessions do not expire. However, authentication tokens do expire (see the
938
+ </span> <span class='comment'># generateToken() method). Also note that sessions cannot explicitly be destroyed.
939
+ </span> <span class='comment'>#
940
+ </span> <span class='comment'># A session ID string can be up to 255 characters long.
941
+ </span> <span class='comment'>#
942
+ </span> <span class='comment'># Calling this method results in an OpenTokException in the event of an error.
943
+ </span> <span class='comment'># Check the error message for details.
944
+ </span> <span class='comment'>#
945
+ </span> <span class='comment'># You can also create a session using the OpenTok REST API (see
946
+ </span> <span class='comment'># http://www.tokbox.com/opentok/api/#session_id_production) or the OpenTok dashboard
947
+ </span> <span class='comment'># (see https://dashboard.tokbox.com/projects).
948
+ </span> <span class='comment'>#
949
+ </span> <span class='comment'># @param [Hash] opts (Optional) This hash defines options for the session.
950
+ </span> <span class='comment'>#
951
+ </span> <span class='comment'># @option opts [String] :media_mode Determines whether the session will transmit streams the
952
+ </span> <span class='comment'># using OpenTok Media Router (&lt;code&gt;:routed&lt;/code&gt;) or not (&lt;code&gt;:relayed&lt;/code&gt;).
953
+ </span> <span class='comment'># By default, sessions use the OpenTok Media Router.
954
+ </span> <span class='comment'>#
955
+ </span> <span class='comment'># With the &lt;code&gt;mediaMode&lt;/code&gt; property set to &lt;code&gt;:routed&lt;/code&gt;, the session
956
+ </span> <span class='comment'># will use the {http://tokbox.com/#multiparty OpenTok Media Router}.
957
+ </span> <span class='comment'># The OpenTok Media Router provides the following benefits:
958
+ </span> <span class='comment'>#
959
+ </span> <span class='comment'># * The OpenTok Media Router can decrease bandwidth usage in multiparty sessions.
960
+ </span> <span class='comment'># (When the &lt;code&gt;mediaMode&lt;/code&gt; property is set to &lt;code&gt;:relayed&lt;/code&gt;,
961
+ </span> <span class='comment'># each client must send a separate audio-video stream to each client subscribing to
962
+ </span> <span class='comment'># it.)
963
+ </span> <span class='comment'># * The OpenTok Media Router can improve the quality of the user experience through
964
+ </span> <span class='comment'># {http://tokbox.com/#iqc Intelligent Quality Control}. With
965
+ </span> <span class='comment'># Intelligent Quality Control, if a client's connectivity degrades to a degree that
966
+ </span> <span class='comment'># it does not support video for a stream it's subscribing to, the video is dropped on
967
+ </span> <span class='comment'># that client (without affecting other clients), and the client receives audio only.
968
+ </span> <span class='comment'># If the client's connectivity improves, the video returns.
969
+ </span> <span class='comment'># * The OpenTok Media Router supports the {http://tokbox.com/platform/archiving archiving}
970
+ </span> <span class='comment'># feature, which lets you record, save, and retrieve OpenTok sessions.
971
+ </span> <span class='comment'>#
972
+ </span> <span class='comment'># With the &lt;code&gt;mediaMode&lt;/code&gt; property set to &lt;code&gt;:relayed&lt;/code&gt;, the session
973
+ </span> <span class='comment'># will attempt to transmit streams directly between clients. If clients cannot connect due to
974
+ </span> <span class='comment'># firewall restrictions, the session uses the OpenTok TURN server to relay audio-video
975
+ </span> <span class='comment'># streams.
976
+ </span> <span class='comment'>#
977
+ </span> <span class='comment'># You will be billed for streamed minutes if you use the OpenTok Media Router or if the
978
+ </span> <span class='comment'># session uses the OpenTok TURN server to relay streams. For information on pricing, see the
979
+ </span> <span class='comment'># {http://www.tokbox.com/pricing OpenTok pricing page}.
980
+ </span> <span class='comment'>#
981
+ </span> <span class='comment'># @option opts [String] :location An IP address that the OpenTok servers will use to
982
+ </span> <span class='comment'># situate the session in its global network. If you do not set a location hint,
983
+ </span> <span class='comment'># the OpenTok servers will be based on the first client connecting to the session.
984
+ </span> <span class='comment'>#
985
+ </span> <span class='comment'># @return [Session] The Session object. The session_id property of the object is the session ID.
986
+ </span> <span class='kw'>def</span> <span class='id identifier rubyid_create_session'>create_session</span><span class='lparen'>(</span><span class='id identifier rubyid_opts'>opts</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
987
+
988
+ <span class='comment'># normalize opts so all keys are symbols and only include valid_opts
989
+ </span> <span class='id identifier rubyid_valid_opts'>valid_opts</span> <span class='op'>=</span> <span class='lbracket'>[</span> <span class='symbol'>:media_mode</span><span class='comma'>,</span> <span class='symbol'>:location</span> <span class='rbracket'>]</span>
990
+ <span class='id identifier rubyid_opts'>opts</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_inject'>inject</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='comma'>,</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span><span class='op'>|</span>
991
+ <span class='kw'>if</span> <span class='id identifier rubyid_valid_opts'>valid_opts</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span> <span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
992
+ <span class='id identifier rubyid_m'>m</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_v'>v</span>
993
+ <span class='kw'>end</span>
994
+ <span class='id identifier rubyid_m'>m</span>
995
+ <span class='kw'>end</span>
996
+
997
+ <span class='comment'># keep opts around for Session constructor, build REST params
998
+ </span> <span class='id identifier rubyid_params'>params</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='period'>.</span><span class='id identifier rubyid_clone'>clone</span>
999
+
1000
+ <span class='comment'># anything other than :relayed sets the REST param to &quot;disabled&quot;, in which case we force
1001
+ </span> <span class='comment'># opts to be :routed. if we were more strict we could raise an error when the value isn't
1002
+ </span> <span class='comment'># either :relayed or :routed
1003
+ </span> <span class='kw'>if</span> <span class='id identifier rubyid_params'>params</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:media_mode</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='symbol'>:relayed</span>
1004
+ <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>p2p.preference</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>enabled</span><span class='tstring_end'>&quot;</span></span>
1005
+ <span class='kw'>else</span>
1006
+ <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>p2p.preference</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>disabled</span><span class='tstring_end'>&quot;</span></span>
1007
+ <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:media_mode</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='symbol'>:routed</span>
1008
+ <span class='kw'>end</span>
1009
+ <span class='comment'># location is optional, but it has to be an IP address if specified at all
1010
+ </span> <span class='kw'>unless</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:location</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
1011
+ <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>location must be an IPv4 address</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:location</span><span class='rbracket'>]</span> <span class='op'>=~</span> <span class='const'>Resolv</span><span class='op'>::</span><span class='const'>IPv4</span><span class='op'>::</span><span class='const'>Regex</span>
1012
+ <span class='kw'>end</span>
1013
+
1014
+ <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_create_session'>create_session</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='rparen'>)</span>
1015
+ <span class='const'>Session</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_api_secret'>api_secret</span><span class='comma'>,</span> <span class='id identifier rubyid_response'>response</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sessions</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Session</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>session_id</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span>
1016
+ <span class='kw'>end</span>
1017
+
1018
+ <span class='comment'># An Archives object, which lets you work with OpenTok 2.0 archives.
1019
+ </span> <span class='kw'>def</span> <span class='id identifier rubyid_archives'>archives</span>
1020
+ <span class='ivar'>@archives</span> <span class='op'>||=</span> <span class='const'>Archives</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_client'>client</span>
1021
+ <span class='kw'>end</span>
1022
+
1023
+ <span class='id identifier rubyid_protected'>protected</span>
1024
+
1025
+ <span class='kw'>def</span> <span class='id identifier rubyid_client'>client</span>
1026
+ <span class='ivar'>@client</span> <span class='op'>||=</span> <span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_api_secret'>api_secret</span><span class='comma'>,</span> <span class='id identifier rubyid_api_url'>api_url</span>
1027
+ <span class='kw'>end</span>
1028
+
1029
+ <span class='kw'>end</span></pre>
1030
+ </td>
1031
+ </tr>
1032
+ </table>
1033
+ </div>
1034
+
1035
+ </div>
1036
+
1037
+ </div>
1038
+
1039
+ <div id="footer">
1040
+ Generated on Tue May 27 13:24:51 2014 by
1041
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1042
+ 0.8.7.4 (ruby-1.9.3).
1043
+ </div>
1044
+
1045
+ </body>
1046
+ </html>