em-xmpp 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,13 @@
1
1
 
2
2
  require 'em-xmpp/jid'
3
3
  require 'em-xmpp/namespaces'
4
+ require 'em-xmpp/xml_builder'
4
5
  require 'fiber'
5
6
 
6
7
  module EM::Xmpp
7
8
  class Entity
8
9
  include Namespaces
10
+ include XmlBuilder
9
11
  attr_reader :jid, :connection
10
12
 
11
13
  def initialize(connection, jid)
@@ -55,11 +57,11 @@ module EM::Xmpp
55
57
  end
56
58
 
57
59
  # sends some plain message to the entity (use type = 'chat')
58
- def say(body, type='chat', xmlproc=nil, &blk)
59
- msg = connection.message_stanza(:to => jid, :type => type) do |xml|
60
- xml.body body
61
- xmlproc.call xml if xmlproc
62
- end
60
+ def say(body, type='chat', *args, &blk)
61
+ msg = connection.message_stanza({:to => jid, :type => type},
62
+ x('body',body),
63
+ *args
64
+ )
63
65
  connection.send_stanza msg, &blk
64
66
  end
65
67
 
@@ -84,14 +86,12 @@ module EM::Xmpp
84
86
  item_fields = {:jid => jid.bare}
85
87
  item_fields[:name] = display_name if display_name
86
88
 
87
- query = connection.iq_stanza(:type => 'set') do |iq|
88
- iq.query(:xmlns => Roster) do |q|
89
- q.item item_fields
90
- groups.each do |grp|
91
- q.group grp
92
- end
93
- end
94
- end
89
+ query = connection.iq_stanza({:type => 'set'},
90
+ x('query',{:xmlns => Roster},
91
+ x('item',item_fields),
92
+ groups.map { |grp| x('group',grp) }
93
+ )
94
+ )
95
95
 
96
96
  send_iq_stanza_fibered query
97
97
  end
@@ -100,11 +100,11 @@ module EM::Xmpp
100
100
  def remove_from_roster
101
101
  item_fields = {:jid => jid.bare, :subscription => 'remove'}
102
102
 
103
- query = connection.iq_stanza(:type => 'set') do |iq|
104
- iq.query(:xmlns => Roster) do |q|
105
- q.item item_fields
106
- end
107
- end
103
+ query = connection.iq_stanza({:type => 'set'},
104
+ x('query',{:xmlns => Roster},
105
+ x('item',item_fields)
106
+ )
107
+ )
108
108
 
109
109
  send_iq_stanza_fibered query
110
110
  end
@@ -114,18 +114,14 @@ module EM::Xmpp
114
114
  def discover_infos(node=nil)
115
115
  hash = {'xmlns' => Namespaces::DiscoverInfos}
116
116
  hash['node'] = node if node
117
- iq = connection.iq_stanza('to'=>jid) do |xml|
118
- xml.query(hash)
119
- end
117
+ iq = connection.iq_stanza({'to'=>jid}, x('query', hash))
120
118
  send_iq_stanza_fibered iq
121
119
  end
122
120
 
123
121
  # discovers items (disco#items) of an entity
124
122
  # can optionally specify a node to discover
125
123
  def discover_items(node=nil)
126
- iq = connection.iq_stanza('to'=>jid.to_s) do |xml|
127
- xml.query('xmlns' => Namespaces::DiscoverItems)
128
- end
124
+ iq = connection.iq_stanza({'to'=>jid.to_s}, x('query', 'xmlns' => Namespaces::DiscoverItems))
129
125
  send_iq_stanza_fibered iq
130
126
  end
131
127
 
@@ -170,13 +166,13 @@ module EM::Xmpp
170
166
  'hash' => filedesc[:md5],
171
167
  'date' => filedesc[:date]
172
168
  }
