bigbluebutton-api-ruby 1.3.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,728 +4,794 @@ require 'spec_helper'
4
4
  # there are separate files with more tests.
5
5
  describe BigBlueButton::BigBlueButtonApi do
6
6
 
7
- # default variables and API object for all tests
8
- let(:url) { "http://server.com" }
9
- let(:salt) { "1234567890abcdefghijkl" }
10
- let(:version) { "0.8" }
11
- let(:debug) { false }
12
- let(:api) { BigBlueButton::BigBlueButtonApi.new(url, salt, version, debug) }
13
-
14
- describe "#initialize" do
15
- context "standard initialization" do
16
- subject { BigBlueButton::BigBlueButtonApi.new(url, salt, version, debug) }
17
- it { subject.url.should == url }
18
- it { subject.salt.should == salt }
19
- it { subject.version.should == version }
20
- it { subject.debug.should == debug }
21
- it { subject.timeout.should == 10 }
22
- it { subject.supported_versions.should include("0.8") }
23
- it { subject.supported_versions.should include("0.81") }
24
- it { subject.request_headers.should == {} }
25
- end
7
+ shared_examples_for "BigBlueButtonApi" do |version|
8
+
9
+ # default variables and API object for all tests
10
+ let(:url) { "http://server.com" }
11
+ let(:secret) { "1234567890abcdefghijkl" }
12
+ let(:logger) { Logger.new(STDOUT) }
13
+ let(:api) { BigBlueButton::BigBlueButtonApi.new(url, secret, version, logger) }
14
+ before { logger.level = Logger::INFO }
15
+
16
+ describe "#initialize" do
17
+ context "standard initialization" do
18
+ subject { BigBlueButton::BigBlueButtonApi.new(url, secret, version, logger) }
19
+ it { subject.url.should == url }
20
+ it { subject.secret.should == secret }
21
+ it { subject.version.should == version }
22
+ it { subject.logger.should == logger }
23
+ it { subject.timeout.should == 10 }
24
+ it { subject.supported_versions.should include("0.8") }
25
+ it { subject.supported_versions.should include("0.81") }
26
+ it { subject.supported_versions.should include("0.9") }
27
+ it { subject.request_headers.should == {} }
28
+ end
26
29
 
27
- context "when the version is not informed, get it from the BBB server" do
28
- before { BigBlueButton::BigBlueButtonApi.any_instance.should_receive(:get_api_version).and_return("0.8") }
29
- subject { BigBlueButton::BigBlueButtonApi.new(url, salt, nil) }
30
- it { subject.version.should == "0.8" }
31
- end
30
+ context "when the version is not informed, get it from the BBB server" do
31
+ before { BigBlueButton::BigBlueButtonApi.any_instance.should_receive(:get_api_version).and_return("0.8") }
32
+ subject { BigBlueButton::BigBlueButtonApi.new(url, secret, nil) }
33
+ it { subject.version.should == "0.8" }
34
+ end
32
35
 
33
- it "when the version is not supported raise an error" do
34
- expect {
35
- BigBlueButton::BigBlueButtonApi.new(url, salt, "0.not-supported", nil)
36
- }.to raise_error(BigBlueButton::BigBlueButtonException)
37
- end
36
+ context "when the version informed is empty, get it from the BBB server" do
37
+ before { BigBlueButton::BigBlueButtonApi.any_instance.should_receive(:get_api_version).and_return("0.8") }
38
+ subject { BigBlueButton::BigBlueButtonApi.new(url, secret, " ") }
39
+ it { subject.version.should == "0.8" }
40
+ end
38
41
 
39
- context "current supported versions" do
40
- subject { BigBlueButton::BigBlueButtonApi.new(url, salt) }
41
- it { subject.supported_versions.should == ["0.8", "0.81"] }
42
- end
43
- end
42
+ it "when the version is lower than the lowest supported, raise exception" do
43
+ expect {
44
+ BigBlueButton::BigBlueButtonApi.new(url, secret, "0.1", nil)
45
+ }.to raise_error(BigBlueButton::BigBlueButtonException)
46
+ end
44
47
 
45
- describe "#create_meeting" do
46
- context "standard case" do
47
- let(:req_params) {
48
- { :name => "name", :meetingID => "meeting-id", :moderatorPW => "mp", :attendeePW => "ap",
49
- :welcome => "Welcome!", :dialNumber => 12345678, :logoutURL => "http://example.com",
50
- :maxParticipants => 25, :voiceBridge => 12345, :webVoice => "12345abc", :record => "true" }
51
- }
52
- let(:req_response) {
53
- { :meetingID => 123, :moderatorPW => 111, :attendeePW => 222, :hasBeenForciblyEnded => "FALSE" }
54
- }
55
- let(:final_response) {
56
- { :meetingID => "123", :moderatorPW => "111", :attendeePW => "222", :hasBeenForciblyEnded => false }
57
- }
48
+ it "when the version is higher than thew highest supported, use the highest supported" do
49
+ BigBlueButton::BigBlueButtonApi.new(url, secret, "5.0", nil).version.should eql('1.0')
50
+ end
58
51
 
59
- # ps: not mocking the formatter here because it's easier to just check the results (final_response)
60
- before { api.should_receive(:send_api_request).with(:create, req_params).and_return(req_response) }
61
- subject {
62
- options = { :moderatorPW => "mp", :attendeePW => "ap", :welcome => "Welcome!",
63
- :dialNumber => 12345678, :logoutURL => "http://example.com", :maxParticipants => 25,
64
- :voiceBridge => 12345, :webVoice => "12345abc", :record => "true" }
65
- api.create_meeting("name", "meeting-id", options)
66
- }
67
- it { subject.should == final_response }
68
- end
52
+ it "compares versions in the format 'x.xx' properly" do
53
+ expect {
54
+ # if not comparing properly, 0.61 would be bigger than 0.9, for example
55
+ # comparing the way BBB does, it is lower, so will raise an exception
56
+ BigBlueButton::BigBlueButtonApi.new(url, secret, "0.61", nil)
57
+ }.to raise_error(BigBlueButton::BigBlueButtonException)
58
+ end
69
59
 
70
- context "accepts non standard options" do
71
- let(:params) {
72
- { :name => "name", :meetingID => "meeting-id",
73
- :moderatorPW => "mp", :attendeePW => "ap", :nonStandard => 1 }
74
- }
75
- before { api.should_receive(:send_api_request).with(:create, params) }
76
- it { api.create_meeting("name", "meeting-id", params) }
60
+ context "current supported versions" do
61
+ before {
62
+ BigBlueButton::BigBlueButtonApi.any_instance.should_receive(:get_api_version).and_return("0.9")
63
+ }
64
+ subject { BigBlueButton::BigBlueButtonApi.new(url, secret) }
65
+ it { subject.supported_versions.should == ["0.8", "0.81", "0.9", "1.0"] }
66
+ end
77
67
  end
78
68
 
79
- context "accepts :record as boolean" do
80
- let(:req_params) {
81
- { :name => "name", :meetingID => "meeting-id",
82
- :moderatorPW => "mp", :attendeePW => "ap", :record => "true" }
83
- }
84
- before { api.should_receive(:send_api_request).with(:create, req_params) }
85
- it {
86
- params = { :name => "name", :meetingID => "meeting-id",
87
- :moderatorPW => "mp", :attendeePW => "ap", :record => true }
88
- api.create_meeting("name", "meeting-id", params)
89
- }
90
- end
69
+ describe "#create_meeting" do
70
+ context "standard case" do
71
+ let(:req_params) {
72
+ { :name => "name", :meetingID => "meeting-id", :moderatorPW => "mp", :attendeePW => "ap",
73
+ :welcome => "Welcome!", :dialNumber => 12345678, :logoutURL => "http://example.com",
74
+ :maxParticipants => 25, :voiceBridge => 12345, :webVoice => "12345abc", :record => "true" }
75
+ }
76
+ let(:req_response) {
77
+ { :meetingID => 123, :moderatorPW => 111, :attendeePW => 222, :hasBeenForciblyEnded => "FALSE" }
78
+ }
79
+ let(:final_response) {
80
+ { :meetingID => "123", :moderatorPW => "111", :attendeePW => "222", :hasBeenForciblyEnded => false }
81
+ }
91
82
 
