bigbluebutton-api-ruby 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,14 @@
1
+ == 0.0.10
2
+
3
+ * Returning hash now will *always* have these 3 values: :returncode (boolean), :messageKey (string) and :message (string).
4
+ * Some values in the hash are now converted to a fixed variable type to avoid inconsistencies:
5
+ * :meetingID (string)
6
+ * :attendeePW (string)
7
+ * :moderatorPW (string)
8
+ * :running (boolean)
9
+ * :hasBeenForciblyEnded (boolean)
10
+ * :endTime and :startTime (DateTime or nil)
11
+
1
12
  == 0.0.9
2
13
 
3
14
  * Simplied "attendees" part of the hash returned in get_meeting_info. Same thing done for get_meetings.
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'bigbluebutton-api-ruby'
5
- s.version = '0.0.9'
5
+ s.version = '0.0.10'
6
6
  s.extra_rdoc_files = ['README.rdoc', 'LICENSE', 'CHANGELOG.rdoc']
7
7
  s.summary = 'Provides an interface to the BigBlueButton web meeting API (https://github.com/mconf/bigbluebutton-api-ruby)'
8
8
  s.description = s.summary
@@ -44,6 +44,18 @@ module BigBlueButton
44
44
  #
45
45
  # TODO: Automatically detect API version using request to index - added in 0.7
46
46
  #
47
+ # Considerations about the returning hash:
48
+ # * The XML returned by BBB is converted to a Hash. See the desired method's documentation for examples.
49
+ # * Three values will *always* exist in the hash: :returncode (boolean), :messageKey (string) and :message (string)
50
+ # * Some of the values returned by BBB are converted to better represent the data. Some of these are listed
51
+ # bellow. They will *always* have the type informed:
52
+ # * :meetingID (string)
53
+ # * :attendeePW (string)
54
+ # * :moderatorPW (string)
55
+ # * :running (boolean)
56
+ # * :hasBeenForciblyEnded (boolean)
57
+ # * :endTime and :startTime (DateTime or nil)
58
+ #
47
59
  class BigBlueButtonApi
48
60
 
49
61
  attr_accessor :url, :supported_versions, :salt, :version, :debug
@@ -113,22 +125,22 @@ module BigBlueButton
113
125
  # On successful creation:
114
126
  #
115
127
  # {
116
- # :returncode=>"SUCCESS", :meetingID=>"bigbluebutton-api-ruby-test",
117
- # :attendeePW=>1234, :moderatorPW=>4321, :hasBeenForciblyEnded=>"false",
118
- # :messageKey=>{}, :message=>{}
128
+ # :returncode=>true, :meetingID=>"bigbluebutton-api-ruby-test",
129
+ # :attendeePW=>"1234", :moderatorPW=>"4321", :hasBeenForciblyEnded=>false,
130
+ # :messageKey=>"", :message=>""
119
131
  # }
120
132
  #
121
- # Meeting that was just forcibly ended:
133
+ # Meeting that was forcibly ended:
122
134
  #
123
135
  # {
124
- # :returncode=>"SUCCESS", :meetingID=>"bigbluebutton-api-ruby-test",
125
- # :attendeePW=>1234, :moderatorPW=>4321, :hasBeenForciblyEnded=>"true",
136
+ # :returncode=>true, :meetingID=>"bigbluebutton-api-ruby-test",
137
+ # :attendeePW=>"1234", :moderatorPW=>"4321", :hasBeenForciblyEnded=>true,
126
138
  # :messageKey=>"duplicateWarning",
127
139
  # :message=>"This conference was already in existence and may currently be in progress."
128
140
  # }
129
141
  #
130
142
  # TODO check if voice_bridge exists in 0.64