173
- iq = connection.iq_stanza('to'=>jid,'type'=>'set') do |xml|
174
- xml.si({:xmlns => EM::Xmpp::Namespaces::StreamInitiation, :id => sid}.merge(si_args)) do |si|
175
- si.file({:xmlns => EM::Xmpp::Namespaces::FileTransfer}.merge(file_args)) do |file|
176
- file.desc filedesc[:description]
169
+ iq = connection.iq_stanza('to'=>jid,'type'=>'set') do
170
+ x('si',{:xmlns => EM::Xmpp::Namespaces::StreamInitiation, :id => sid}.merge(si_args)) do
171
+ x('file', {:xmlns => EM::Xmpp::Namespaces::FileTransfer}.merge(file_args)) do
172
+ x('desc', filedesc[:description])
177
173
  end
178
- si.feature(:xmlns => EM::Xmpp::Namespaces::FeatureNeg) do |feat|
179
- connection.build_submit_form(feat,form)
174
+ x('feature', :xmlns => EM::Xmpp::Namespaces::FeatureNeg) do
175
+ connection.build_submit_form(form)
180
176
  end
181
177
  end
182
178
  end
@@ -184,10 +180,10 @@ module EM::Xmpp
184
180
  end
185
181
 
186
182
  def negotiation_reply(reply_id,form)
187
- iq = connection.iq_stanza('to'=>jid,'type'=>'result','id'=>reply_id) do |xml|
188
- xml.si(:xmlns => EM::Xmpp::Namespaces::StreamInitiation) do |si|
189
- si.feature(:xmlns => EM::Xmpp::Namespaces::FeatureNeg) do |feat|
190
- connection.build_submit_form(feat,form)
183
+ iq = connection.iq_stanza('to'=>jid,'type'=>'result','id'=>reply_id) do
184
+ x('si', :xmlns => EM::Xmpp::Namespaces::StreamInitiation) do
185
+ x('feature', :xmlns => EM::Xmpp::Namespaces::FeatureNeg) do
186
+ connection.build_submit_form(form)
191
187
  end
192
188
  end
193
189
  end
@@ -214,11 +210,11 @@ module EM::Xmpp
214
210
  end
215
211
 
216
212
  def publish_data(item)
217
- iq = connection.iq_stanza('type' => 'set','to' => jid) do |xml|
218
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |pubsub|
219
- pubsub.publish(:node => EM::Xmpp::Namespaces::AvatarData) do |pub|
220
- pub.item(:id => item.id) do |i|
221
- i.data({:xmnls => EM::Xmpp::Namespaces::AvatarData}, item.b64)
213
+ iq = connection.iq_stanza({'type' => 'set','to' => jid}) do
214
+ x('pubsub',{'xmlns' => EM::Xmpp::Namespaces::PubSub}) do
215
+ x('publish',:node => EM::Xmpp::Namespaces::AvatarData) do
216
+ x('item', :id => item.id) do
217
+ x('data', {:xmnls => EM::Xmpp::Namespaces::AvatarData}, item.b64)
222
218
  end
223
219
  end
224
220
  end
@@ -227,12 +223,12 @@ module EM::Xmpp
227
223
  end
228
224
 
229
225
  def publish_metadata(item)
230
- iq = connection.iq_stanza('type' => 'set','to' => jid) do |xml|
231
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |pubsub|
232
- pubsub.publish(:node => EM::Xmpp::Namespaces::AvatarMetaData) do |pub|
233
- pub.item(:id => item.id) do |i|
234
- i.metadata({:xmnls => EM::Xmpp::Namespaces::AvatarMetaData}) do |md|
235
- md.info(:width => item.width, :height => item.height, :bytes => item.bytes, :type => item.mime, :id => item.id)
226
+ iq = connection.iq_stanza('type' => 'set','to' => jid) do
227
+ x('pubsub', :xmlns => EM::Xmpp::Namespaces::PubSub) do
228
+ x('publish', :node => EM::Xmpp::Namespaces::AvatarMetaData) do
229
+ x('item', :id => item.id) do
230
+ x('metadata',{:xmnls => EM::Xmpp::Namespaces::AvatarMetaData}) do
231
+ x('info', :width => item.width, :height => item.height, :bytes => item.bytes, :type => item.mime, :id => item.id)
236
232
  end
237
233
  end
238
234
  end