92
- context "with modules" do
93
- let(:req_params) {
94
- { :name => "name", :meetingID => "meeting-id", :moderatorPW => "mp", :attendeePW => "ap" }
95
- }
96
- let(:req_response) {
97
- { :meetingID => 123, :moderatorPW => 111, :attendeePW => 222, :hasBeenForciblyEnded => "FALSE", :createTime => "123123123" }
98
- }
99
- let(:final_response) {
100
- { :meetingID => "123", :moderatorPW => "111", :attendeePW => "222", :hasBeenForciblyEnded => false, :createTime => 123123123 }
101
- }
102
- let(:modules) {
103
- m = BigBlueButton::BigBlueButtonModules.new
104
- m.add_presentation(:url, "http://www.samplepdf.com/sample.pdf")
105
- m.add_presentation(:url, "http://www.samplepdf.com/sample2.pdf")
106
- m.add_presentation(:base64, "JVBERi0xLjQKJ....[clipped here]....0CiUlRU9GCg==", "first-class.pdf")
107
- m
108
- }
83
+ # ps: not mocking the formatter here because it's easier to just check the results (final_response)
84
+ before { api.should_receive(:send_api_request).with(:create, req_params).and_return(req_response) }
85
+ subject {
86
+ options = { :moderatorPW => "mp", :attendeePW => "ap", :welcome => "Welcome!",
87
+ :dialNumber => 12345678, :logoutURL => "http://example.com", :maxParticipants => 25,
88
+ :voiceBridge => 12345, :webVoice => "12345abc", :record => "true" }
89
+ api.create_meeting("name", "meeting-id", options)
90
+ }
91
+ it { subject.should == final_response }
92
+ end
109
93
 
110
- before {
111
- api.should_receive(:send_api_request).with(:create, req_params, modules.to_xml).
112
- and_return(req_response)
113
- }
114
- subject {
115
- options = { :moderatorPW => "mp", :attendeePW => "ap" }
116
- api.create_meeting("name", "meeting-id", options, modules)
117
- }
118
- it { subject.should == final_response }
119
- end
94
+ context "accepts non standard options" do
95
+ let(:params) {
96
+ { :name => "name", :meetingID => "meeting-id",
97
+ :moderatorPW => "mp", :attendeePW => "ap", :nonStandard => 1 }
98
+ }
99
+ before { api.should_receive(:send_api_request).with(:create, params) }
100
+ it { api.create_meeting("name", "meeting-id", params) }
101
+ end
120
102
 
121
- context "without modules" do
122
- let(:req_params) {
123
- { :name => "name", :meetingID => "meeting-id", :moderatorPW => "mp", :attendeePW => "ap",
124
- :welcome => "Welcome!", :dialNumber => 12345678, :logoutURL => "http://example.com",
125
- :maxParticipants => 25, :voiceBridge => 12345, :record => "true", :duration => 20,
126
- :meta_1 => "meta1", :meta_2 => "meta2" }
127
- }
128
- let(:req_response) {
129
- { :meetingID => 123, :moderatorPW => 111, :attendeePW => 222, :hasBeenForciblyEnded => "FALSE", :createTime => "123123123" }
130
- }
131
- let(:final_response) {
132
- { :meetingID => "123", :moderatorPW => "111", :attendeePW => "222", :hasBeenForciblyEnded => false, :createTime => 123123123 }
133
- }
103
+ context "accepts :record as boolean" do
104
+ let(:req_params) {
105
+ { :name => "name", :meetingID => "meeting-id",
106
+ :moderatorPW => "mp", :attendeePW => "ap", :record => "true" }
107
+ }
108
+ before { api.should_receive(:send_api_request).with(:create, req_params) }
109
+ it {
110
+ params = { :name => "name", :meetingID => "meeting-id",
111
+ :moderatorPW => "mp", :attendeePW => "ap", :record => true }
112
+ api.create_meeting("name", "meeting-id", params)
113
+ }
114
+ end
134
115
 
135
- before { api.should_receive(:send_api_request).with(:create, req_params).and_return(req_response) }
136
- subject {
137
- options = { :moderatorPW => "mp", :attendeePW => "ap", :welcome => "Welcome!", :dialNumber => 12345678,
138
- :logoutURL => "http://example.com", :maxParticipants => 25, :voiceBridge => 12345, :record => true,
139
- :duration => 20, :meta_1 => "meta1", :meta_2 => "meta2" }
140
- api.create_meeting("name", "meeting-id", options)
141
- }
142
- it { subject.should == final_response }
143
- end
144
- end
116
+ context "with modules" do
117
+ let(:req_params) {
118
+ { :name => "name", :meetingID => "meeting-id", :moderatorPW => "mp", :attendeePW => "ap" }
119
+ }
120
+ let(:req_response) {
121
+ { :meetingID => 123, :moderatorPW => 111, :attendeePW => 222, :hasBeenForciblyEnded => "FALSE", :createTime => "123123123" }
122
+ }
123
+ let(:final_response) {
124
+ { :meetingID => "123", :moderatorPW => "111", :attendeePW => "222", :hasBeenForciblyEnded => false, :createTime => 123123123 }
125
+ }
126
+ let(:modules) {
127
+ m = BigBlueButton::BigBlueButtonModules.new
128
+ m.add_presentation(:url, "http://www.samplepdf.com/sample.pdf")
129
+ m.add_presentation(:url, "http://www.samplepdf.com/sample2.pdf")
130
+ m.add_presentation(:base64, "JVBERi0xLjQKJ....[clipped here]....0CiUlRU9GCg==", "first-class.pdf")
131
+ m
132
+ }
145
133
 
146
- describe "#end_meeting" do
147
- let(:meeting_id) { "meeting-id" }
148
- let(:moderator_password) { "password" }
134
+ before {
135
+ api.should_receive(:send_api_request).with(:create, req_params, modules.to_xml).
136
+ and_return(req_response)
137
+ }
138
+ subject {
139
+ options = { :moderatorPW => "mp", :attendeePW => "ap" }
140
+ api.create_meeting("name", "meeting-id", options, modules)
141
+ }
142
+ it { subject.should == final_response }
143
+ end
149
144
 
150
- context "standard case" do
151
- let(:params) { { :meetingID => meeting_id, :password => moderator_password } }
152
- let(:response) { "anything" }
145
+ context "without modules" do
146
+ let(:req_params) {
147
+ { :name => "name", :meetingID => "meeting-id", :moderatorPW => "mp", :attendeePW => "ap",
148
+ :welcome => "Welcome!", :dialNumber => 12345678, :logoutURL => "http://example.com",
149
+ :maxParticipants => 25, :voiceBridge => 12345, :record => "true", :duration => 20,
150
+ :meta_1 => "meta1", :meta_2 => "meta2" }
151
+ }
152
+ let(:req_response) {
153
+ { :meetingID => 123, :moderatorPW => 111, :attendeePW => 222, :hasBeenForciblyEnded => "FALSE", :createTime => "123123123" }
154
+ }
155
+ let(:final_response) {
156
+ { :meetingID => "123", :moderatorPW => "111", :attendeePW => "222", :hasBeenForciblyEnded => false, :createTime => 123123123 }
157
+ }
153
158
 
154
- before { api.should_receive(:send_api_request).with(:end, params).and_return(response) }
155
- it { api.end_meeting(meeting_id, moderator_password).should == response }
159
+ before { api.should_receive(:send_api_request).with(:create, req_params).and_return(req_response) }
160
+ subject {
161
+ options = { :moderatorPW => "mp", :attendeePW => "ap", :welcome => "Welcome!", :dialNumber => 12345678,
162
+ :logoutURL => "http://example.com", :maxParticipants => 25, :voiceBridge => 12345, :record => true,
163
+ :duration => 20, :meta_1 => "meta1", :meta_2 => "meta2" }
164
+ api.create_meeting("name", "meeting-id", options)
165
+ }
166
+ it { subject.should == final_response }
167
+ end
156
168
  end
157
169
 
158
- context "accepts non standard options" do
159
- let(:params_in) {
160
- { :anything1 => "anything-1", :anything2 => 2 }
161
- }
162
- let(:params_out) {
163
- { :meetingID => meeting_id, :password => moderator_password,
164
- :anything1 => "anything-1", :anything2 => 2 }
165
- }
166
- before { api.should_receive(:send_api_request).with(:end, params_out) }
167
- it { api.end_meeting(meeting_id, moderator_password, params_in) }
168
- end
169
- end
170
+ describe "#end_meeting" do
171
+ let(:meeting_id) { "meeting-id" }
172
+ let(:moderator_password) { "password" }
170
173
 
171
- describe "#is_meeting_running?" do
172
- let(:meeting_id) { "meeting-id" }
173
- let(:params) { { :meetingID => meeting_id } }
174
+ context "standard case" do
175
+ let(:params) { { :meetingID => meeting_id, :password => moderator_password } }
176
+ let(:response) { "anything" }
174
177
 
175
- context "when the meeting is running" do
176
- let(:response) { { :running => "TRUE" } }
177
- before { api.should_receive(:send_api_request).with(:isMeetingRunning, params).and_return(response) }
178
- it { api.is_meeting_running?(meeting_id).should == true }
179
- end
178
+ before { api.should_receive(:send_api_request).with(:end, params).and_return(response) }
179
+ it { api.end_meeting(meeting_id, moderator_password).should == response }
180
+ end
180
181
 