131
- def create_meeting(meeting_name, meeting_id, moderator_password, attendee_password,
143
+ def create_meeting(meeting_name, meeting_id, moderator_password = nil, attendee_password = nil,
132
144
  welcome_message = nil, dial_number = nil, logout_url = nil,
133
145
  max_participants = nil, voice_bridge = nil)
134
146
 
@@ -137,7 +149,15 @@ module BigBlueButton
137
149
  :welcome => welcome_message, :dialNumber => dial_number,
138
150
  :logoutURL => logout_url, :maxParticpants => max_participants }
139
151
  params[:voiceBridge] = voice_bridge if @version == '0.7'
140
- send_api_request(:create, params)
152
+
153
+ response = send_api_request(:create, params)
154
+
155
+ response[:meetingID] = response[:meetingID].to_s
156
+ response[:moderatorPW] = response[:moderatorPW].to_s
157
+ response[:attendeePW] = response[:attendeePW].to_s
158
+ response[:hasBeenForciblyEnded] = response[:hasBeenForciblyEnded].downcase == "true"
159
+
160
+ response
141
161
  end
142
162
 
143
163
  # Ends an existing meeting. Throws BigBlueButtonException on failure.
@@ -149,7 +169,7 @@ module BigBlueButton
149
169
  # On success:
150
170
  #
151
171
  # {
152
- # :returncode=>"SUCCESS", :messageKey=>"sentEndMeetingRequest",
172
+ # :returncode=>true, :messageKey=>"sentEndMeetingRequest",
153
173
  # :message=>"A request to end the meeting was sent. Please wait a few seconds, and then use the getMeetingInfo
154
174
  # or isMeetingRunning API calls to verify that it was ended."
155
175
  # }
@@ -163,7 +183,7 @@ module BigBlueButton
163
183
  # meeting_id:: Unique identifier for the meeting
164
184
  def is_meeting_running?(meeting_id)
165
185
  hash = send_api_request(:isMeetingRunning, { :meetingID => meeting_id } )
166
- hash[:running] == "true"
186
+ hash[:running].downcase == "true"
167
187
  end
168
188
 
169
189
  # Warning: As of this version of the gem, this call does not work
@@ -201,22 +221,22 @@ module BigBlueButton
201
221
  # With attendees:
202
222
  #
203
223
  # {
204
- # :returncode=>"SUCCESS", :meetingID=>"bigbluebutton-api-ruby-test", :attendeePW=>1234, :moderatorPW=>4321, :running=>"true",
205
- # :hasBeenForciblyEnded=>"false", :startTime=>"Wed Apr 06 17:09:57 UTC 2011", :endTime=>"null", :participantCount=>4, :moderatorCount=>2,
224
+ # :returncode=>true, :meetingID=>"bigbluebutton-api-ruby-test", :attendeePW=>"1234", :moderatorPW=>"4321", :running=>true,
225
+ # :hasBeenForciblyEnded=>false, :startTime=>DateTime("Wed Apr 06 17:09:57 UTC 2011"), :endTime=>nil, :participantCount=>4, :moderatorCount=>2,
206
226
  # :attendees => [
207
- # {:userID=>"ndw1fnaev0rj", :fullName=>"House M.D.", :role=>"MODERATOR"},
208
- # {:userID=>"gn9e22b7ynna", :fullName=>"Dexter Morgan", :role=>"MODERATOR"},
209
- # {:userID=>"llzihbndryc3", :fullName=>"Cameron Palmer", :role=>"VIEWER"},
210
- # {:userID=>"rbepbovolsxt", :fullName=>"Trinity", :role=>"VIEWER"}
211
- # ], :messageKey=>{}, :message=>{}
227
+ # {:userID=>"ndw1fnaev0rj", :fullName=>"House M.D.", :role=>:moderator},
228
+ # {:userID=>"gn9e22b7ynna", :fullName=>"Dexter Morgan", :role=>:moderator},
229
+ # {:userID=>"llzihbndryc3", :fullName=>"Cameron Palmer", :role=>:viewer},
230
+ # {:userID=>"rbepbovolsxt", :fullName=>"Trinity", :role=>:viewer}
231
+ # ], :messageKey=>"", :message=>""
212
232
  # }