@@ -240,13 +236,13 @@ module EM::Xmpp
240
236
  end
241
237
  send_iq_stanza_fibered iq
242
238
  end
243
-
239
+
244
240
  def remove
245
- iq = connection.iq_stanza('type' => 'set','to' => jid) do |xml|
246
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |pubsub|
247
- pubsub.publish(:node => EM::Xmpp::Namespaces::AvatarMetaData) do |pub|
248
- pub.item(:id => "current") do |i|
249
- i.metadata(:xmlns => EM::Xmpp::Namespaces::AvatarMetaData)
241
+ iq = connection.iq_stanza('type' => 'set','to' => jid) do
242
+ x('pubsub', :xmlns => EM::Xmpp::Namespaces::PubSub) do
243
+ x('publish', :node => EM::Xmpp::Namespaces::AvatarMetaData) do
244
+ x('item', :id => "current") do
245
+ x('metadata', :xmlns => EM::Xmpp::Namespaces::AvatarMetaData)
250
246
  end
251
247
  end
252
248
  end
@@ -269,22 +265,22 @@ module EM::Xmpp
269
265
  # requests the list of subscriptions on this PubSub service
270
266
  # returns the iq context for the answer
271
267
  def service_subscriptions
272
- iq = connection.iq_stanza('to'=>jid.bare) do |xml|
273
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |pubsub|
274
- pubsub.subscriptions
275
- end
276
- end
268
+ iq = connection.iq_stanza({'to'=>jid.bare},
269
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
270
+ x('subscriptions')
271
+ )
272
+ )
277
273
  send_iq_stanza_fibered iq
278
274
  end
279
275
 
280
276
  # requests the list of affiliations for this PubSub service
281
277
  # returns the iq context for the answer
282
278
  def service_affiliations
283
- iq = connection.iq_stanza('to'=>jid.bare) do |xml|
284
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |pubsub|
285
- pubsub.affiliations
286
- end
287
- end
279
+ iq = connection.iq_stanza({'to'=>jid.bare},
280
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
281
+ x('affiliations')
282
+ )
283
+ )
288
284
  send_iq_stanza_fibered iq
289
285
  end
290
286
 
@@ -295,11 +291,11 @@ module EM::Xmpp
295
291
  params['subid'] = subscription_id if subscription_id
296
292
  subscribee = connection.jid.bare
297
293
 
298
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'get') do |xml|
299
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |sub|
300
- sub.options({'node' => node_id, 'jid'=>subscribee}.merge(params))
301
- end
302
- end
294
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'get'},
295
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
296
+ x('options',{'node' => node_id, 'jid'=>subscribee}.merge(params))
297
+ )
298
+ )
303
299
 
304
300
  send_iq_stanza_fibered iq
305
301
  end
@@ -310,13 +306,13 @@ module EM::Xmpp
310
306
  def configure_subscription(form)
311
307
  subscribee = connection.jid.bare
312
308
 
313
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
314
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |sub|
315
- sub.options({'node' => node_id, 'jid'=>subscribee}) do |options|
316
- connection.build_submit_form(options,form)
317
- end
318
- end
319
- end
309
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
310
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
311
+ x('options',{'node' => node_id, 'jid'=>subscribee},
312
+ connection.build_submit_form(form)
313
+ )
314
+ )
315
+ )
320
316
 
321
317
  send_iq_stanza_fibered iq
322
318
  end
@@ -326,11 +322,11 @@ module EM::Xmpp
326
322
  def default_subscription_configuration
327
323
  subscribee = connection.jid.bare
328
324
  args = {'node' => node_id} if node_id
329
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'get') do |xml|
330
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |sub|
331
- sub.default(args)
332
- end
333
- end
325
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'get'},
326
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
327
+ x('default',args)
328
+ )
329
+ )
334
330
 
335
331
  send_iq_stanza_fibered iq
336
332
  end
@@ -341,11 +337,11 @@ module EM::Xmpp
341
337
  def subscribe
342
338
  subscribee = connection.jid.bare
343
339
 