181
- context "when the meeting is not running" do
182
- let(:response) { { :running => "FALSE" } }
183
- before { api.should_receive(:send_api_request).with(:isMeetingRunning, params).and_return(response) }
184
- it { api.is_meeting_running?(meeting_id).should == false }
182
+ context "accepts non standard options" do
183
+ let(:params_in) {
184
+ { :anything1 => "anything-1", :anything2 => 2 }
185
+ }
186
+ let(:params_out) {
187
+ { :meetingID => meeting_id, :password => moderator_password,
188
+ :anything1 => "anything-1", :anything2 => 2 }
189
+ }
190
+ before { api.should_receive(:send_api_request).with(:end, params_out) }
191
+ it { api.end_meeting(meeting_id, moderator_password, params_in) }
192
+ end
185
193
  end
186
194
 
187
- context "accepts non standard options" do
188
- let(:params_in) {
189
- { :anything1 => "anything-1", :anything2 => 2 }
190
- }
191
- let(:params_out) {
192
- { :meetingID => meeting_id, :anything1 => "anything-1", :anything2 => 2 }
193
- }
194
- before { api.should_receive(:send_api_request).with(:isMeetingRunning, params_out) }
195
- it { api.is_meeting_running?(meeting_id, params_in) }
196
- end
197
- end
195
+ describe "#is_meeting_running?" do
196
+ let(:meeting_id) { "meeting-id" }
197
+ let(:params) { { :meetingID => meeting_id } }
198
198
 
199
- describe "#join_meeting_url" do
200
- context "standard case" do
201
- let(:params) {
202
- { :meetingID => "meeting-id", :password => "pw", :fullName => "Name",
203
- :userID => "id123", :webVoiceConf => 12345678, :createTime => 9876543 }
204
- }
199
+ context "when the meeting is running" do
200
+ let(:response) { { :running => "TRUE" } }
201
+ before { api.should_receive(:send_api_request).with(:isMeetingRunning, params).and_return(response) }
202
+ it { api.is_meeting_running?(meeting_id).should == true }
203
+ end
205
204
 
206
- before { api.should_receive(:get_url).with(:join, params).and_return("test-url") }
207
- it {
208
- options = { :userID => "id123", :webVoiceConf => 12345678, :createTime => 9876543 }
209
- api.join_meeting_url("meeting-id", "Name", "pw", options).should == "test-url"
210
- }
211
- end
205
+ context "when the meeting is not running" do
206
+ let(:response) { { :running => "FALSE" } }
207
+ before { api.should_receive(:send_api_request).with(:isMeetingRunning, params).and_return(response) }
208
+ it { api.is_meeting_running?(meeting_id).should == false }
209
+ end
212
210
 
213
- context "accepts non standard options" do
214
- let(:params) {
215
- { :meetingID => "meeting-id", :password => "pw",
216
- :fullName => "Name", :userID => "id123", :nonStandard => 1 }
217
- }
218
- before { api.should_receive(:get_url).with(:join, params) }
219
- it { api.join_meeting_url("meeting-id", "Name", "pw", params) }
211
+ context "accepts non standard options" do
212
+ let(:params_in) {
213
+ { :anything1 => "anything-1", :anything2 => 2 }
214
+ }
215
+ let(:params_out) {
216
+ { :meetingID => meeting_id, :anything1 => "anything-1", :anything2 => 2 }
217
+ }
218
+ before { api.should_receive(:send_api_request).with(:isMeetingRunning, params_out) }
219
+ it { api.is_meeting_running?(meeting_id, params_in) }
220
+ end
220
221
  end
221
- end
222
222
 
223
- describe "#get_meeting_info" do
224
- let(:meeting_id) { "meeting-id" }
225
- let(:password) { "password" }
223
+ describe "#join_meeting_url" do
224
+ context "standard case" do
225
+ let(:params) {
226
+ { :meetingID => "meeting-id", :password => "pw", :fullName => "Name",
227
+ :userID => "id123", :webVoiceConf => 12345678, :createTime => 9876543 }
228
+ }
226
229
 
227
- context "standard case" do
228
- let(:params) { { :meetingID => meeting_id, :password => password } }
230
+ before { api.should_receive(:get_url).with(:join, params).and_return(["test-url", nil]) }
231
+ it {
232
+ options = { :userID => "id123", :webVoiceConf => 12345678, :createTime => 9876543 }
233
+ api.join_meeting_url("meeting-id", "Name", "pw", options).should == "test-url"
234
+ }
235
+ end
229
236
 
230
- let(:attendee1) { { :userID => 123, :fullName => "Dexter Morgan", :role => "MODERATOR" } }
231
- let(:attendee2) { { :userID => "id2", :fullName => "Cameron", :role => "VIEWER" } }
232
- let(:response) {
233
- { :meetingID => 123, :moderatorPW => 111, :attendeePW => 222, :hasBeenForciblyEnded => "FALSE",
234
- :running => "TRUE", :startTime => "Thu Sep 01 17:51:42 UTC 2011", :endTime => "null",
235
- :returncode => true, :attendees => { :attendee => [ attendee1, attendee2 ] },
236
- :messageKey => "mkey", :message => "m", :participantCount => "50", :moderatorCount => "3",
237
- :meetingName => "meeting-name", :maxUsers => "100", :voiceBridge => "12341234", :createTime => "123123123",
238
- :recording => "false", :meta_1 => "abc", :meta_2 => "2" }
239
- } # hash after the send_api_request call, before the formatting
240
-
241
- let(:expected_attendee1) { { :userID => "123", :fullName => "Dexter Morgan", :role => :moderator } }
242
- let(:expected_attendee2) { { :userID => "id2", :fullName => "Cameron", :role => :viewer } }
243
- let(:final_response) {
244
- { :meetingID => "123", :moderatorPW => "111", :attendeePW => "222", :hasBeenForciblyEnded => false,
245
- :running => true, :startTime => DateTime.parse("Thu Sep 01 17:51:42 UTC 2011"), :endTime => nil,
246
- :returncode => true, :attendees => [ expected_attendee1, expected_attendee2 ],
247
- :messageKey => "mkey", :message => "m", :participantCount => 50, :moderatorCount => 3,
248
- :meetingName => "meeting-name", :maxUsers => 100, :voiceBridge => 12341234, :createTime => 123123123,
249
- :recording => false, :meta_1 => "abc", :meta_2 => "2" }
250
- } # expected return hash after all the formatting
251
-
252
- # ps: not mocking the formatter here because it's easier to just check the results (final_response)
253
- before { api.should_receive(:send_api_request).with(:getMeetingInfo, params).and_return(response) }
254
- it { api.get_meeting_info(meeting_id, password).should == final_response }
237
+ context "accepts non standard options" do
238
+ let(:params) {
239
+ { :meetingID => "meeting-id", :password => "pw",
240
+ :fullName => "Name", :userID => "id123", :nonStandard => 1 }
241
+ }
242
+ before { api.should_receive(:get_url).with(:join, params) }
243
+ it { api.join_meeting_url("meeting-id", "Name", "pw", params) }
244
+ end
255
245
  end
256
246
 
