opentok 0.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,91 @@
1
+ require "opentok/archives"
2
+ require "opentok/opentok"
3
+ require "opentok/version"
4
+ require "opentok/archive"
5
+ require "opentok/archive_list"
6
+
7
+ require "spec_helper"
8
+
9
+ describe OpenTok::Archives do
10
+
11
+ let(:api_key) { "123456" }
12
+ let(:api_secret) { "1234567890abcdef1234567890abcdef1234567890" }
13
+ let(:session_id) { "SESSIONID" }
14
+ let(:archive_name) { "ARCHIVE NAME" }
15
+ let(:started_archive_id) { "30b3ebf1-ba36-4f5b-8def-6f70d9986fe9" }
16
+ let(:findable_archive_id) { "f6e7ee58-d6cf-4a59-896b-6d56b158ec71" }
17
+ let(:deletable_archive_id) { "832641bf-5dbf-41a1-ad94-fea213e59a92" }
18
+
19
+ let(:opentok) { OpenTok::OpenTok.new api_key, api_secret }
20
+ let(:archives) { opentok.archives }
21
+ subject { archives }
22
+
23
+ it { should be_an_instance_of OpenTok::Archives }
24
+
25
+ it "should create archives", :vcr => { :erb => { :version => OpenTok::VERSION } } do
26
+ archive = archives.create session_id
27
+ expect(archive).to be_an_instance_of OpenTok::Archive
28
+ expect(archive.session_id).to eq session_id
29
+ expect(archive.id).not_to be_nil
30
+ end
31
+
32
+ it "should create named archives", :vcr => { :erb => { :version => OpenTok::VERSION } } do
33
+ archive = archives.create session_id, :name => archive_name
34
+ expect(archive).to be_an_instance_of OpenTok::Archive
35
+ expect(archive.session_id).to eq session_id
36
+ expect(archive.name).to eq archive_name
37
+ end
38
+
39
+
40
+ it "should stop archives", :vcr => { :erb => { :version => OpenTok::VERSION } } do
41
+ archive = archives.stop_by_id started_archive_id
42
+ expect(archive).to be_an_instance_of OpenTok::Archive
43
+ expect(archive.status).to eq "stopped"
44
+ end
45
+
46
+ it "should find archives by id", :vcr => { :erb => { :version => OpenTok::VERSION } } do
47
+ archive = archives.find findable_archive_id
48
+ expect(archive).to be_an_instance_of OpenTok::Archive
49
+ expect(archive.id).to eq findable_archive_id
50
+ end
51
+
52
+ it "should delete an archive by id", :vcr => { :erb => { :version => OpenTok::VERSION } } do
53
+ success = archives.delete_by_id deletable_archive_id
54
+ expect(success).to be_true
55
+ # expect(archive.status).to eq ""
56
+ end
57
+
58
+ # TODO: context "with a session that has no participants" do
59
+ # let(:session_id) { "" }
60
+ # it "should refuse to create archives with appropriate error" do
61
+ # expect { archives.create session_id }.to raise_error
62
+ # end
63
+ # end
64
+
65
+ context "when many archives are created" do
66
+ it "should return all archives", :vcr => { :erb => { :version => OpenTok::VERSION } } do
67
+ archive_list = archives.all
68
+ expect(archive_list).to be_an_instance_of OpenTok::ArchiveList
69
+ expect(archive_list.total).to eq 6
70
+ end
71
+
72
+ it "should return archives with an offset", :vcr => { :erb => { :version => OpenTok::VERSION } } do
73
+ archive_list = archives.all :offset => 3
74
+ expect(archive_list).to be_an_instance_of OpenTok::ArchiveList
75
+ expect(archive_list.count).to eq 3
76
+ end
77
+
78
+ it "should return count number of archives", :vcr => { :erb => { :version => OpenTok::VERSION } } do
79
+ archive_list = archives.all :count => 2
80
+ expect(archive_list).to be_an_instance_of OpenTok::ArchiveList
81
+ expect(archive_list.count).to eq 2
82
+ end
83
+
84
+ it "should return part of the archives when using offset and count", :vcr => { :erb => { :version => OpenTok::VERSION } } do
85
+ archive_list = archives.all :count => 4, :offset => 2
86
+ expect(archive_list).to be_an_instance_of OpenTok::ArchiveList
87
+ expect(archive_list.count).to eq 4
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,144 @@
1
+ require "opentok/opentok"
2
+ require "opentok/version"
3
+
4
+ require "spec_helper"
5
+ require "shared/opentok_generates_tokens"
6
+
7
+ describe OpenTok::OpenTok do
8
+
9
+ let(:opentok) { OpenTok::OpenTok.new api_key, api_secret }
10
+ subject { opentok }
11
+
12
+ context "when initialized properly" do
13
+
14
+ let(:api_key) { "123456" }
15
+ let(:api_secret) { "1234567890abcdef1234567890abcdef1234567890" }
16
+
17
+ let(:default_api_url) { "https://api.opentok.com" }
18
+
19
+ it { should be_an_instance_of OpenTok::OpenTok }
20
+
21
+ it "should have an api_key property" do
22
+ expect(opentok.api_key).to eq api_key
23
+ end
24
+
25
+ it "has the default api_url set" do
26
+ expect(opentok.api_url).to eq default_api_url
27
+ end
28
+
29
+ include_examples "opentok generates tokens"
30
+
31
+ describe "#create_session" do
32
+
33
+ let(:location) { '12.34.56.78' }
34
+
35
+ it "creates default sessions", :vcr => { :erb => { :version => OpenTok::VERSION } } do
36
+ session = opentok.create_session
37
+ expect(session).to be_an_instance_of OpenTok::Session
38
+ # TODO: do we need to be any more specific about what a valid session_id looks like?
39
+ expect(session.session_id).to be_an_instance_of String
40
+ expect(session.media_mode).to eq :routed
41
+ expect(session.location).to eq nil
42
+ end
43
+
44
+ it "creates relayed media sessions", :vcr => { :erb => { :version => OpenTok::VERSION } } do
45
+ session = opentok.create_session :media_mode => :relayed
46
+ expect(session).to be_an_instance_of OpenTok::Session
47
+ expect(session.session_id).to be_an_instance_of String
48
+ expect(session.media_mode).to eq :relayed
49
+ expect(session.location).to eq nil
50
+ end
51
+
52
+ it "creates routed media sessions", :vcr => { :erb => { :version => OpenTok::VERSION } } do
53
+ session = opentok.create_session :media_mode => :routed
54
+ expect(session).to be_an_instance_of OpenTok::Session
55
+ expect(session.session_id).to be_an_instance_of String
56
+ expect(session.media_mode).to eq :routed
57
+ expect(session.location).to eq nil
58
+ end
59
+
60
+ it "creates sessions with a location hint", :vcr => { :erb => { :version => OpenTok::VERSION } } do
61
+ session = opentok.create_session :location => location
62
+ expect(session).to be_an_instance_of OpenTok::Session
63
+ expect(session.session_id).to be_an_instance_of String
64
+ expect(session.media_mode).to eq :routed
65
+ expect(session.location).to eq location
66
+ end
67
+
68
+ it "creates relayed media sessions with a location hint", :vcr => { :erb => { :version => OpenTok::VERSION } } do
69
+ session = opentok.create_session :media_mode => :relayed, :location => location
70
+ expect(session).to be_an_instance_of OpenTok::Session
71
+ expect(session.session_id).to be_an_instance_of String
72
+ expect(session.media_mode).to eq :relayed
73
+ expect(session.location).to eq location
74
+ end
75
+
76
+ it "creates routed media sessions with a location hint", :vcr => { :erb => { :version => OpenTok::VERSION } } do
77
+ session = opentok.create_session :media_mode => :routed, :location => location
78
+ expect(session).to be_an_instance_of OpenTok::Session
79
+ expect(session.session_id).to be_an_instance_of String
80
+ expect(session.media_mode).to eq :routed
81
+ expect(session.location).to eq location
82
+ end
83
+
84
+ it "creates routed media sessions for invalid media modes", :vcr => { :erb => { :version => OpenTok::VERSION } } do
85
+ session = opentok.create_session :media_mode => :blah
86
+ expect(session).to be_an_instance_of OpenTok::Session
87
+ expect(session.session_id).to be_an_instance_of String
88
+ expect(session.media_mode).to eq :routed
89
+ expect(session.location).to eq nil
90
+ end
91
+
92
+ end
93
+
94
+ context "with an api_key that's a number" do
95
+ let(:api_key) { 123456 }
96
+
97
+ it { should be_an_instance_of(OpenTok::OpenTok) }
98
+
99
+ it "changes api_key property to string" do
100
+ expect(opentok.api_key).to eq api_key.to_s
101
+ end
102
+
103
+ it "should have an api_url property" do
104
+ expect(opentok.api_url).to eq default_api_url
105
+ end
106
+
107
+ # TODO: maybe i don't need to run all the tests
108
+ include_examples "opentok generates tokens"
109
+ end
110
+
111
+ context "with an additional api_url" do
112
+ let(:api_url) { "http://example.opentok.com" }
113
+ let(:opentok) { OpenTok::OpenTok.new api_key, api_secret, api_url }
114
+
115
+ it { should be_an_instance_of(OpenTok::OpenTok) }
116
+
117
+ it "should have an api_url property" do
118
+ expect(opentok.api_url).to eq api_url
119
+ end
120
+
121
+ # TODO: i don't need to run all the tests, just a set that checks for the URL's effect
122
+ # include_examples "generates tokens"
123
+ end
124
+
125
+ end
126
+
127
+ # ah, the magic of duck typing. the errors raised don't have any specific description
128
+ # see discussion here: https://www.ruby-forum.com/topic/194593
129
+ context "when initialized improperly" do
130
+ context "with no arguments" do
131
+ subject { -> { @opentok = OpenTOk::OpenTok.new } }
132
+ it { should raise_error }
133
+ end
134
+ context "with just an api_key" do
135
+ subject { -> { @opentok = OpenTOk::OpenTok.new "123456" } }
136
+ it { should raise_error }
137
+ end
138
+ context "with arguments of the wrong type" do
139
+ subject { -> { @opentok = OpenTOk::OpenTok.new api_key: "123456" } }
140
+ it { should raise_error }
141
+ end
142
+ end
143
+
144
+ end
@@ -0,0 +1,71 @@
1
+ require "opentok/session"
2
+
3
+ require "spec_helper"
4
+ require "shared/session_generates_tokens"
5
+
6
+ describe OpenTok::Session do
7
+
8
+ let(:api_key) { "123456" }
9
+ let(:api_secret) { "1234567890abcdef1234567890abcdef1234567890" }
10
+ let(:session_id) { "SESSIONID" }
11
+
12
+ let(:session) { OpenTok::Session.new api_key, api_secret, session_id }
13
+ subject { session }
14
+
15
+ context "when initialized with no options" do
16
+ it { should be_an_instance_of OpenTok::Session }
17
+ it "should have an api_key property" do
18
+ expect(session.api_key).to eq api_key
19
+ end
20
+ it "should have an api_secret property" do
21
+ expect(session.api_secret).to eq api_secret
22
+ end
23
+ it "should have a session_id property" do
24
+ expect(session.session_id).to eq session_id
25
+ end
26
+ it "should be represented by session_id when coerced to a string" do
27
+ expect(session.to_s).to eq session_id
28
+ end
29
+ it "should have the default media mode of routed" do
30
+ expect(session.media_mode).to eq :routed
31
+ end
32
+ it "should not have a location value" do
33
+ expect(session.location).to eq nil
34
+ end
35
+ include_examples "session generates tokens"
36
+ end
37
+
38
+ context "when initialized with options" do
39
+ let(:default_opts) { {} }
40
+ let(:session) { OpenTok::Session.new api_key, api_secret, session_id, default_opts }
41
+
42
+ it { should be_an_instance_of OpenTok::Session }
43
+ it "should have an api_key property" do
44
+ expect(session.api_key).to eq api_key
45
+ end
46
+ it "should have an api_secret property" do
47
+ expect(session.api_secret).to eq api_secret
48
+ end
49
+ it "should have a session_id property" do
50
+ expect(session.session_id).to eq session_id
51
+ end
52
+ it "should be represented by session_id when coerced to a string" do
53
+ expect(session.to_s).to eq session_id
54
+ end
55
+ it "should have media mode when set in options" do
56
+ opts = { :media_mode => :routed }
57
+ session = OpenTok::Session.new api_key, api_secret, session_id, opts
58
+ expect(session.media_mode).to eq :routed
59
+ opts = { :media_mode => :relayed }
60
+ session = OpenTok::Session.new api_key, api_secret, session_id, opts
61
+ expect(session.media_mode).to eq :relayed
62
+ end
63
+ it "should have a location value when set in options" do
64
+ opts = { :location => '12.34.56.78' }
65
+ session = OpenTok::Session.new api_key, api_secret, session_id, opts
66
+ expect(session.location).to eq opts[:location]
67
+ end
68
+ include_examples "session generates tokens"
69
+ end
70
+
71
+ end
@@ -0,0 +1,62 @@
1
+ require "opentok/constants"
2
+ require "matchers/token"
3
+
4
+ shared_examples "opentok generates tokens" do
5
+ describe "#generate_token" do
6
+ # these must be known quantities because generate_token will have to verify that the session_id
7
+ # belongs to the api_key, it doesn't have the luxury of getting that type of failure in an error
8
+ # response from the server
9
+ let(:api_key) { "123456" }
10
+ let(:api_secret) { "1234567890abcdef1234567890abcdef1234567890" }
11
+ let(:session_id) { "1_MX4xMjM0NTZ-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4" }
12
+ let(:default_role) { :publisher }
13
+
14
+ it "generates plain tokens" do
15
+ plain_token = opentok.generate_token session_id
16
+ expect(plain_token).to be_an_instance_of String
17
+ expect(plain_token).to carry_token_data :session_id => session_id
18
+ expect(plain_token).to carry_token_data :api_key => api_key
19
+ expect(plain_token).to carry_token_data :role => default_role
20
+ expect(plain_token).to carry_token_data [:nonce, :create_time]
21
+ expect(plain_token).to carry_valid_token_signature api_secret
22
+ end
23
+
24
+ it "generates tokens with an expire time" do
25
+ expire_time = Time.now + (60*60*24)
26
+ expiring_token = opentok.generate_token session_id, :expire_time => expire_time
27
+ expect(expiring_token).to be_an_instance_of String
28
+ expect(expiring_token).to carry_token_data :session_id => session_id
29
+ expect(expiring_token).to carry_token_data :api_key => api_key
30
+ expect(expiring_token).to carry_token_data :role => default_role
31
+ expect(expiring_token).to carry_token_data :expire_time => expire_time.to_i
32
+ expect(expiring_token).to carry_token_data [:nonce, :create_time]
33
+ expect(expiring_token).to carry_valid_token_signature api_secret
34
+ end
35
+
36
+ it "generates tokens with a role" do
37
+ role = :moderator
38
+ role_token = opentok.generate_token session_id, :role => role
39
+ expect(role_token).to be_an_instance_of String
40
+ expect(role_token).to carry_token_data :session_id => session_id
41
+ expect(role_token).to carry_token_data :api_key => api_key
42
+ expect(role_token).to carry_token_data :role => role
43
+ expect(role_token).to carry_token_data [:nonce, :create_time]
44
+ expect(role_token).to carry_valid_token_signature api_secret
45
+ end
46
+
47
+ it "generates tokens with data" do
48
+ data = "name=Johnny"
49
+ data_bearing_token = opentok.generate_token session_id, :data => data
50
+ expect(data_bearing_token).to be_an_instance_of String
51
+ expect(data_bearing_token).to carry_token_data :session_id => session_id
52
+ expect(data_bearing_token).to carry_token_data :api_key => api_key
53
+ expect(data_bearing_token).to carry_token_data :role => default_role
54
+ expect(data_bearing_token).to carry_token_data :data => data
55
+ expect(data_bearing_token).to carry_token_data [:nonce, :create_time]
56
+ expect(data_bearing_token).to carry_valid_token_signature api_secret
57
+ end
58
+
59
+ # TODO a context about using a bad session_id
60
+ end
61
+
62
+ end
@@ -0,0 +1,63 @@
1
+ require "opentok/constants"
2
+ require "matchers/token"
3
+
4
+ shared_examples "session generates tokens" do
5
+ describe "#generate_token" do
6
+ # these must be known quantities because generate_token will have to verify that the session_id
7
+ # belongs to the api_key, it doesn't have the luxury of getting that type of failure in an error
8
+ # response from the server
9
+ let(:api_key) { "123456" }
10
+ let(:api_secret) { "1234567890abcdef1234567890abcdef1234567890" }
11
+ let(:session_id) { "1_MX4xMjM0NTZ-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4" }
12
+ let(:default_role) { :publisher }
13
+
14
+ it "generates plain tokens" do
15
+ plain_token = session.generate_token
16
+ expect(plain_token).to be_an_instance_of String
17
+ expect(plain_token).to carry_token_data :session_id => session_id
18
+ expect(plain_token).to carry_token_data :api_key => api_key
19
+ expect(plain_token).to carry_token_data :role => default_role
20
+ expect(plain_token).to carry_token_data [:nonce, :create_time]
21
+ expect(plain_token).to carry_valid_token_signature api_secret
22
+ end
23
+
24
+ it "generates tokens with an expire time" do
25
+ expire_time = Time.now + (60*60*24)
26
+ expiring_token = session.generate_token :expire_time => expire_time
27
+ expect(expiring_token).to be_an_instance_of String
28
+ expect(expiring_token).to carry_token_data :session_id => session_id
29
+ expect(expiring_token).to carry_token_data :api_key => api_key
30
+ expect(expiring_token).to carry_token_data :role => default_role
31
+ expect(expiring_token).to carry_token_data :expire_time => expire_time.to_i
32
+ expect(expiring_token).to carry_token_data [:nonce, :create_time]
33
+ expect(expiring_token).to carry_valid_token_signature api_secret
34
+ end
35
+
36
+ it "generates tokens with a role" do
37
+ role = :moderator
38
+ role_token = session.generate_token :role => role
39
+ expect(role_token).to be_an_instance_of String
40
+ expect(role_token).to carry_token_data :session_id => session_id
41
+ expect(role_token).to carry_token_data :api_key => api_key
42
+ expect(role_token).to carry_token_data :role => role
43
+ expect(role_token).to carry_token_data [:nonce, :create_time]
44
+ expect(role_token).to carry_valid_token_signature api_secret
45
+ end
46
+
47
+ it "generates tokens with data" do
48
+ data = "name=Johnny"
49
+ data_bearing_token = session.generate_token :data => data
50
+ expect(data_bearing_token).to be_an_instance_of String
51
+ expect(data_bearing_token).to carry_token_data :session_id => session_id
52
+ expect(data_bearing_token).to carry_token_data :api_key => api_key
53
+ expect(data_bearing_token).to carry_token_data :role => default_role
54
+ expect(data_bearing_token).to carry_token_data :data => data
55
+ expect(data_bearing_token).to carry_token_data [:nonce, :create_time]
56
+ expect(data_bearing_token).to carry_valid_token_signature api_secret
57
+ end
58
+
59
+
60
+ # TODO a context about using a bad session_id
61
+ end
62
+
63
+ end
@@ -1,15 +1,14 @@
1
- require 'opentok'
2
-
3
- require 'vcr'
4
- require 'webmock'
1
+ require "vcr"
5
2
 
6
3
  VCR.configure do |c|
7
4
  c.cassette_library_dir = 'spec/cassettes'
8
5
  c.hook_into :webmock
9
- c.default_cassette_options = { :record => :new_episodes }
10
- c.allow_http_connections_when_no_cassette=true
6
+ c.default_cassette_options = { :match_requests_on => [:method, :uri, :query, :body, :headers] }
7
+ c.configure_rspec_metadata!
11
8
  end
12
9
 
13
10
  RSpec.configure do |c|
14
- c.extend VCR::RSpec::Macros
11
+ # so we can use :vcr rather than :vcr => true;
12
+ # in RSpec 3 this will no longer be necessary.
13
+ c.treat_symbols_as_metadata_keys_with_true_values = true
15
14
  end