344
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
345
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |sub|
346
- sub.subscribe('node' => node_id, 'jid'=>subscribee)
347
- end
348
- end
340
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
341
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
342
+ x('subscribe','node' => node_id, 'jid'=>subscribee)
343
+ )
344
+ )
349
345
 
350
346
  send_iq_stanza_fibered iq
351
347
  end
@@ -356,14 +352,14 @@ module EM::Xmpp
356
352
  def subscribe_and_configure(form)
357
353
  subscribee = connection.jid.bare
358
354
 
359
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
360
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |sub|
361
- sub.subscribe('node' => node_id, 'jid'=>subscribee)
362
- sub.options do |options|
363
- connection.build_submit_form(options,form)
364
- end
365
- end
366
- end
355
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
356
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
357
+ x('subscribe','node' => node_id, 'jid'=>subscribee),
358
+ x('options',
359
+ connection.build_submit_form(form)
360
+ )
361
+ )
362
+ )
367
363
 
368
364
  send_iq_stanza_fibered iq
369
365
  end
@@ -377,11 +373,11 @@ module EM::Xmpp
377
373
  params['subid'] = subscription_id if subscription_id
378
374
  subscribee = connection.jid.bare
379
375
 
380
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
381
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |sub|
382
- sub.unsubscribe({'node' => node_id, 'jid'=>subscribee}.merge(params))
383
- end
384
- end
376
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
377
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
378
+ x('unsubscribe',{'node' => node_id, 'jid'=>subscribee}.merge(params))
379
+ )
380
+ )
385
381
 
386
382
  send_iq_stanza_fibered iq
387
383
  end
@@ -394,49 +390,46 @@ module EM::Xmpp
394
390
  def items(max_items=nil,item_ids=nil)
395
391
  params = {}
396
392
  params['max_items'] = max_items if max_items
397
- iq = connection.iq_stanza('to'=>jid.bare) do |xml|
398
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |retrieve|
399
- retrieve.items({'node' => node_id}.merge(params)) do |items|
400
- if item_ids.respond_to?(:each)
401
- item_ids.each do |item_id|
402
- items('id' => item_id)
393
+ iq = connection.iq_stanza({'to'=>jid.bare},
394
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
395
+ x('items',{'node' => node_id}.merge(params),
396
+ if item_ids.respond_to?(:map)
397
+ item_ids.map do |item_id|
398
+ x('item','id' => item_id)
403
399
  end
404
400
  end
405
- end
406
- end
407
- end
401
+ )
402
+ )
403
+ )
408
404
 
409
405
  send_iq_stanza_fibered iq
410
406
  end
411
407
 
412
408
  # publishes a payload to the pubsub node
413
- # if the item_payload responds to :call (e.g., a proc)
414
- # then the item_payload will receive :call method with, as unique parameter,
415
- # the xml node of the xml builder. this method call should append an entry
416
- # node with the payload
417
- # otherwise it is just serialized in an entry node
409
+ # if the item_payload exists
410
+ # then inserted to item node,
411
+ # otherwise an entry node with *entry_args inserted
418
412
  #
419
413
  # item_id is an optional ID to identify the payload, otherwise, the
420
414
  # pubsub service will attribute an ID
421
415
  #
422
416
  # returns the iq context for the answer
423
- def publish(item_payload,item_id=nil)
417
+ def publish(item_payload,item_id=nil,*entry_args)
424
418
  params = {}
425
419
  params['id'] = item_id if item_id
426
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
427
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |pubsub|
428
- pubsub.publish(:node => node_id) do |publish|
429
- if item_payload.respond_to?(:call)
430
- publish.item(params) { |payload| item_payload.call payload }
420
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
421
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
422
+ x('publish',{:node => node_id},
423
+ x('item',params,
424
+ if item_payload
425
+ item_payload
431
426
  else
432
- publish.item(params) do |item|
433
- item.entry(item_payload)
434
- end
427
+ x('entry',*entry_args)
435
428
  end
436
-
437
- end
438
- end
439
- end
429
+ )
430
+ )
431
+ )
432
+ )
440
433
 