257
- context "accepts non standard options" do
258
- let(:params_in) {
259
- { :anything1 => "anything-1", :anything2 => 2 }
260
- }
261
- let(:params_out) {
262
- { :meetingID => meeting_id, :password => password,
263
- :anything1 => "anything-1", :anything2 => 2 }
264
- }
265
- before { api.should_receive(:send_api_request).with(:getMeetingInfo, params_out).and_return({}) }
266
- it { api.get_meeting_info(meeting_id, password, params_in) }
247
+ describe "#get_meeting_info" do
248
+ let(:meeting_id) { "meeting-id" }
249
+ let(:password) { "password" }
250
+
251
+ context "standard case" do
252
+ let(:params) { { :meetingID => meeting_id, :password => password } }
253
+
254
+ let(:attendee1) { { :userID => 123, :fullName => "Dexter Morgan", :role => "MODERATOR" } }
255
+ let(:attendee2) { { :userID => "id2", :fullName => "Cameron", :role => "VIEWER" } }
256
+ let(:response) {
257
+ { :meetingID => 123, :moderatorPW => 111, :attendeePW => 222, :hasBeenForciblyEnded => "FALSE",
258
+ :running => "TRUE", :startTime => "Thu Sep 01 17:51:42 UTC 2011", :endTime => "null",
259
+ :returncode => true, :attendees => { :attendee => [ attendee1, attendee2 ] },
260
+ :messageKey => "mkey", :message => "m", :participantCount => "50", :moderatorCount => "3",
261
+ :meetingName => "meeting-name", :maxUsers => "100", :voiceBridge => "12341234", :createTime => "123123123",
262
+ :recording => "false", :meta_1 => "abc", :meta_2 => "2" }
263
+ } # hash after the send_api_request call, before the formatting
264
+
265
+ let(:expected_attendee1) { { :userID => "123", :fullName => "Dexter Morgan", :role => :moderator } }
266
+ let(:expected_attendee2) { { :userID => "id2", :fullName => "Cameron", :role => :viewer } }
267
+ let(:final_response) {
268
+ { :meetingID => "123", :moderatorPW => "111", :attendeePW => "222", :hasBeenForciblyEnded => false,
269
+ :running => true, :startTime => DateTime.parse("Thu Sep 01 17:51:42 UTC 2011"), :endTime => nil,
270
+ :returncode => true, :attendees => [ expected_attendee1, expected_attendee2 ],
271
+ :messageKey => "mkey", :message => "m", :participantCount => 50, :moderatorCount => 3,
272
+ :meetingName => "meeting-name", :maxUsers => 100, :voiceBridge => 12341234, :createTime => 123123123,
273
+ :recording => false, :meta_1 => "abc", :meta_2 => "2" }
274
+ } # expected return hash after all the formatting
275
+
276
+ # ps: not mocking the formatter here because it's easier to just check the results (final_response)
277
+ before { api.should_receive(:send_api_request).with(:getMeetingInfo, params).and_return(response) }
278
+ it { api.get_meeting_info(meeting_id, password).should == final_response }
279
+ end
280
+
281
+ context "accepts non standard options" do
282
+ let(:params_in) {
283
+ { :anything1 => "anything-1", :anything2 => 2 }
284
+ }
285
+ let(:params_out) {
286
+ { :meetingID => meeting_id, :password => password,
287
+ :anything1 => "anything-1", :anything2 => 2 }
288
+ }
289
+ before { api.should_receive(:send_api_request).with(:getMeetingInfo, params_out).and_return({}) }
290
+ it { api.get_meeting_info(meeting_id, password, params_in) }
291
+ end
267
292
  end
268
- end
269
293
 
270
- describe "#get_meetings" do
271
- context "standard case" do
272
- let(:meeting_hash1) { { :meetingID => "Demo Meeting", :attendeePW => "ap", :moderatorPW => "mp", :hasBeenForciblyEnded => false, :running => true } }
273
- let(:meeting_hash2) { { :meetingID => "Ended Meeting", :attendeePW => "pass", :moderatorPW => "pass", :hasBeenForciblyEnded => true, :running => false } }
274
- let(:flattened_response) {
275
- { :returncode => true, :meetings => [ meeting_hash1, meeting_hash2 ], :messageKey => "mkey", :message => "m" }
276
- } # hash *after* the flatten_objects call
294
+ describe "#get_meetings" do
295
+ context "standard case" do
296
+ let(:meeting_hash1) { { :meetingID => "Demo Meeting", :attendeePW => "ap", :moderatorPW => "mp", :hasBeenForciblyEnded => false, :running => true } }
297
+ let(:meeting_hash2) { { :meetingID => "Ended Meeting", :attendeePW => "pass", :moderatorPW => "pass", :hasBeenForciblyEnded => true, :running => false } }
298
+ let(:flattened_response) {
299
+ { :returncode => true, :meetings => [ meeting_hash1, meeting_hash2 ], :messageKey => "mkey", :message => "m" }
300
+ } # hash *after* the flatten_objects call
301
+
302
+ before {
303
+ api.should_receive(:send_api_request).with(:getMeetings, {}).
304
+ and_return(flattened_response)
305
+ formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter)
306
+ formatter_mock.should_receive(:flatten_objects).with(:meetings, :meeting)
307
+ BigBlueButton::BigBlueButtonFormatter.should_receive(:new).and_return(formatter_mock)
308
+ BigBlueButton::BigBlueButtonFormatter.should_receive(:format_meeting).with(meeting_hash1)
309
+ BigBlueButton::BigBlueButtonFormatter.should_receive(:format_meeting).with(meeting_hash2)
310
+ }
311
+ it { api.get_meetings }
312
+ end
277
313
 
278
- before {
279
- api.should_receive(:send_api_request).with(:getMeetings, {}).
280
- and_return(flattened_response)
281
- formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter)
282
- formatter_mock.should_receive(:flatten_objects).with(:meetings, :meeting)
283
- BigBlueButton::BigBlueButtonFormatter.should_receive(:new).and_return(formatter_mock)
284
- BigBlueButton::BigBlueButtonFormatter.should_receive(:format_meeting).with(meeting_hash1)
285
- BigBlueButton::BigBlueButtonFormatter.should_receive(:format_meeting).with(meeting_hash2)
286
- }
287
- it { api.get_meetings }
314
+ context "accepts non standard options" do
315
+ let(:params) {
316
+ { :anything1 => "anything-1", :anything2 => 2 }
317
+ }
318
+ before { api.should_receive(:send_api_request).with(:getMeetings, params).and_return({}) }
319
+ it { api.get_meetings(params) }
320
+ end
288
321
  end
289
322
 
290
- context "accepts non standard options" do
291
- let(:params) {
292
- { :anything1 => "anything-1", :anything2 => 2 }
293
- }
294
- before { api.should_receive(:send_api_request).with(:getMeetings, params).and_return({}) }
295
- it { api.get_meetings(params) }
296
- end
297
- end
323
+ describe "#get_api_version" do
324
+ context "returns the version returned by the server" do
325
+ let(:hash) { { :returncode => true, :version => "0.8" } }
326
+ before { api.should_receive(:send_api_request).with(:index).and_return(hash) }
327
+ it { api.get_api_version.should == "0.8" }
328
+ end
298
329
 
299
- describe "#get_api_version" do
300
- context "returns the version returned by the server" do
301
- let(:hash) { { :returncode => true, :version => "0.8" } }
302
- before { api.should_receive(:send_api_request).with(:index).and_return(hash) }
303
- it { api.get_api_version.should == "0.8" }
330
+ context "returns an empty string when the server responds with an empty hash" do
331
+ before { api.should_receive(:send_api_request).with(:index).and_return({}) }
332
+ it { api.get_api_version.should == "" }
333
+ end
304
334
  end
305
335
 
306
- context "returns an empty string when the server responds with an empty hash" do
307
- before { api.should_receive(:send_api_request).with(:index).and_return({}) }
308
- it { api.get_api_version.should == "" }
336
+ describe "#test_connection" do
337
+ context "returns the returncode returned by the server" do
338
+ let(:hash) { { :returncode => "any-value" } }
339
+ before { api.should_receive(:send_api_request).with(:index).and_return(hash) }
340
+ it { api.test_connection.should == "any-value" }
341
+ end
309
342
  end
310
- end
311
343
 
312
- describe "#test_connection" do
313
- context "returns the returncode returned by the server" do
314
- let(:hash) { { :returncode => "any-value" } }
315
- before { api.should_receive(:send_api_request).with(:index).and_return(hash) }
316
- it { api.test_connection.should == "any-value" }
344
+ describe "#check_url" do
345
+ context "when method = :check" do
346
+ it {
347
+ api.url = 'http://my-test-server.com/bigbluebutton/api'
348
+ api.check_url.should == 'http://my-test-server.com/check'
349
+ }
350
+ end
317
351
  end
318
- end
319
352
 
320
- describe "#==" do
321
- let(:api2) { BigBlueButton::BigBlueButtonApi.new(url, salt, version, debug) }
353
+ describe "#==" do
354
+ let(:api2) { BigBlueButton::BigBlueButtonApi.new(url, secret, version, logger) }
322
355
 
323
- context "compares attributes" do
324
- it { api.should == api2 }
325
- end
356
+ context "compares attributes" do
357
+ it { api.should == api2 }
358
+ end
326
359
 
327
- context "differs #debug" do
328
- before { api2.debug = !api.debug }
329
- it { api.should_not == api2 }
330
- end
360
+ context "differs #logger" do
361
+ before { api2.logger = !api.logger }
362
+ it { api.should_not == api2 }
363
+ end
364
+
365
+ context "differs #secret" do
366
+ before { api2.secret = api.secret + "x" }
367
+ it { api.should_not == api2 }
368
+ end
369
+
370
+ context "differs #version" do
371
+ before { api2.version = api.version + "x" }
372
+ it { api.should_not == api2 }
373
+ end
331
374
 
332
- context "differs #salt" do
333
- before { api2.salt = api.salt + "x" }
334
- it { api.should_not == api2 }
375
+ context "differs #supported_versions" do
376
+ before { api2.supported_versions << "x" }
377
+ it { api.should_not == api2 }
378
+ end
335
379
  end
336
380
 