213
233
  #
214
234
  # Without attendees (not started):
215
235
  #
216
236
  # {
217
- # :returncode=>"SUCCESS", :meetingID=>"bigbluebutton-api-ruby-test", :attendeePW=>1234, :moderatorPW=>4321, :running=>"false",
218
- # :hasBeenForciblyEnded=>"false", :startTime=>"null", :endTime=>"null", :participantCount=>0, :moderatorCount=>0,
219
- # :attendees=>[], :messageKey=>{ }, :message=>{ }
237
+ # :returncode=>true, :meetingID=>"bigbluebutton-api-ruby-test", :attendeePW=>"1234", :moderatorPW=>"4321", :running=>false,
238
+ # :hasBeenForciblyEnded=>false, :startTime=>nil, :endTime=>nil, :participantCount=>0, :moderatorCount=>0,
239
+ # :attendees=>[], :messageKey=>"", :message=>""
220
240
  # }
221
241
  #
222
242
  def get_meeting_info(meeting_id, password)
@@ -224,17 +244,28 @@ module BigBlueButton
224
244
 
225
245
  # simplify the hash making a node :attendees with an array with all attendees
226
246
  if response[:attendees].empty?
227
- meetings = []
247
+ attendees = []
228
248
  else
229
249
  node = response[:attendees][:attendee]
230
250
  if node.kind_of?(Array)
231
- meetings = node
251
+ attendees = node
232
252
  else
233
- meetings = []
234
- meetings << node
253
+ attendees = []
254
+ attendees << node
235
255
  end
236
256
  end
237
- response[:attendees] = meetings
257
+ response[:attendees] = attendees
258
+ response[:attendees].each { |att| att[:role] = att[:role].downcase.to_sym }
259
+
260
+ response[:meetingID] = response[:meetingID].to_s
261
+ response[:moderatorPW] = response[:moderatorPW].to_s
262
+ response[:attendeePW] = response[:attendeePW].to_s
263
+ response[:hasBeenForciblyEnded] = response[:hasBeenForciblyEnded].downcase == "true"
264
+ response[:running] = response[:running].downcase == "true"
265
+ response[:startTime] = response[:startTime].downcase == "null" ?
266
+ nil : DateTime.parse(response[:startTime])
267
+ response[:endTime] = response[:endTime].downcase == "null" ?
268
+ nil : DateTime.parse(response[:endTime])
238
269
 
239
270
  response
240
271
  end
@@ -246,16 +277,17 @@ module BigBlueButton
246
277
  #
247
278
  # Server with one or more meetings:
248
279
  #
249
- # { :returncode => "SUCCESS",
280
+ # { :returncode => true,
250
281
  # :meetings => [
251
- # {:meetingID=>"Demo Meeting", :attendeePW=>"ap", :moderatorPW=>"mp", :hasBeenForciblyEnded=>"false", :running=>"true"},
252
- # {:meetingID=>"I was ended Meeting", :attendeePW=>"pass", :moderatorPW=>"pass", :hasBeenForciblyEnded=>"true", :running=>"false"}
253
- # ]
282
+ # {:meetingID=>"Demo Meeting", :attendeePW=>"ap", :moderatorPW=>"mp", :hasBeenForciblyEnded=>false, :running=>true},
283
+ # {:meetingID=>"I was ended Meeting", :attendeePW=>"pass", :moderatorPW=>"pass", :hasBeenForciblyEnded=>true, :running=>false}
284
+ # ],
285
+ # :messageKey=>"", :message=>""
254
286
  # }
255
287
  #
256
288
  # Server with no meetings:
257
289
  #
258
- # {:returncode=>"SUCCESS", :meetings=>[], :messageKey=>"noMeetings", :message=>"no meetings were found on this server"}
290
+ # {:returncode=>true, :meetings=>[], :messageKey=>"noMeetings", :message=>"no meetings were found on this server"}
259
291
  #