441
434
  send_iq_stanza_fibered iq
442
435
  end
@@ -445,13 +438,13 @@ module EM::Xmpp
445
438
  #
446
439
  # returns the iq context for the answer
447
440
  def retract(item_id=nil)
448
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
449
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |pubsub|
450
- pubsub.retract(:node => node_id) do |retract|
451
- retract.item(:id => item_id)
452
- end
453
- end
454
- end
441
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
442
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
443
+ x('retract',{:node => node_id},
444
+ x('item',:id => item_id)
445
+ )
446
+ )
447
+ )
455
448
 
456
449
  send_iq_stanza_fibered iq
457
450
  end
@@ -460,11 +453,11 @@ module EM::Xmpp
460
453
  #
461
454
  # returns the iq context for the answer
462
455
  def create
463
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
464
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |pubsub|
465
- pubsub.create(:node => node_id)
466
- end
467
- end
456
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
457
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
458
+ x('create',:node => node_id)
459
+ )
460
+ )
468
461
 
469
462
  send_iq_stanza_fibered iq
470
463
  end
@@ -474,11 +467,11 @@ module EM::Xmpp
474
467
  #
475
468
  # returns the iq context for the answer
476
469
  def purge
477
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
478
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSubOwner) do |pubsub|
479
- pubsub.purge(:node => node_id)
480
- end
481
- end
470
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
471
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
472
+ x('purge',:node => node_id)
473
+ )
474
+ )
482
475
 
483
476
  send_iq_stanza_fibered iq
484
477
  end
@@ -486,37 +479,37 @@ module EM::Xmpp
486
479
  # requests the list of subscriptions on this pubsub node (for the owner)
487
480
  # returns the iq context for the answer
488
481
  def subscriptions
489
- iq = connection.iq_stanza('to'=>jid.bare) do |xml|
490
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSubOwner) do |pubsub|
491
- pubsub.subscriptions(:node => node_id)
492
- end
493
- end
482
+ iq = connection.iq_stanza({'to'=>jid.bare},
483
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
484
+ x('subscriptions',:node => node_id)
485
+ )
486
+ )
494
487
  send_iq_stanza_fibered iq
495
488
  end
496
489
 
497
490
  # requests the list of affiliations on this pubsub node (for the owner)
498
491
  # returns the iq context for the answer
499
492
  def affiliations
500
- iq = connection.iq_stanza('to'=>jid.bare) do |xml|
501
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSubOwner) do |pubsub|
502
- pubsub.affiliations(:node => node_id)
503
- end
504
- end
493
+ iq = connection.iq_stanza({'to'=>jid.bare},
494
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
495
+ x('affiliations',:node => node_id)
496
+ )
497
+ )
505
498
  send_iq_stanza_fibered iq
506
499
  end
507
500
 
508
501
  # changes the subscription status of a pubsub node (for the owner)
509
502
  # returns the iq context for the answer
510
503
  def modify_subscriptions(subs)
511
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
512
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSubOwner) do |pubsub|
513
- pubsub.subscriptions(:node => node_id) do |node|
514
- subs.each do |s|
515
- node.subscription(:jid => s.jid, :subscription => s.subscription, :subid => s.sub_id)
504
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
505
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
506
+ x('subscriptions',{:node => node_id},
507
+ subs.map do |s|
508
+ x('subscription',:jid => s.jid, :subscription => s.subscription, :subid => s.sub_id)
516
509
  end
517
- end
518
- end
519
- end
510
+ )
511
+ )
512
+ )
520
513
  send_iq_stanza_fibered iq
521
514
  end
522
515
 
@@ -524,15 +517,15 @@ module EM::Xmpp
524
517
  # returns the iq context for the answer
525
518
  def modify_affiliations(affs)
526
519
  affs = [affs].flatten
527
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
528
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSubOwner) do |pubsub|
529
- pubsub.affiliations(:node => node_id) do |node|
530
- affs.each do |s|
531
- node.affiliation(:jid => s.jid, :affiliation => s.affiliation)
520
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
521
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
522
+ x('affiliations',{:node => node_id},
523
+ affs.map do |s|
524
+ x('affiliation',:jid => s.jid, :affiliation => s.affiliation)
532
525
  end
533
- end
534
- end
535
- end
526
+ )
527
+ )
528
+ )
536
529
  send_iq_stanza_fibered iq