337
- context "differs #version" do
338
- before { api2.version = api.version + "x" }
339
- it { api.should_not == api2 }
381
+ describe "#last_http_response" do
382
+ # we test this through a #test_connection call
383
+
384
+ let(:request_mock) { mock }
385
+ before {
386
+ api.should_receive(:get_url)
387
+ # this return value will be stored in @http_response
388
+ api.should_receive(:send_request).and_return(request_mock)
389
+ # to return fast from #send_api_request
390
+ request_mock.should_receive(:body).and_return("")
391
+ api.test_connection
392
+ }
393
+ it { api.last_http_response.should == request_mock }
340
394
  end
341
395
 
342
- context "differs #supported_versions" do
343
- before { api2.supported_versions << "x" }
344
- it { api.should_not == api2 }
396
+ describe "#last_xml_response" do
397
+ # we test this through a #test_connection call
398
+
399
+ let(:request_mock) { mock }
400
+ let(:expected_xml) { "<response><returncode>SUCCESS</returncode></response>" }
401
+ before {
402
+ api.should_receive(:get_url)
403
+ api.should_receive(:send_request).and_return(request_mock)
404
+ request_mock.should_receive(:body).at_least(1).and_return(expected_xml)
405
+ api.test_connection
406
+ }
407
+ it { api.last_xml_response.should == expected_xml }
345
408
  end
346
- end
347
409
 
348
- describe "#last_http_response" do
349
- # we test this through a #test_connection call
350
-
351
- let(:request_mock) { mock }
352
- before {
353
- api.should_receive(:get_url)
354
- # this return value will be stored in @http_response
355
- api.should_receive(:send_request).and_return(request_mock)
356
- # to return fast from #send_api_request
357
- request_mock.should_receive(:body).and_return("")
358
- api.test_connection
359
- }
360
- it { api.last_http_response.should == request_mock }
361
- end
410
+ describe "#get_url" do
362
411
 
363
- describe "#last_xml_response" do
364
- # we test this through a #test_connection call
365
-
366
- let(:request_mock) { mock }
367
- let(:expected_xml) { "<response><returncode>SUCCESS</returncode></response>" }
368
- before {
369
- api.should_receive(:get_url)
370
- api.should_receive(:send_request).and_return(request_mock)
371
- request_mock.should_receive(:body).at_least(1).and_return(expected_xml)
372
- api.test_connection
373
- }
374
- it { api.last_xml_response.should == expected_xml }
375
- end
412
+ context "when method = :index" do
413
+ it { api.get_url(:index).should == [api.url, nil] }
414
+ end
376
415
 
377
- describe "#get_url" do
416
+ context "when method = :check" do
417
+ it {
418
+ api.url = 'http://my-test-server.com/bigbluebutton/api'
419
+ api.get_url(:check).should == ['http://my-test-server.com/check', nil]
420
+ }
421
+ end
378
422
 