260
292
  def get_meetings
261
293
  response = send_api_request(:getMeetings, { :random => rand(9999999999) } )
@@ -274,6 +306,14 @@ module BigBlueButton
274
306
  end
275
307
  response[:meetings] = meetings
276
308
 
309
+ response[:meetings].each do |meeting|
310
+ meeting[:meetingID] = meeting[:meetingID].to_s
311
+ meeting[:moderatorPW] = meeting[:moderatorPW].to_s
312
+ meeting[:attendeePW] = meeting[:attendeePW].to_s
313
+ meeting[:hasBeenForciblyEnded] = meeting[:hasBeenForciblyEnded].downcase == "true"
314
+ meeting[:running] = meeting[:running].downcase == "true"
315
+ end
316
+
277
317
  response
278
318
  end
279
319
 
@@ -284,8 +324,8 @@ module BigBlueButton
284
324
  # Works for BBB >= 0.7 only. For earlier versions, returns an empty string.
285
325
  def get_api_version
286
326
  response = send_api_request(:index)
287
- if response[:returncode] == "SUCCESS"
288
- response[:version]
327
+ if response[:returncode]
328
+ response[:version].to_s
289
329
  else
290
330
  ""
291
331
  end
@@ -295,11 +335,10 @@ module BigBlueButton
295
335
  def test_connection
296
336
  if @version == '0.7'
297
337
  response = send_api_request(:index)
298
- response[:returncode] == "SUCCESS"
299
338
  else
300
339
  response = get_meetings
301
- response[:returncode] == "SUCCESS"
302
340
  end
341
+ response[:returncode]
303
342
  end
304
343
 
305
344
  # API's are equal if all the following attributes are equal
@@ -355,14 +394,18 @@ module BigBlueButton
355
394
 
356
395
  # and remove the "response" node
357
396
  hash = Hash[hash[:response]].inject({}){|h,(k,v)| h[k] = v; h}
358
- puts "BigBlueButtonAPI: URL response hash = #{hash.inspect}" if @debug
359
397
 
360
- return_code = hash[:returncode]
361
- unless return_code == "SUCCESS"
398
+ # Adjust some values. There will always be a returncode, message and messageKey in the hash.
399
+ hash[:returncode] = hash[:returncode].downcase == "success" # true instead of "SUCCESS"
400
+ hash[:messageKey] = "" if !hash.has_key?(:messageKey) or hash[:messageKey].empty? # "" instead of {}
401
+ hash[:message] = "" if !hash.has_key?(:message) or hash[:message].empty? # "" instead of {}
402
+
403
+ unless hash[:returncode]
362
404
  exception = BigBlueButtonException.new(hash[:message])
363
405
  exception.key = hash.has_key?(:messageKey) ? hash[:messageKey] : ""
364
406
  raise exception
365
407
  end
408
+
366
409
  hash
367
410
  end
368
411
 
data/test/test.rb CHANGED
@@ -27,7 +27,7 @@ def general_test
27
27
  puts
28
28
  puts "---------------------------------------------------"
29
29
  if @api.test_connection
30
- puts "Connection success! continuing..."
30
+ puts "Connection successful! continuing..."
31
31
  else
32
32
  puts "Connection failed! The server might be unreachable. Exiting..."
33
33
  Kernel.exit!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigbluebutton-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-04-08 00:00:00.000000000Z
13
+ date: 2011-04-28 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: &78653840 !ruby/object:Gem::Requirement
17
+ requirement: &80178430 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 1.4.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *78653840
25
+ version_requirements: *80178430
26
26
  description: Provides an interface to the BigBlueButton web meeting API (https://github.com/mconf/bigbluebutton-api-ruby)
27
27
  email:
28
28
  - leonardodaronco@gmail.com