537
530
  end
538
531
 
@@ -558,13 +551,13 @@ module EM::Xmpp
558
551
  #
559
552
  # returns the iq context for the answer
560
553
  def delete(redirect_uri=nil)
561
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
562
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSubOwner) do |pubsub|
563
- pubsub.delete(:node => node_id) do |del|
564
- del.redirect(:uri => redirect_uri) if redirect_uri
565
- end
566
- end
567
- end
554
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
555
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
556
+ x('delete',{:node => node_id},
557
+ x_if(redirect_uri,'redirect',:uri => redirect_uri)
558
+ )
559
+ )
560
+ )
568
561
 
569
562
  send_iq_stanza_fibered iq
570
563
  end
@@ -573,14 +566,14 @@ module EM::Xmpp
573
566
  #
574
567
  # returns the iq context for the answer
575
568
  def create_and_configure(form)
576
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
577
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSub) do |node|
578
- node.create('node' => node_id)
579
- node.configure do |options|
580
- connection.build_submit_form(options,form)
581
- end
582
- end
583
- end
569
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
570
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
571
+ x('create','node' => node_id),
572
+ x('configure',
573
+ connection.build_submit_form(form)
574
+ )
575
+ )
576
+ )
584
577
 
585
578
  send_iq_stanza_fibered iq
586
579
  end
@@ -590,11 +583,11 @@ module EM::Xmpp
590
583
  #
591
584
  # returns the iq context for the answer
592
585
  def configuration_options
593
- iq = connection.iq_stanza('to'=>jid.bare) do |xml|
594
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSubOwner) do |node|
595
- node.configure('node' => node_id)
596
- end
597
- end
586
+ iq = connection.iq_stanza({'to'=>jid.bare},
587
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
588
+ x('configure','node' => node_id)
589
+ )
590
+ )
598
591
 
599
592
  send_iq_stanza_fibered iq
600
593
  end
@@ -603,13 +596,13 @@ module EM::Xmpp
603
596
  #
604
597
  # returns the iq context for the answer
605
598
  def configure(form)
606
- iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set') do |xml|
607
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSubOwner) do |node|
608
- node.configure('node' => node_id) do |config|
609
- connection.build_submit_form(config,form)
610
- end
611
- end
612
- end
599
+ iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
600
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
601
+ x('configure',{'node' => node_id},
602
+ connection.build_submit_form(form)
603
+ )
604
+ )
605
+ )
613
606
 
614
607
  send_iq_stanza_fibered iq
615
608
  end
@@ -618,11 +611,11 @@ module EM::Xmpp
618
611
  #
619
612
  # returns the iq context for the answer
620
613
  def default_configuration
621
- iq = connection.iq_stanza('to'=>jid.bare) do |xml|
622
- xml.pubsub(:xmlns => EM::Xmpp::Namespaces::PubSubOwner) do |sub|
623
- sub.default
624
- end
625
- end
614
+ iq = connection.iq_stanza({'to'=>jid.bare},
615
+ x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
616
+ x('default')
617
+ )
618
+ )
626
619
 
627
620
  send_iq_stanza_fibered iq
628
621
  end
@@ -647,19 +640,21 @@ module EM::Xmpp
647
640
 
648
641
  # Join a MUC.
649
642
  def join(nick,pass=nil,historysize=0,&blk)
650
- pres = connection.presence_stanza('to'=> muc(nick).to_s) do |xml|
651
- xml.password pass if pass
652
- xml.x('xmlns' => Namespaces::Muc) do |x|
653
- x.history('maxchars' => historysize.to_s)
643
+ pres = connection.presence_stanza('to'=> muc(nick).to_s) do
644
+ nodes = []
645
+ nodes << x('password', pass) if pass
646
+ nodes << x('x', 'xmlns' => Namespaces::Muc) do
647
+ x('history', 'maxchars' => historysize.to_s)
654
648
  end