379
- context "when method = :index" do
380
- it { api.get_url(:index).should == api.url }
381
- end
423
+ context "when method != :index" do
424
+ context "validates the entire url" do
425
+ context "with params" do
426
+ let(:params) { { :param1 => "value1", :param2 => "value2" } }
427
+ subject { api.get_url(:join, params)[0] }
428
+ it {
429
+ # the hash can be sorted differently depending on the ruby version
430
+ if params.map{ |k,v| "#{k}" }.join =~ /^param1/
431
+ subject.should match(/#{url}\/join\?param1=value1&param2=value2/)
432
+ else
433
+ subject.should match(/#{url}\/join\?param2=value2&param1=value1/)
434
+ end
435
+ }
436
+ end
382
437
 
383
- context "when method != :index" do
384
- context "validates the entire url" do
385
- context "with params" do
386
- let(:params) { { :param1 => "value1", :param2 => "value2" } }
387
- subject { api.get_url(:join, params) }
438
+ context "without params" do
439
+ subject { api.get_url(:join)[0] }
440
+ it { subject.should match(/#{url}\/join\?[^&]/) }
441
+ end
442
+ end
443
+
444
+ context "when method = :setConfigXML" do
388
445
  it {
389
- # the hash can be sorted differently depending on the ruby version
390
- if params.map{ |k,v| "#{k}" }.join =~ /^param1/
391
- subject.should match(/#{url}\/join\?param1=value1&param2=value2/)
392
- else
393
- subject.should match(/#{url}\/join\?param2=value2&param1=value1/)
394
- end
446
+ api.url = 'http://my-test-server.com/bigbluebutton/api'
447
+ response = api.get_url(:setConfigXML, { param1: 1, param2: 2 })
448
+ response[0].should eql('http://my-test-server.com/bigbluebutton/api/setConfigXML')
449
+ response[1].should match(/checksum=.*&param1=1&param2=2/)
395
450
  }
396
451
  end
397
452
 
398
- context "without params" do
399
- subject { api.get_url(:join) }
400
- it { subject.should match(/#{url}\/join\?[^&]/) }
453
+ context "discards params with nil value" do
454
+ let(:params) { { :param1 => "value1", :param2 => nil } }
455
+ subject { api.get_url(:join, params)[0] }
456
+ it { subject.should_not match(/param2=/) }
401
457
  end
402
- end
403
458
 
404
- context "discards params with nil value" do
405
- let(:params) { { :param1 => "value1", :param2 => nil } }
406
- subject { api.get_url(:join, params) }
407
- it { subject.should_not match(/param2=/) }
408
- end
409
-
410
- context "escapes all params" do
411
- let(:params) { { :param1 => "value with spaces", :param2 => "@$" } }
412
- subject { api.get_url(:join, params) }
413
- it { subject.should match(/param1=value\+with\+spaces/) }
414
- it { subject.should match(/param2=%40%24/) }
415
- end
459
+ context "escapes all params" do
460
+ let(:params) { { :param1 => "value with spaces", :param2 => "@$" } }
461
+ subject { api.get_url(:join, params)[0] }
462
+ it { subject.should match(/param1=value\+with\+spaces/) }
463
+ it { subject.should match(/param2=%40%24/) }
464
+ end
416
465
 
417
- context "includes the checksum" do
418
- let(:params) { { :param1 => "value1", :param2 => "value2" } }
419
- let(:checksum) {
420
- # the hash can be sorted differently depending on the ruby version
421
- if params.map{ |k,v| "#{k}" }.join =~ /^param1/
422
- "67882ae54f49600f56f358c10d24697ef7d8c6b2"
423
- else
424
- "85a54e28e4ec18bfdcb214a73f74d35b09a84176"
466
+ [ [' ', '+'],
467
+ ['*', '*']
468
+ ].each do |values|
469
+ context "escapes #{values[0].inspect} as #{values[1].inspect}" do
470
+ let(:params) { { param1: "before#{values[0]}after" } }
471
+ subject { api.get_url(:join, params)[0] }
472
+ it { subject.should match(/param1=before#{Regexp.quote(values[1])}after/) }
425
473
  end
426
- }
427
- subject { api.get_url(:join, params) }
428
- it { subject.should match(/checksum=#{checksum}$/) }
474
+ end
475
+
476
+ context "includes the checksum" do
477
+ let(:params) { { :param1 => "value1", :param2 => "value2" } }
478
+ let(:checksum) {
479
+ # the hash can be sorted differently depending on the ruby version
480
+ if params.map{ |k,v| k }.join =~ /^param1/
481
+ "67882ae54f49600f56f358c10d24697ef7d8c6b2"
482
+ else
483
+ "85a54e28e4ec18bfdcb214a73f74d35b09a84176"
484
+ end
485
+ }
486
+ subject { api.get_url(:join, params)[0] }
487
+ it { subject.should match(/checksum=#{checksum}$/) }
488
+ end
429
489
  end
430
490
  end
431
- end
432
491
 
433
- describe "#send_api_request" do
434
- let(:method) { :join }
435
- let(:params) { { :param1 => "value1" } }
436
- let(:data) { "any data" }
437
- let(:url) { "http://test-server:8080?param1=value1&checksum=12345" }
438
- let(:make_request) { api.send_api_request(method, params, data) }
439
- let(:response_mock) { mock() } # mock of what send_request() would return
492
+ describe "#send_api_request" do
493
+ let(:method) { :join }
494
+ let(:params) { { :param1 => "value1" } }
495
+ let(:data) { "any data" }
496
+ let(:url) { "http://test-server:8080?param1=value1&checksum=12345" }
497
+ let(:make_request) { api.send_api_request(method, params, data) }
498
+ let(:response_mock) { mock() } # mock of what send_request() would return
440
499
 
441
- before { api.should_receive(:get_url).with(method, params).and_return(url) }
500
+ before { api.should_receive(:get_url).with(method, params).and_return([url, nil]) }
442
501
 
443
- context "returns an empty hash if the response body is empty" do
444
- before do
445
- api.should_receive(:send_request).with(url, data).and_return(response_mock)
446
- response_mock.should_receive(:body).and_return("")
502
+ context "returns an empty hash if the response body is empty" do
503
+ before do
504
+ api.should_receive(:send_request).with(url, data).and_return(response_mock)
505
+ response_mock.should_receive(:body).and_return("")
506
+ end
507
+ it { make_request.should == { } }
447
508
  end
448
- it { make_request.should == { } }
449
- end
450
509
 
451
- context "hashfies and validates the response body" do
452
- before do
453
- api.should_receive(:send_request).with(url, data).and_return(response_mock)
454
- response_mock.should_receive(:body).twice.and_return("response-body")
510
+ context "hashfies and validates the response body" do
511
+ before do
512
+ api.should_receive(:send_request).with(url, data).and_return(response_mock)
513
+ response_mock.should_receive(:body).twice.and_return("response-body")
514
+ end
515
+
516
+ context "checking if it has a :response key" do
517
+ before { BigBlueButton::BigBlueButtonHash.should_receive(:from_xml).with("response-body").and_return({ }) }
518
+ it { expect { make_request }.to raise_error(BigBlueButton::BigBlueButtonException) }
519
+ end
520
+
521
+ context "checking if it the :response key has a :returncode key" do
522
+ before { BigBlueButton::BigBlueButtonHash.should_receive(:from_xml).with("response-body").and_return({ :response => { } }) }
523
+ it { expect { make_request }.to raise_error(BigBlueButton::BigBlueButtonException) }
524
+ end
455
525
  end
456
526
 
457
- context "checking if it has a :response key" do
458
- before { BigBlueButton::BigBlueButtonHash.should_receive(:from_xml).with("response-body").and_return({ }) }
459
- it { expect { make_request }.to raise_error(BigBlueButton::BigBlueButtonException) }
527
+ context "formats the response hash" do
528
+ let(:response) { { :returncode => "SUCCESS" } }
529
+ let(:formatted_response) { { :returncode => true, :messageKey => "", :message => "" } }
530
+ before do
531
+ api.should_receive(:send_request).with(url, data).and_return(response_mock)
532
+ response_mock.should_receive(:body).twice.and_return("response-body")
533
+ BigBlueButton::BigBlueButtonHash.should_receive(:from_xml).with("response-body").and_return(response)
534
+
535
+ # here starts the validation
536
+ # doesn't test the resulting format, only that the formatter was called
537
+ formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter)
538
+ BigBlueButton::BigBlueButtonFormatter.should_receive(:new).with(response).and_return(formatter_mock)
539
+ formatter_mock.should_receive(:default_formatting).and_return(formatted_response)
540
+ end
541
+ it { make_request }
460
542
  end
461
543
 
462
- context "checking if it the :response key has a :returncode key" do
463
- before { BigBlueButton::BigBlueButtonHash.should_receive(:from_xml).with("response-body").and_return({ :response => { } }) }
544
+ context "raise an error if the formatted response has no :returncode" do
545
+ let(:response) { { :returncode => true } }
546
+ let(:formatted_response) { { } }
547
+ before do
548
+ api.should_receive(:send_request).with(url, data).and_return(response_mock)
549
+ response_mock.should_receive(:body).twice.and_return("response-body")
550
+ BigBlueButton::BigBlueButtonHash.should_receive(:from_xml).with("response-body").and_return(response)
551
+
552
+ formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter)
553
+ BigBlueButton::BigBlueButtonFormatter.should_receive(:new).with(response).and_return(formatter_mock)
554
+ formatter_mock.should_receive(:default_formatting).and_return(formatted_response)
555
+ end
464
556
  it { expect { make_request }.to raise_error(BigBlueButton::BigBlueButtonException) }
465
557
  end
466
558
  end
467
559
 
468
- context "formats the response hash" do
469
- let(:response) { { :returncode => "SUCCESS" } }
470
- let(:formatted_response) { { :returncode => true, :messageKey => "", :message => "" } }
471
- before do
472
- api.should_receive(:send_request).with(url, data).and_return(response_mock)
473
- response_mock.should_receive(:body).twice.and_return("response-body")
474
- BigBlueButton::BigBlueButtonHash.should_receive(:from_xml).with("response-body").and_return(response)
475
-
476
- # here starts the validation
477
- # doesn't test the resulting format, only that the formatter was called
478
- formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter)
479
- BigBlueButton::BigBlueButtonFormatter.should_receive(:new).with(response).and_return(formatter_mock)
480
- formatter_mock.should_receive(:default_formatting).and_return(formatted_response)
481
- end
482
- it { make_request }
483
- end
560
+ describe "#send_request" do
561
+ let(:url) { "http://test-server:8080/res?param1=value1&checksum=12345" }
562
+ let(:url_parsed) { URI.parse(url) }
563
+ let(:res) { Net::HTTPResponse.new(1.0, '200', 'OK') }
484
564
 
485
- context "raise an error if the formatted response has no :returncode" do
486
- let(:response) { { :returncode => true } }
487
- let(:formatted_response) { { } }
488
565
  before do
489
- api.should_receive(:send_request).with(url, data).and_return(response_mock)
490
- response_mock.should_receive(:body).twice.and_return("response-body")
491
- BigBlueButton::BigBlueButtonHash.should_receive(:from_xml).with("response-body").and_return(response)
492
-
493
- formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter)
494
- BigBlueButton::BigBlueButtonFormatter.should_receive(:new).with(response).and_return(formatter_mock)
495
- formatter_mock.should_receive(:default_formatting).and_return(formatted_response)
566
+ @http_mock = mock(Net::HTTP)
567
+ @http_mock.should_receive(:"open_timeout=").with(api.timeout)
568
+ @http_mock.should_receive(:"read_timeout=").with(api.timeout)
569
+ Net::HTTP.should_receive(:new).with("test-server", 8080).and_return(@http_mock)
570
+ res.stub(:body) { "ok" }
496
571
  end
497
- it { expect { make_request }.to raise_error(BigBlueButton::BigBlueButtonException) }
498
- end
499
- end
500
572
 
501
- describe "#send_request" do
502
- let(:url) { "http://test-server:8080/res?param1=value1&checksum=12345" }
503
- let(:url_parsed) { URI.parse(url) }
573
+ context "standard case" do
574
+ before { @http_mock.should_receive(:get).with("/res?param1=value1&checksum=12345", {}).and_return(res) }
575
+ it { api.send(:send_request, url).should == res }
576
+ end
504
577
 
505
- before do
506
- @http_mock = mock(Net::HTTP)
507
- @http_mock.should_receive(:"open_timeout=").with(api.timeout)
508
- @http_mock.should_receive(:"read_timeout=").with(api.timeout)
509
- Net::HTTP.should_receive(:new).with("test-server", 8080).and_return(@http_mock)
510
- end
578
+ context "handles a TimeoutError" do
579
+ before { @http_mock.should_receive(:get) { raise TimeoutError } }
580
+ it { expect { api.send(:send_request, url) }.to raise_error(BigBlueButton::BigBlueButtonException) }
581
+ end
511
582
 
512
- context "standard case" do
513
- before { @http_mock.should_receive(:get).with("/res?param1=value1&checksum=12345", {}).and_return("ok") }
514
- it { api.send(:send_request, url).should == "ok" }
515
- end
583
+ context "handles general Exceptions" do
584
+ before { @http_mock.should_receive(:get) { raise Exception } }
585
+ it { expect { api.send(:send_request, url) }.to raise_error(BigBlueButton::BigBlueButtonException) }
586
+ end
516
587
 
517
- context "handles a TimeoutError" do
518
- before { @http_mock.should_receive(:get) { raise TimeoutError } }
519
- it { expect { api.send(:send_request, url) }.to raise_error(BigBlueButton::BigBlueButtonException) }
520
- end
588
+ context "post with data" do
589
+ let(:data) { "any data" }
590
+ before {
591
+ path = "/res?param1=value1&checksum=12345"
592
+ opts = { 'Content-Type' => 'application/xml' }
593
+ @http_mock.should_receive(:post).with(path, data, opts).and_return(res)
594
+ }
595
+ it {
596
+ api.send(:send_request, url, data).should == res
597
+ }
598
+ end
521
599
 
522
- context "handles general Exceptions" do
523
- before { @http_mock.should_receive(:get) { raise Exception } }
524
- it { expect { api.send(:send_request, url) }.to raise_error(BigBlueButton::BigBlueButtonException) }
525
- end
600
+ context "get with headers" do
601
+ let(:headers_hash) { { :anything => "anything" } }
602
+ before { @http_mock.should_receive(:get).with("/res?param1=value1&checksum=12345", headers_hash).and_return(res) }
603
+ it {
604
+ api.request_headers = headers_hash
605
+ api.send(:send_request, url).should == res
606
+ }
607
+ end
526
608
 
527
- context "post with data" do
528
- let(:data) { "any data" }
529
- before {
530
- path = "/res?param1=value1&checksum=12345"
531
- opts = { 'Content-Type' => 'text/xml' }
532
- @http_mock.should_receive(:post).with(path, data, opts).and_return("ok")
533
- }
534
- it {
535
- api.send(:send_request, url, data).should == "ok"
536
- }
609
+ context "get with headers" do
610
+ let(:headers_hash) { { :anything => "anything" } }
611
+ let(:data) { "any data" }
612
+ before {
613
+ path = "/res?param1=value1&checksum=12345"
614
+ opts = { 'Content-Type' => 'application/xml', :anything => "anything" }
615
+ @http_mock.should_receive(:post).with(path, data, opts).and_return(res)
616
+ }
617
+ it {
618
+ api.request_headers = headers_hash
619
+ api.send(:send_request, url, data).should == res
620
+ }
621
+ end
537
622
  end
538
623
 
539
- context "get with headers" do
540
- let(:headers_hash) { { :anything => "anything" } }
541
- before { @http_mock.should_receive(:get).with("/res?param1=value1&checksum=12345", headers_hash).and_return("ok") }
542
- it {
543
- api.request_headers = headers_hash
544
- api.send(:send_request, url).should == "ok"
624
+ describe "#get_recordings" do
625
+ let(:recording1) { { :recordID => "id1", :meetindID => "meeting-id" } } # simplified "recording" node in the response
626
+ let(:recording2) { { :recordID => "id2", :meetindID => "meeting-id" } }
627
+ let(:response) {
628
+ { :returncode => true, :recordings => { :recording => [ recording1, recording2 ] }, :messageKey => "mkey", :message => "m" }
545
629
  }
546
- end
630
+ let(:flattened_response) {
631
+ { :returncode => true, :recordings => [ recording1, recording2 ], :messageKey => "mkey", :message => "m" }
632
+ } # hash *after* the flatten_objects call
547
633
 
548
- context "get with headers" do
549
- let(:headers_hash) { { :anything => "anything" } }
550
- let(:data) { "any data" }
551
- before {
552
- path = "/res?param1=value1&checksum=12345"
553
- opts = { 'Content-Type' => 'text/xml', :anything => "anything" }
554
- @http_mock.should_receive(:post).with(path, data, opts).and_return("ok")
555
- }
556
- it {
557
- api.request_headers = headers_hash
558
- api.send(:send_request, url, data).should == "ok"
559
- }
560
- end
561
- end
634
+ context "accepts non standard options" do
635
+ let(:params) { { :meetingID => "meeting-id", :nonStandard => 1 } }
636
+ before { api.should_receive(:send_api_request).with(:getRecordings, params).and_return(response) }
637
+ it { api.get_recordings(params) }
638
+ end
562
639
 
563
- describe "#get_recordings" do
564
- let(:recording1) { { :recordID => "id1", :meetindID => "meeting-id" } } # simplified "recording" node in the response
565
- let(:recording2) { { :recordID => "id2", :meetindID => "meeting-id" } }
566
- let(:response) {
567
- { :returncode => true, :recordings => { :recording => [ recording1, recording2 ] }, :messageKey => "mkey", :message => "m" }
568
- }
569
- let(:flattened_response) {
570
- { :returncode => true, :recordings => [ recording1, recording2 ], :messageKey => "mkey", :message => "m" }
571
- } # hash *after* the flatten_objects call
572
-
573
- context "accepts non standard options" do
574
- let(:params) { { :meetingID => "meeting-id", :nonStandard => 1 } }
575
- before { api.should_receive(:send_api_request).with(:getRecordings, params).and_return(response) }
576
- it { api.get_recordings(params) }
577
- end
640
+ context "without meeting ID" do
641
+ before { api.should_receive(:send_api_request).with(:getRecordings, {}).and_return(response) }
642
+ it { api.get_recordings.should == response }
643
+ end
578
644
 
579
- context "without meeting ID" do
580
- before { api.should_receive(:send_api_request).with(:getRecordings, {}).and_return(response) }
581
- it { api.get_recordings.should == response }
582
- end
645
+ context "with one meeting ID" do
646
+ context "in an array" do
647
+ let(:options) { { :meetingID => ["meeting-id"] } }
648
+ let(:req_params) { { :meetingID => "meeting-id" } }
649
+ before { api.should_receive(:send_api_request).with(:getRecordings, req_params).and_return(response) }
650
+ it { api.get_recordings(options).should == response }
651
+ end
583
652
 
584
- context "with one meeting ID" do
585
- context "in an array" do
586
- let(:options) { { :meetingID => ["meeting-id"] } }
587
- let(:req_params) { { :meetingID => "meeting-id" } }
588
- before { api.should_receive(:send_api_request).with(:getRecordings, req_params).and_return(response) }
589
- it { api.get_recordings(options).should == response }
653
+ context "in a string" do
654
+ let(:options) { { :meetingID => "meeting-id" } }
655
+ let(:req_params) { { :meetingID => "meeting-id" } }
656
+ before { api.should_receive(:send_api_request).with(:getRecordings, req_params).and_return(response) }
657
+ it { api.get_recordings(options).should == response }
658
+ end
590
659
  end
591
660
 
592
- context "in a string" do
593
- let(:options) { { :meetingID => "meeting-id" } }
594
- let(:req_params) { { :meetingID => "meeting-id" } }
595
- before { api.should_receive(:send_api_request).with(:getRecordings, req_params).and_return(response) }
596
- it { api.get_recordings(options).should == response }
597
- end
598
- end
661
+ context "with several meeting IDs" do
662
+ context "in an array" do
663
+ let(:options) { { :meetingID => ["meeting-id-1", "meeting-id-2"] } }
664
+ let(:req_params) { { :meetingID => "meeting-id-1,meeting-id-2" } }
665
+ before { api.should_receive(:send_api_request).with(:getRecordings, req_params).and_return(response) }
666
+ it { api.get_recordings(options).should == response }
667
+ end
599
668
 
600
- context "with several meeting IDs" do
601
- context "in an array" do
602
- let(:options) { { :meetingID => ["meeting-id-1", "meeting-id-2"] } }
603
- let(:req_params) { { :meetingID => "meeting-id-1,meeting-id-2" } }
604
- before { api.should_receive(:send_api_request).with(:getRecordings, req_params).and_return(response) }
605
- it { api.get_recordings(options).should == response }
669
+ context "in a string" do
670
+ let(:options) { { :meetingID => "meeting-id-1,meeting-id-2" } }
671
+ let(:req_params) { { :meetingID => "meeting-id-1,meeting-id-2" } }
672
+ before { api.should_receive(:send_api_request).with(:getRecordings, req_params).and_return(response) }
673
+ it { api.get_recordings(options).should == response }
674
+ end
606
675
  end
607
676
 
608
- context "in a string" do
609
- let(:options) { { :meetingID => "meeting-id-1,meeting-id-2" } }
610
- let(:req_params) { { :meetingID => "meeting-id-1,meeting-id-2" } }
611
- before { api.should_receive(:send_api_request).with(:getRecordings, req_params).and_return(response) }
612
- it { api.get_recordings(options).should == response }
677
+ context "formats the response" do
678
+ before {
679
+ api.should_receive(:send_api_request).with(:getRecordings, anything).and_return(flattened_response)
680
+ formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter)
681
+ formatter_mock.should_receive(:flatten_objects).with(:recordings, :recording)
682
+ BigBlueButton::BigBlueButtonFormatter.should_receive(:format_recording).with(recording1)
683
+ BigBlueButton::BigBlueButtonFormatter.should_receive(:format_recording).with(recording2)
684
+ BigBlueButton::BigBlueButtonFormatter.should_receive(:new).and_return(formatter_mock)
685
+ }
686
+ it { api.get_recordings }
613
687
  end
614
688
  end
615
689
 
616
- context "formats the response" do
617
- before {
618
- api.should_receive(:send_api_request).with(:getRecordings, anything).and_return(flattened_response)
619
- formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter)
620
- formatter_mock.should_receive(:flatten_objects).with(:recordings, :recording)
621
- BigBlueButton::BigBlueButtonFormatter.should_receive(:format_recording).with(recording1)
622
- BigBlueButton::BigBlueButtonFormatter.should_receive(:format_recording).with(recording2)
623
- BigBlueButton::BigBlueButtonFormatter.should_receive(:new).and_return(formatter_mock)
624
- }
625
- it { api.get_recordings }
626
- end
627
- end
628
-
629
- describe "#publish_recordings" do
630
-
631
- context "publish is converted to string" do
632
- let(:recordIDs) { "any" }
633
- let(:req_params) { { :publish => "false", :recordID => "any" } }
634
- before { api.should_receive(:send_api_request).with(:publishRecordings, req_params) }
635
- it { api.publish_recordings(recordIDs, false) }
636
- end
690
+ describe "#publish_recordings" do
637
691
 
638
- context "with one recording ID" do
639
- context "in an array" do
640
- let(:recordIDs) { ["id-1"] }
641
- let(:req_params) { { :publish => "true", :recordID => "id-1" } }
692
+ context "publish is converted to string" do
693
+ let(:recordIDs) { "any" }
694
+ let(:req_params) { { :publish => "false", :recordID => "any" } }
642
695
  before { api.should_receive(:send_api_request).with(:publishRecordings, req_params) }
643
- it { api.publish_recordings(recordIDs, true) }
696
+ it { api.publish_recordings(recordIDs, false) }
644
697
  end
645
698
 
646
- context "in a string" do
647
- let(:recordIDs) { "id-1" }
648
- let(:req_params) { { :publish => "true", :recordID => "id-1" } }
649
- before { api.should_receive(:send_api_request).with(:publishRecordings, req_params) }
650
- it { api.publish_recordings(recordIDs, true) }
699
+ context "with one recording ID" do
700
+ context "in an array" do
701
+ let(:recordIDs) { ["id-1"] }
702
+ let(:req_params) { { :publish => "true", :recordID => "id-1" } }
703
+ before { api.should_receive(:send_api_request).with(:publishRecordings, req_params) }
704
+ it { api.publish_recordings(recordIDs, true) }
705
+ end
706
+
707
+ context "in a string" do
708
+ let(:recordIDs) { "id-1" }
709
+ let(:req_params) { { :publish => "true", :recordID => "id-1" } }
710
+ before { api.should_receive(:send_api_request).with(:publishRecordings, req_params) }
711
+ it { api.publish_recordings(recordIDs, true) }
712
+ end
651
713
  end
652
- end
653
714
 
654
- context "with several recording IDs" do
655
- context "in an array" do
656
- let(:recordIDs) { ["id-1", "id-2"] }
657
- let(:req_params) { { :publish => "true", :recordID => "id-1,id-2" } }
658
- before { api.should_receive(:send_api_request).with(:publishRecordings, req_params) }
659
- it { api.publish_recordings(recordIDs, true) }
715
+ context "with several recording IDs" do
716
+ context "in an array" do
717
+ let(:recordIDs) { ["id-1", "id-2"] }
718
+ let(:req_params) { { :publish => "true", :recordID => "id-1,id-2" } }
719
+ before { api.should_receive(:send_api_request).with(:publishRecordings, req_params) }
720
+ it { api.publish_recordings(recordIDs, true) }
721
+ end
722
+
723
+ context "in a string" do
724
+ let(:recordIDs) { "id-1,id-2,id-3" }
725
+ let(:req_params) { { :publish => "true", :recordID => "id-1,id-2,id-3" } }
726
+ before { api.should_receive(:send_api_request).with(:publishRecordings, req_params) }
727
+ it { api.publish_recordings(recordIDs, true) }
728
+ end
660
729
  end
661
730
 
662
- context "in a string" do
663
- let(:recordIDs) { "id-1,id-2,id-3" }
664
- let(:req_params) { { :publish => "true", :recordID => "id-1,id-2,id-3" } }
665
- before { api.should_receive(:send_api_request).with(:publishRecordings, req_params) }
666
- it { api.publish_recordings(recordIDs, true) }
731
+ context "accepts non standard options" do
732
+ let(:recordIDs) { ["id-1"] }
733
+ let(:params_in) {
734
+ { :anything1 => "anything-1", :anything2 => 2 }
735
+ }
736
+ let(:params_out) {
737
+ { :publish => "true", :recordID => "id-1",
738
+ :anything1 => "anything-1", :anything2 => 2 }
739
+ }
740
+ before { api.should_receive(:send_api_request).with(:publishRecordings, params_out) }
741
+ it { api.publish_recordings(recordIDs, true, params_in) }
667
742
  end
668
743
  end
669
744
 
670
- context "accepts non standard options" do
671
- let(:recordIDs) { ["id-1"] }
672
- let(:params_in) {
673
- { :anything1 => "anything-1", :anything2 => 2 }
674
- }
675
- let(:params_out) {
676
- { :publish => "true", :recordID => "id-1",
677
- :anything1 => "anything-1", :anything2 => 2 }
678
- }
679
- before { api.should_receive(:send_api_request).with(:publishRecordings, params_out) }
680
- it { api.publish_recordings(recordIDs, true, params_in) }
681
- end
682
- end
745
+ describe "#delete_recordings" do
683
746
 
684
- describe "#delete_recordings" do
747
+ context "with one recording ID" do
748
+ context "in an array" do
749
+ let(:recordIDs) { ["id-1"] }
750
+ let(:req_params) { { :recordID => "id-1" } }
751
+ before { api.should_receive(:send_api_request).with(:deleteRecordings, req_params) }
752
+ it { api.delete_recordings(recordIDs) }
753
+ end
685
754
 
686
- context "with one recording ID" do
687
- context "in an array" do
688
- let(:recordIDs) { ["id-1"] }
689
- let(:req_params) { { :recordID => "id-1" } }
690
- before { api.should_receive(:send_api_request).with(:deleteRecordings, req_params) }
691
- it { api.delete_recordings(recordIDs) }
755
+ context "in a string" do
756
+ let(:recordIDs) { "id-1" }
757
+ let(:req_params) { { :recordID => "id-1" } }
758
+ before { api.should_receive(:send_api_request).with(:deleteRecordings, req_params) }
759
+ it { api.delete_recordings(recordIDs) }
760
+ end
692
761
  end
693
762
 
694
- context "in a string" do
695
- let(:recordIDs) { "id-1" }
696
- let(:req_params) { { :recordID => "id-1" } }
697
- before { api.should_receive(:send_api_request).with(:deleteRecordings, req_params) }
698
- it { api.delete_recordings(recordIDs) }
699
- end
700
- end
763
+ context "with several recording IDs" do
764
+ context "in an array" do
765
+ let(:recordIDs) { ["id-1", "id-2"] }
766
+ let(:req_params) { { :recordID => "id-1,id-2" } }
767
+ before { api.should_receive(:send_api_request).with(:deleteRecordings, req_params) }
768
+ it { api.delete_recordings(recordIDs) }
769
+ end
701
770
 
702
- context "with several recording IDs" do
703
- context "in an array" do
704
- let(:recordIDs) { ["id-1", "id-2"] }
705
- let(:req_params) { { :recordID => "id-1,id-2" } }
706
- before { api.should_receive(:send_api_request).with(:deleteRecordings, req_params) }
707
- it { api.delete_recordings(recordIDs) }
771
+ context "in a string" do
772
+ let(:recordIDs) { "id-1,id-2,id-3" }
773
+ let(:req_params) { { :recordID => "id-1,id-2,id-3" } }
774
+ before { api.should_receive(:send_api_request).with(:deleteRecordings, req_params) }
775
+ it { api.delete_recordings(recordIDs) }
776
+ end
708
777
  end
709
778
 
710
- context "in a string" do
711
- let(:recordIDs) { "id-1,id-2,id-3" }
712
- let(:req_params) { { :recordID => "id-1,id-2,id-3" } }
713
- before { api.should_receive(:send_api_request).with(:deleteRecordings, req_params) }
714
- it { api.delete_recordings(recordIDs) }
779
+ context "accepts non standard options" do
780
+ let(:recordIDs) { ["id-1"] }
781
+ let(:params_in) {
782
+ { :anything1 => "anything-1", :anything2 => 2 }
783
+ }
784
+ let(:params_out) {
785
+ { :recordID => "id-1", :anything1 => "anything-1", :anything2 => 2 }
786
+ }
787
+ before { api.should_receive(:send_api_request).with(:deleteRecordings, params_out) }
788
+ it { api.delete_recordings(recordIDs, params_in) }
715
789
  end
716
790
  end
717
-
718
- context "accepts non standard options" do
719
- let(:recordIDs) { ["id-1"] }
720
- let(:params_in) {
721
- { :anything1 => "anything-1", :anything2 => 2 }
722
- }
723
- let(:params_out) {
724
- { :recordID => "id-1", :anything1 => "anything-1", :anything2 => 2 }
725
- }
726
- before { api.should_receive(:send_api_request).with(:deleteRecordings, params_out) }
727
- it { api.delete_recordings(recordIDs, params_in) }
728
- end
729
791
  end
730
792
 
793
+ it_should_behave_like "BigBlueButtonApi", "0.8"
794
+ it_should_behave_like "BigBlueButtonApi", "0.81"
795
+ it_should_behave_like "BigBlueButtonApi", "0.9"
796
+ it_should_behave_like "BigBlueButtonApi", "1.0"
731
797
  end