649
+ nodes
655
650
  end
656
651
  connection.send_stanza pres, &blk
657
652
  end
658
653
 
659
654
  # Leave a MUC.
660
655
  def part(nick,msg=nil)
661
- pres = connection.presence_stanza('to'=> muc(nick).to_s,'type'=>'unavailable') do |xml|
662
- xml.status msg if msg
656
+ pres = connection.presence_stanza('to'=> muc(nick).to_s,'type'=>'unavailable') do
657
+ x('status', msg) if msg
663
658
  end
664
659
  connection.send_stanza pres
665
660
  end
@@ -669,22 +664,23 @@ module EM::Xmpp
669
664
  join(nick)
670
665
  end
671
666
 
672
- # Say some message in the muc.
667
+ # Say some message in the muc.
673
668
  def say(body, xmlproc=nil, &blk)
674
- msg = connection.message_stanza(:to => jid, :type => 'groupchat') do |xml|
675
- xml.body body
676
- xmlproc.call xml if xmlproc
669
+ msg = connection.message_stanza(:to => jid, :type => 'groupchat') do
670
+ nodes = []
671
+ nodes << x('body',body,&xmlproc)
672
+ nodes << xmlproc.call if xmlproc
673
+ nodes
677
674
  end
678
675
  connection.send_stanza msg, &blk
679
676
  end
680
677
 
681
678
  private
682
-
683
679
  def set_role(role,nick,reason=nil,&blk)
684
- iq = connection.iq_stanza(:to => jid,:type => 'set') do |xml|
685
- xml.query('xmlns' => Namespaces::MucAdmin) do |q|
686
- q.item('nick' => nick, 'role' => role) do |r|
687
- r.reason reason if reason
680
+ iq = connection.iq_stanza(:to => jid,:type => 'set') do
681
+ x('query', 'xmlns' => Namespaces::MucAdmin) do
682
+ x('item', 'nick' => nick, 'role' => role) do
683
+ x('reason',reason) if reason
688
684
  end
689
685
  end
690
686
  end
@@ -692,10 +688,10 @@ module EM::Xmpp
692
688
  end
693
689
 
694
690
  def set_affiliation(affiliation,affiliated_jid,reason=nil,&blk)
695
- iq = connection.iq_stanza(:to => jid,:type => 'set') do |xml|
696
- xml.query('xmlns' => Namespaces::MucAdmin) do |q|
697
- q.item('affiliation' => affiliation, 'jid' => affiliated_jid) do |r|
698
- r.reason reason if reason
691
+ iq = connection.iq_stanza(:to => jid,:type => 'set') do
692
+ x('query','xmlns' => Namespaces::MucAdmin) do
693
+ x('item', 'affiliation' => affiliation, 'jid' => affiliated_jid) do
694
+ x('reason', reason) if reason
699
695
  end
700
696
  end
701
697
  end
@@ -815,18 +811,18 @@ module EM::Xmpp
815
811
 
816
812
  # sets the room subject (Message Of The Day)
817
813
  def motd(subject,&blk)
818
- msg = connection.message_stanza(:to => jid) do |xml|
819
- xml.subject subject
814
+ msg = connection.message_stanza(:to => jid) do
815
+ x('subject',subject)
820
816
  end
821
817
  connection.send_stanza msg, &blk
822
818
  end
823
819
 
824
820
  # invites someone (based on his jid) to the MUC
825
821
  def invite(invited_jid,reason="no reason",&blk)
826
- msg = connection.message_stanza(:to => jid) do |xml|
827
- xml.x('xmlns' => Namespaces::MucUser) do |x|
828
- x.invite('to' => invited_jid.to_s) do |invite|
829
- invite.reason reason
822
+ msg = connection.message_stanza(:to => jid) do
823
+ x('x', 'xmlns' => Namespaces::MucUser) do
824
+ x('invite', 'to' => invited_jid.to_s) do
825
+ x('reason', reason) if reason
830
826
  end
831
827
  end
832
828
  end