jubjub 0.0.7 → 0.0.8
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.
- data/README.mdown +27 -1
- data/lib/jubjub.rb +1 -1
- data/lib/jubjub/connection/xmpp_gateway.rb +9 -9
- data/lib/jubjub/connection/xmpp_gateway/helper.rb +5 -5
- data/lib/jubjub/connection/xmpp_gateway/muc.rb +127 -32
- data/lib/jubjub/connection/xmpp_gateway/pubsub.rb +64 -64
- data/lib/jubjub/data_form.rb +16 -13
- data/lib/jubjub/errors.rb +2 -2
- data/lib/jubjub/helpers.rb +32 -0
- data/lib/jubjub/jid.rb +8 -8
- data/lib/jubjub/muc.rb +3 -1
- data/lib/jubjub/muc/affiliation.rb +77 -0
- data/lib/jubjub/muc/affiliations_collection.rb +31 -0
- data/lib/jubjub/muc/collection.rb +12 -19
- data/lib/jubjub/muc/configuration.rb +2 -2
- data/lib/jubjub/muc/muc.rb +24 -11
- data/lib/jubjub/pubsub.rb +1 -1
- data/lib/jubjub/pubsub/affiliation.rb +20 -20
- data/lib/jubjub/pubsub/affiliation_collection.rb +11 -18
- data/lib/jubjub/pubsub/collection.rb +14 -21
- data/lib/jubjub/pubsub/configuration.rb +2 -2
- data/lib/jubjub/pubsub/item.rb +8 -8
- data/lib/jubjub/pubsub/item_collection.rb +10 -17
- data/lib/jubjub/pubsub/pubsub.rb +17 -17
- data/lib/jubjub/pubsub/subscription.rb +6 -6
- data/lib/jubjub/response.rb +1 -1
- data/lib/jubjub/response/error.rb +6 -6
- data/lib/jubjub/response/proxy.rb +8 -8
- data/lib/jubjub/response/response.rb +10 -10
- data/lib/jubjub/user.rb +16 -15
- data/spec/connection/xmpp_gateway_muc_spec.rb +174 -40
- data/spec/connection/xmpp_gateway_pubsub_spec.rb +100 -104
- data/spec/fixtures/vcr_cassettes/muc_configuration.yml +73 -6
- data/spec/fixtures/vcr_cassettes/muc_create_with_configuration.yml +8 -8
- data/spec/fixtures/vcr_cassettes/muc_message.yml +89 -0
- data/spec/fixtures/vcr_cassettes/muc_modify_affiliations.yml +367 -0
- data/spec/fixtures/vcr_cassettes/muc_retrieve_affiliations.yml +93 -0
- data/spec/fixtures/vcr_cassettes/pubsub_publish_with_dataform_payload.yml +3 -3
- data/spec/fixtures/vcr_cassettes/pubsub_retrieve_items.yml +24 -18
- data/spec/mixins/user_spec.rb +37 -37
- data/spec/models/data_form_spec.rb +3 -3
- data/spec/models/jid_spec.rb +41 -41
- data/spec/models/muc_affiliation_collection_spec.rb +146 -0
- data/spec/models/muc_affiliation_spec.rb +215 -0
- data/spec/models/muc_collection_spec.rb +64 -32
- data/spec/models/muc_configuration_spec.rb +3 -3
- data/spec/models/muc_spec.rb +44 -23
- data/spec/models/pubsub_affiliation_collection_spec.rb +65 -30
- data/spec/models/pubsub_affiliation_spec.rb +50 -50
- data/spec/models/pubsub_collection_spec.rb +65 -49
- data/spec/models/pubsub_item_collection_spec.rb +17 -17
- data/spec/models/pubsub_item_spec.rb +18 -18
- data/spec/models/pubsub_spec.rb +41 -41
- data/spec/models/pubsub_subscription_spec.rb +23 -23
- data/spec/models/response_error_spec.rb +19 -19
- data/spec/models/response_proxy_spec.rb +51 -49
- data/spec/models/response_spec.rb +33 -33
- data/spec/support/helpers.rb +21 -1
- data/spec/support/matchers.rb +4 -4
- data/spec/support/shared_examples.rb +132 -94
- data/spec/support/webmock_stanza_matching.rb +43 -0
- metadata +45 -16
data/README.mdown
CHANGED
@@ -67,6 +67,31 @@ Examples
|
|
67
67
|
c['muc#roomconfig_allowinvites'] = false
|
68
68
|
}
|
69
69
|
|
70
|
+
# Retrieve current affiliations
|
71
|
+
room.affiliations
|
72
|
+
=> [#<Jubjub::Muc::Affiliation:0x1019a3c90 @muc_jid="jubjub@chat.test.com" @jid="theozaurus@jabber.org" @nick=nil @affiliation="owner" @role=nil>]
|
73
|
+
|
74
|
+
# Search affiliations
|
75
|
+
room.affiliations['theozaurus@jabber.org']
|
76
|
+
=> #<Jubjub::Muc::Affiliation:0x1019a3c90 @muc_jid="jubjub@chat.test.com" @jid="theozaurus@jabber.org" @nick=nil @affiliation="owner" @role=nil>
|
77
|
+
|
78
|
+
# Test affiliations
|
79
|
+
room.affiliations['theozaurus@jabber.org'].owner?
|
80
|
+
=> true
|
81
|
+
room.affiliations['theozaurus@jabber.org'].member?
|
82
|
+
=> false
|
83
|
+
|
84
|
+
# Create affiliation
|
85
|
+
room.affiliations['bob@test.com'].set_admin
|
86
|
+
=> true
|
87
|
+
# or
|
88
|
+
room.affiliations['bot@test.com'].set('admin')
|
89
|
+
=> true
|
90
|
+
|
91
|
+
# Message a room
|
92
|
+
room.message "I am an invisible man."
|
93
|
+
=> #<Jubjub::Muc:0x10161c3b0 @jid="customjub@chat.test.com" @name=nil>
|
94
|
+
|
70
95
|
# Destroy a room
|
71
96
|
room.destroy
|
72
97
|
=> true
|
@@ -230,7 +255,8 @@ The error `type` and error `condition` are the important factors. The `type` is
|
|
230
255
|
TODO
|
231
256
|
====
|
232
257
|
|
233
|
-
- MUC user role
|
258
|
+
- MUC user role control
|
259
|
+
- Bulk Pubsub and MUC affiliation control
|
234
260
|
- Better exception handling
|
235
261
|
- Service discovery
|
236
262
|
- Operations that are not IQ based, such as rosters and two way messaging
|
data/lib/jubjub.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'jubjub/user'
|
1
|
+
require 'jubjub/user'
|
@@ -6,23 +6,23 @@ require "jubjub/connection/xmpp_gateway/pubsub"
|
|
6
6
|
module Jubjub
|
7
7
|
module Connection
|
8
8
|
class XmppGateway
|
9
|
-
|
9
|
+
|
10
10
|
attr_reader :jid
|
11
|
-
|
11
|
+
|
12
12
|
def initialize(jid,password,settings)
|
13
13
|
@jid = jid
|
14
14
|
@password = password
|
15
15
|
@settings = settings
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def muc
|
19
19
|
@muc ||= Muc.new(self)
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def pubsub
|
23
23
|
@pubsub ||= Pubsub.new(self)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def write(stanza)
|
27
27
|
req = Net::HTTP::Post.new( url.path )
|
28
28
|
req.basic_auth( @jid.to_s, @password )
|
@@ -33,20 +33,20 @@ module Jubjub
|
|
33
33
|
# OK
|
34
34
|
else
|
35
35
|
#res.error!
|
36
|
-
end
|
36
|
+
end
|
37
37
|
decode res.body
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
41
|
-
|
41
|
+
|
42
42
|
def url
|
43
43
|
URI.parse "http://#{@settings[:host]}:#{@settings[:port]}/"
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def decode(http_body)
|
47
47
|
Nokogiri::XML::Document.parse http_body
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|
@@ -2,16 +2,16 @@ module Jubjub
|
|
2
2
|
module Connection
|
3
3
|
class XmppGateway
|
4
4
|
module Helper
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(connection)
|
7
7
|
@connection = connection
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def write(stanza)
|
11
|
-
@connection.write(
|
11
|
+
@connection.write stanza.to_xml(:indent => 0, :save_with => Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
@@ -5,19 +5,19 @@ module Jubjub
|
|
5
5
|
module Connection
|
6
6
|
class XmppGateway
|
7
7
|
class Muc
|
8
|
-
|
8
|
+
|
9
9
|
include Helper
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(connection)
|
12
12
|
@connection = connection
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# http://xmpp.org/extensions/xep-0045.html#createroom-instant
|
16
16
|
# <presence
|
17
17
|
# from='crone1@shakespeare.lit/desktop'
|
18
18
|
# to='darkcave@chat.shakespeare.lit/firstwitch'>
|
19
19
|
# <x xmlns='http://jabber.org/protocol/muc'/>
|
20
|
-
# </presence>
|
20
|
+
# </presence>
|
21
21
|
# <iq from='crone1@shakespeare.lit/desktop'
|
22
22
|
# id='create1'
|
23
23
|
# to='darkcave@chat.shakespeare.lit'
|
@@ -35,23 +35,23 @@ module Jubjub
|
|
35
35
|
#
|
36
36
|
def create(full_jid, configuration = Jubjub::Muc::Configuration.new)
|
37
37
|
room_jid = Jubjub::Jid.new full_jid.node, full_jid.domain
|
38
|
-
|
38
|
+
|
39
39
|
request = Nokogiri::XML::Builder.new do |xml|
|
40
40
|
xml.iq_(:type => 'set', :to => room_jid) {
|
41
|
-
xml.query_('xmlns' => '
|
41
|
+
xml.query_('xmlns' => namespaces['muc_owner']){
|
42
42
|
configuration.to_builder(xml.parent)
|
43
43
|
}
|
44
44
|
}
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
presence full_jid
|
48
|
-
|
49
|
-
Jubjub::Response.new( write request
|
48
|
+
|
49
|
+
Jubjub::Response.new( write request ){|stanza|
|
50
50
|
success = stanza.xpath( '/iq[@type="result"]' ).any?
|
51
51
|
Jubjub::Muc.new room_jid, nil, @connection if success
|
52
52
|
}.proxy_result
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
# http://xmpp.org/extensions/xep-0045.html#createroom-reserved
|
56
56
|
# <presence
|
57
57
|
# from='crone1@shakespeare.lit/desktop'
|
@@ -200,16 +200,16 @@ module Jubjub
|
|
200
200
|
# </iq>
|
201
201
|
def configuration(full_jid)
|
202
202
|
room_jid = Jubjub::Jid.new full_jid.node, full_jid.domain
|
203
|
-
|
203
|
+
|
204
204
|
request = Nokogiri::XML::Builder.new do |xml|
|
205
205
|
xml.iq_(:to => room_jid, :type => 'get') {
|
206
|
-
xml.query_('xmlns' => '
|
206
|
+
xml.query_('xmlns' => namespaces['muc_owner'])
|
207
207
|
}
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
presence full_jid
|
211
|
-
|
212
|
-
Jubjub::Response.new( write request
|
211
|
+
|
212
|
+
Jubjub::Response.new( write request ){|stanza|
|
213
213
|
config = stanza.xpath(
|
214
214
|
"/iq[@type='result']/muc_owner:query/x_data:x[@type='form']",
|
215
215
|
namespaces
|
@@ -217,7 +217,7 @@ module Jubjub
|
|
217
217
|
Jubjub::Muc::Configuration.new config if config
|
218
218
|
}.proxy_result
|
219
219
|
end
|
220
|
-
|
220
|
+
|
221
221
|
# http://xmpp.org/extensions/xep-0045.html#destroyroom
|
222
222
|
# <iq from='crone1@shakespeare.lit/desktop'
|
223
223
|
# id='begone'
|
@@ -238,17 +238,17 @@ module Jubjub
|
|
238
238
|
def destroy(jid)
|
239
239
|
request = Nokogiri::XML::Builder.new do |xml|
|
240
240
|
xml.iq_(:to => jid, :type => 'set') {
|
241
|
-
xml.query_('xmlns' => '
|
241
|
+
xml.query_('xmlns' => namespaces['muc_owner']){
|
242
242
|
xml.destroy_
|
243
243
|
}
|
244
244
|
}
|
245
245
|
end
|
246
|
-
|
247
|
-
Jubjub::Response.new( write request
|
246
|
+
|
247
|
+
Jubjub::Response.new( write request ){|stanza|
|
248
248
|
stanza.xpath( '/iq[@type="result"]' ).any?
|
249
249
|
}.proxy_result
|
250
250
|
end
|
251
|
-
|
251
|
+
|
252
252
|
# http://xmpp.org/extensions/xep-0045.html#disco-rooms
|
253
253
|
# <iq from='hag66@shakespeare.lit/pda'
|
254
254
|
# id='disco2'
|
@@ -276,11 +276,11 @@ module Jubjub
|
|
276
276
|
def list(jid)
|
277
277
|
request = Nokogiri::XML::Builder.new do |xml|
|
278
278
|
xml.iq_(:to => jid, :type => 'get') {
|
279
|
-
xml.query_('xmlns' => '
|
279
|
+
xml.query_('xmlns' => namespaces['disco_items'])
|
280
280
|
}
|
281
281
|
end
|
282
|
-
|
283
|
-
Jubjub::Response.new( write request
|
282
|
+
|
283
|
+
Jubjub::Response.new( write request ){|stanza|
|
284
284
|
stanza.xpath(
|
285
285
|
'/iq[@type="result"]/disco_items:query/disco_items:item',
|
286
286
|
namespaces
|
@@ -290,7 +290,101 @@ module Jubjub
|
|
290
290
|
}
|
291
291
|
}.proxy_result
|
292
292
|
end
|
293
|
-
|
293
|
+
|
294
|
+
# http://xmpp.org/extensions/xep-0045.html#modifymember
|
295
|
+
# <iq from='crone1@shakespeare.lit/desktop'
|
296
|
+
# id='member3'
|
297
|
+
# to='coven@chat.shakespeare.lit'
|
298
|
+
# type='get'>
|
299
|
+
# <query xmlns='http://jabber.org/protocol/muc#admin'>
|
300
|
+
# <item affiliation='member'/>
|
301
|
+
# </query>
|
302
|
+
# </iq>
|
303
|
+
#
|
304
|
+
# Expected
|
305
|
+
# <iq from='coven@chat.shakespeare.lit'
|
306
|
+
# id='member3'
|
307
|
+
# to='crone1@shakespeare.lit/desktop'
|
308
|
+
# type='result'>
|
309
|
+
# <query xmlns='http://jabber.org/protocol/muc#admin'>
|
310
|
+
# <item affiliation='member'
|
311
|
+
# jid='hag66@shakespeare.lit'
|
312
|
+
# nick='thirdwitch'
|
313
|
+
# role='participant'/>
|
314
|
+
# </query>
|
315
|
+
# </iq>
|
316
|
+
def retrieve_affiliations(jid, affiliation)
|
317
|
+
request = Nokogiri::XML::Builder.new do |xml|
|
318
|
+
xml.iq_(:to => jid, :type => 'get') {
|
319
|
+
xml.query_('xmlns' => namespaces['muc_admin']) {
|
320
|
+
xml.item_(:affiliation => affiliation)
|
321
|
+
}
|
322
|
+
}
|
323
|
+
end
|
324
|
+
|
325
|
+
Jubjub::Response.new( write request ){|stanza|
|
326
|
+
stanza.xpath(
|
327
|
+
'/iq[@type="result"]/muc_admin:query/muc_admin:item',
|
328
|
+
namespaces
|
329
|
+
).map{|item|
|
330
|
+
# Convert to Jubjub object
|
331
|
+
Jubjub::Muc::Affiliation.new jid, item.attr('jid'), item.attr('nick'), item.attr('role'), item.attr('affiliation'), @connection
|
332
|
+
}
|
333
|
+
}.proxy_result
|
334
|
+
end
|
335
|
+
|
336
|
+
# http://xmpp.org/extensions/xep-0045.html#grantmember
|
337
|
+
# <iq from='crone1@shakespeare.lit/desktop'
|
338
|
+
# id='member1'
|
339
|
+
# to='coven@chat.shakespeare.lit'
|
340
|
+
# type='set'>
|
341
|
+
# <query xmlns='http://jabber.org/protocol/muc#admin'>
|
342
|
+
# <item affiliation='member'
|
343
|
+
# jid='hag66@shakespeare.lit'/>
|
344
|
+
# </query>
|
345
|
+
# </iq>
|
346
|
+
#
|
347
|
+
# Expected
|
348
|
+
# <iq from='coven@chat.shakespeare.lit'
|
349
|
+
# id='member1'
|
350
|
+
# to='crone1@shakespeare.lit/desktop'
|
351
|
+
# type='result'/>
|
352
|
+
def modify_affiliations(muc_jid, *affiliations)
|
353
|
+
affiliations = [affiliations].flatten
|
354
|
+
|
355
|
+
request = Nokogiri::XML::Builder.new do |xml|
|
356
|
+
xml.iq_(:to => muc_jid, :type => 'set') {
|
357
|
+
xml.query_('xmlns' => namespaces['muc_admin']) {
|
358
|
+
affiliations.each {|a|
|
359
|
+
xml.item_(:affiliation => a.affiliation, :jid => a.jid)
|
360
|
+
}
|
361
|
+
}
|
362
|
+
}
|
363
|
+
end
|
364
|
+
|
365
|
+
Jubjub::Response.new( write request ){|stanza|
|
366
|
+
stanza.xpath( '/iq[@type="result"]' ).any?
|
367
|
+
}.proxy_result
|
368
|
+
end
|
369
|
+
|
370
|
+
|
371
|
+
# http://xmpp.org/extensions/xep-0045.html#message
|
372
|
+
# <message
|
373
|
+
# from='hag66@shakespeare.lit/pda'
|
374
|
+
# to='coven@chat.shakespeare.lit'
|
375
|
+
# type='groupchat'>
|
376
|
+
# <body>Harpier cries: 'tis time, 'tis time.</body>
|
377
|
+
# </message>
|
378
|
+
def message(muc_jid, body)
|
379
|
+
request = Nokogiri::XML::Builder.new do |xml|
|
380
|
+
xml.message_(:to => muc_jid, :type => 'groupchat') {
|
381
|
+
xml.body_ body
|
382
|
+
}
|
383
|
+
end
|
384
|
+
|
385
|
+
write request
|
386
|
+
end
|
387
|
+
|
294
388
|
# http://xmpp.org/extensions/xep-0045.html#exit
|
295
389
|
# <presence
|
296
390
|
# from='hag66@shakespeare.lit/pda'
|
@@ -299,31 +393,32 @@ module Jubjub
|
|
299
393
|
def exit(full_jid)
|
300
394
|
presence full_jid, :unavailable
|
301
395
|
end
|
302
|
-
|
396
|
+
|
303
397
|
private
|
304
|
-
|
398
|
+
|
305
399
|
def presence(full_jid, availability = :available)
|
306
400
|
options = { :to => full_jid }
|
307
401
|
options[:type] = availability unless availability == :available
|
308
|
-
|
402
|
+
|
309
403
|
request = Nokogiri::XML::Builder.new do |xml|
|
310
404
|
xml.presence_(options) {
|
311
405
|
xml.x_('xmlns' => 'http://jabber.org/protocol/muc')
|
312
406
|
}
|
313
407
|
end
|
314
|
-
|
315
|
-
write request
|
408
|
+
|
409
|
+
write request
|
316
410
|
end
|
317
|
-
|
411
|
+
|
318
412
|
def namespaces
|
319
413
|
{
|
320
414
|
'disco_items' => 'http://jabber.org/protocol/disco#items',
|
321
415
|
'muc_owner' => "http://jabber.org/protocol/muc#owner",
|
416
|
+
'muc_admin' => "http://jabber.org/protocol/muc#admin",
|
322
417
|
'x_data' => 'jabber:x:data'
|
323
418
|
}
|
324
419
|
end
|
325
|
-
|
420
|
+
|
326
421
|
end
|
327
422
|
end
|
328
423
|
end
|
329
|
-
end
|
424
|
+
end
|
@@ -5,13 +5,13 @@ module Jubjub
|
|
5
5
|
module Connection
|
6
6
|
class XmppGateway
|
7
7
|
class Pubsub
|
8
|
-
|
8
|
+
|
9
9
|
include Helper
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(connection)
|
12
12
|
@connection = connection
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# http://xmpp.org/extensions/xep-0060.html#entity-nodes
|
16
16
|
# <iq type='get'
|
17
17
|
# from='francisco@denmark.lit/barracks'
|
@@ -19,7 +19,7 @@ module Jubjub
|
|
19
19
|
# id='nodes1'>
|
20
20
|
# <query xmlns='http://jabber.org/protocol/disco#items'/>
|
21
21
|
# </iq>
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# Expected
|
24
24
|
# <iq type='result'
|
25
25
|
# from='pubsub.shakespeare.lit'
|
@@ -40,8 +40,8 @@ module Jubjub
|
|
40
40
|
xml.query_('xmlns' => namespaces['disco_items'])
|
41
41
|
}
|
42
42
|
end
|
43
|
-
|
44
|
-
Jubjub::Response.new( write request
|
43
|
+
|
44
|
+
Jubjub::Response.new( write request ){|stanza|
|
45
45
|
stanza.xpath(
|
46
46
|
'/iq[@type="result"]/disco_items:query/disco_items:item',
|
47
47
|
namespaces
|
@@ -52,7 +52,7 @@ module Jubjub
|
|
52
52
|
}
|
53
53
|
}.proxy_result
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
# http://xmpp.org/extensions/xep-0060.html#owner-create-and-configure
|
57
57
|
# <iq type='set'
|
58
58
|
# from='hamlet@denmark.lit/elsinore'
|
@@ -71,7 +71,7 @@ module Jubjub
|
|
71
71
|
# </configure>
|
72
72
|
# </pubsub>
|
73
73
|
# </iq>
|
74
|
-
#
|
74
|
+
#
|
75
75
|
# Expected
|
76
76
|
# <iq type='result'
|
77
77
|
# from='pubsub.shakespeare.lit'
|
@@ -82,7 +82,7 @@ module Jubjub
|
|
82
82
|
xml.iq_(:to => jid, :type => 'set') {
|
83
83
|
xml.pubsub_('xmlns' => namespaces['pubsub']) {
|
84
84
|
xml.create_('node' => node)
|
85
|
-
if configuration
|
85
|
+
if configuration
|
86
86
|
xml.configure_{
|
87
87
|
configuration.to_builder(xml.parent)
|
88
88
|
}
|
@@ -90,8 +90,8 @@ module Jubjub
|
|
90
90
|
}
|
91
91
|
}
|
92
92
|
end
|
93
|
-
|
94
|
-
Jubjub::Response.new( write request
|
93
|
+
|
94
|
+
Jubjub::Response.new( write request ){|stanza|
|
95
95
|
success = stanza.xpath(
|
96
96
|
# Pull out required parts
|
97
97
|
'/iq[@type="result"]'
|
@@ -99,7 +99,7 @@ module Jubjub
|
|
99
99
|
Jubjub::Pubsub.new jid, node, @connection if success
|
100
100
|
}.proxy_result
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
# http://xmpp.org/extensions/xep-0060.html#owner-configure
|
104
104
|
# <iq type='get'
|
105
105
|
# from='hamlet@denmark.lit/elsinore'
|
@@ -109,7 +109,7 @@ module Jubjub
|
|
109
109
|
# <configure node='princely_musings'/>
|
110
110
|
# </pubsub>
|
111
111
|
# </iq>
|
112
|
-
#
|
112
|
+
#
|
113
113
|
# Expected
|
114
114
|
# <iq type='result'
|
115
115
|
# from='pubsub.shakespeare.lit'
|
@@ -132,7 +132,7 @@ module Jubjub
|
|
132
132
|
# </configure>
|
133
133
|
# </pubsub>
|
134
134
|
# </iq>
|
135
|
-
def default_configuration(jid)
|
135
|
+
def default_configuration(jid)
|
136
136
|
request = Nokogiri::XML::Builder.new do |xml|
|
137
137
|
xml.iq_(:to => jid, :type => 'get') {
|
138
138
|
xml.pubsub_('xmlns' => namespaces['pubsub_owner']) {
|
@@ -140,8 +140,8 @@ module Jubjub
|
|
140
140
|
}
|
141
141
|
}
|
142
142
|
end
|
143
|
-
|
144
|
-
Jubjub::Response.new( write request
|
143
|
+
|
144
|
+
Jubjub::Response.new( write request ){|stanza|
|
145
145
|
config = stanza.xpath(
|
146
146
|
# Pull out required parts
|
147
147
|
"/iq[@type='result']/pubsub_owner:pubsub/pubsub_owner:default/x_data:x[@type='form']",
|
@@ -150,7 +150,7 @@ module Jubjub
|
|
150
150
|
Jubjub::Pubsub::Configuration.new config if config
|
151
151
|
}.proxy_result
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
# http://xmpp.org/extensions/xep-0060.html#owner-delete
|
155
155
|
# <iq type='set'
|
156
156
|
# from='hamlet@denmark.lit/elsinore'
|
@@ -162,12 +162,12 @@ module Jubjub
|
|
162
162
|
# </delete>
|
163
163
|
# </pubsub>
|
164
164
|
# </iq>
|
165
|
-
#
|
165
|
+
#
|
166
166
|
# Expected
|
167
167
|
# <iq type='result'
|
168
168
|
# from='pubsub.shakespeare.lit'
|
169
169
|
# id='delete1'/>
|
170
|
-
def destroy(jid, node, redirect_jid = nil, redirect_node = nil)
|
170
|
+
def destroy(jid, node, redirect_jid = nil, redirect_node = nil)
|
171
171
|
request = Nokogiri::XML::Builder.new do |xml|
|
172
172
|
xml.iq_(:to => jid, :type => 'set') {
|
173
173
|
xml.pubsub_('xmlns' => namespaces['pubsub_owner']) {
|
@@ -177,12 +177,12 @@ module Jubjub
|
|
177
177
|
}
|
178
178
|
}
|
179
179
|
end
|
180
|
-
|
181
|
-
Jubjub::Response.new( write request
|
180
|
+
|
181
|
+
Jubjub::Response.new( write request ){|stanza|
|
182
182
|
stanza.xpath( '/iq[@type="result"]' ).any?
|
183
183
|
}.proxy_result
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
# http://xmpp.org/extensions/xep-0060.html#owner-purge
|
187
187
|
# <iq type='set'
|
188
188
|
# from='hamlet@denmark.lit/elsinore'
|
@@ -205,12 +205,12 @@ module Jubjub
|
|
205
205
|
}
|
206
206
|
}
|
207
207
|
end
|
208
|
-
|
209
|
-
Jubjub::Response.new( write request
|
208
|
+
|
209
|
+
Jubjub::Response.new( write request ){|stanza|
|
210
210
|
stanza.xpath( '/iq[@type="result"]' ).any?
|
211
211
|
}.proxy_result
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
# http://xmpp.org/extensions/xep-0060.html#subscriber-subscribe
|
215
215
|
# <iq type='set'
|
216
216
|
# from='francisco@denmark.lit/barracks'
|
@@ -236,7 +236,7 @@ module Jubjub
|
|
236
236
|
# subscription='subscribed'/>
|
237
237
|
# </pubsub>
|
238
238
|
# </iq>
|
239
|
-
def subscribe(jid, node)
|
239
|
+
def subscribe(jid, node)
|
240
240
|
request = Nokogiri::XML::Builder.new do |xml|
|
241
241
|
xml.iq_(:to => jid, :type => 'set') {
|
242
242
|
xml.pubsub_('xmlns' => namespaces['pubsub']) {
|
@@ -244,21 +244,21 @@ module Jubjub
|
|
244
244
|
}
|
245
245
|
}
|
246
246
|
end
|
247
|
-
|
248
|
-
Jubjub::Response.new( write request
|
247
|
+
|
248
|
+
Jubjub::Response.new( write request ){|stanza|
|
249
249
|
result = stanza.xpath(
|
250
250
|
'/iq[@type="result"]/pubsub:pubsub/pubsub:subscription',
|
251
251
|
namespaces
|
252
252
|
)
|
253
253
|
if result.any?
|
254
254
|
subscriber = Jubjub::Jid.new(result.first.attr('jid'))
|
255
|
-
subid = result.first.attr('subid')
|
255
|
+
subid = result.first.attr('subid')
|
256
256
|
subscription = result.first.attr('subscription')
|
257
257
|
Jubjub::Pubsub::Subscription.new jid, node, subscriber, subid, subscription, @connection
|
258
258
|
end
|
259
259
|
}.proxy_result
|
260
260
|
end
|
261
|
-
|
261
|
+
|
262
262
|
# http://xmpp.org/extensions/xep-0060.html#subscriber-unsubscribe
|
263
263
|
# <iq type='set'
|
264
264
|
# from='francisco@denmark.lit/barracks'
|
@@ -270,16 +270,16 @@ module Jubjub
|
|
270
270
|
# jid='francisco@denmark.lit'/>
|
271
271
|
# </pubsub>
|
272
272
|
# </iq>
|
273
|
-
#
|
273
|
+
#
|
274
274
|
# Expected
|
275
275
|
# <iq type='result'
|
276
276
|
# from='pubsub.shakespeare.lit'
|
277
277
|
# to='francisco@denmark.lit/barracks'
|
278
278
|
# id='unsub1'/>
|
279
|
-
def unsubscribe(jid, node, subid=nil)
|
279
|
+
def unsubscribe(jid, node, subid=nil)
|
280
280
|
unsubscribe_options = {'node' => node, 'jid' => subscriber}
|
281
281
|
unsubscribe_options['subid'] = subid if subid
|
282
|
-
|
282
|
+
|
283
283
|
request = Nokogiri::XML::Builder.new do |xml|
|
284
284
|
xml.iq_(:to => jid, :type => 'set') {
|
285
285
|
xml.pubsub_('xmlns' => namespaces['pubsub']) {
|
@@ -287,12 +287,12 @@ module Jubjub
|
|
287
287
|
}
|
288
288
|
}
|
289
289
|
end
|
290
|
-
|
291
|
-
Jubjub::Response.new( write request
|
290
|
+
|
291
|
+
Jubjub::Response.new( write request ){|stanza|
|
292
292
|
stanza.xpath( '/iq[@type="result"]' ).any?
|
293
293
|
}.proxy_result
|
294
294
|
end
|
295
|
-
|
295
|
+
|
296
296
|
# http://xmpp.org/extensions/xep-0060.html#publisher-publish
|
297
297
|
# <iq type='set'
|
298
298
|
# from='hamlet@denmark.lit/blogbot'
|
@@ -306,7 +306,7 @@ module Jubjub
|
|
306
306
|
# </publish>
|
307
307
|
# </pubsub>
|
308
308
|
# </iq>
|
309
|
-
#
|
309
|
+
#
|
310
310
|
# Expected
|
311
311
|
# <iq type='result'
|
312
312
|
# from='pubsub.shakespeare.lit'
|
@@ -321,7 +321,7 @@ module Jubjub
|
|
321
321
|
def publish(jid, node, data, item_id = nil)
|
322
322
|
item_options = {}
|
323
323
|
item_options[:id] = item_id if item_id
|
324
|
-
|
324
|
+
|
325
325
|
request = Nokogiri::XML::Builder.new do |xml|
|
326
326
|
xml.iq_(:to => jid, :type => 'set') {
|
327
327
|
xml.pubsub_('xmlns' => namespaces['pubsub']) {
|
@@ -337,8 +337,8 @@ module Jubjub
|
|
337
337
|
}
|
338
338
|
}
|
339
339
|
end
|
340
|
-
|
341
|
-
Jubjub::Response.new( write request
|
340
|
+
|
341
|
+
Jubjub::Response.new( write request ){|stanza|
|
342
342
|
result = stanza.xpath(
|
343
343
|
'/iq[@type="result"]/pubsub:pubsub/pubsub:publish/pubsub:item',
|
344
344
|
namespaces
|
@@ -350,7 +350,7 @@ module Jubjub
|
|
350
350
|
end
|
351
351
|
}.proxy_result
|
352
352
|
end
|
353
|
-
|
353
|
+
|
354
354
|
# http://xmpp.org/extensions/xep-0060.html#publisher-delete
|
355
355
|
# <iq type='set'
|
356
356
|
# from='hamlet@denmark.lit/elsinore'
|
@@ -362,7 +362,7 @@ module Jubjub
|
|
362
362
|
# </retract>
|
363
363
|
# </pubsub>
|
364
364
|
# </iq>
|
365
|
-
#
|
365
|
+
#
|
366
366
|
# Expected
|
367
367
|
# <iq type='result'
|
368
368
|
# from='pubsub.shakespeare.lit'
|
@@ -378,12 +378,12 @@ module Jubjub
|
|
378
378
|
}
|
379
379
|
}
|
380
380
|
end
|
381
|
-
|
382
|
-
Jubjub::Response.new( write request
|
381
|
+
|
382
|
+
Jubjub::Response.new( write request ){|stanza|
|
383
383
|
stanza.xpath( '/iq[@type="result"]' ).any?
|
384
384
|
}.proxy_result
|
385
385
|
end
|
386
|
-
|
386
|
+
|
387
387
|
# http://xmpp.org/extensions/xep-0060.html#subscriber-retrieve
|
388
388
|
# <iq type='get'
|
389
389
|
# from='francisco@denmark.lit/barracks'
|
@@ -393,7 +393,7 @@ module Jubjub
|
|
393
393
|
# <items node='princely_musings'/>
|
394
394
|
# </pubsub>
|
395
395
|
# </iq>
|
396
|
-
#
|
396
|
+
#
|
397
397
|
# Expected
|
398
398
|
# <iq type='result'
|
399
399
|
# from='pubsub.shakespeare.lit'
|
@@ -427,8 +427,8 @@ module Jubjub
|
|
427
427
|
}
|
428
428
|
}
|
429
429
|
end
|
430
|
-
|
431
|
-
Jubjub::Response.new( write request
|
430
|
+
|
431
|
+
Jubjub::Response.new( write request ){|stanza|
|
432
432
|
stanza.xpath(
|
433
433
|
'/iq[@type="result"]/pubsub:pubsub/pubsub:items/pubsub:item',
|
434
434
|
namespaces
|
@@ -439,8 +439,8 @@ module Jubjub
|
|
439
439
|
}
|
440
440
|
}.proxy_result
|
441
441
|
end
|
442
|
-
|
443
|
-
|
442
|
+
|
443
|
+
|
444
444
|
# http://xmpp.org/extensions/xep-0060.html#owner-affiliations
|
445
445
|
# <iq type='get'
|
446
446
|
# from='hamlet@denmark.lit/elsinore'
|
@@ -450,7 +450,7 @@ module Jubjub
|
|
450
450
|
# <affiliations node='princely_musings'/>
|
451
451
|
# </pubsub>
|
452
452
|
# </iq>
|
453
|
-
#
|
453
|
+
#
|
454
454
|
# Expected
|
455
455
|
# <iq type='result'
|
456
456
|
# from='pubsub.shakespeare.lit'
|
@@ -471,8 +471,8 @@ module Jubjub
|
|
471
471
|
}
|
472
472
|
}
|
473
473
|
end
|
474
|
-
|
475
|
-
Jubjub::Response.new( write request
|
474
|
+
|
475
|
+
Jubjub::Response.new( write request ){|stanza|
|
476
476
|
stanza.xpath(
|
477
477
|
'/iq[@type="result"]/pubsub_owner:pubsub/pubsub_owner:affiliations/pubsub_owner:affiliation',
|
478
478
|
namespaces
|
@@ -483,7 +483,7 @@ module Jubjub
|
|
483
483
|
}
|
484
484
|
}.proxy_result
|
485
485
|
end
|
486
|
-
|
486
|
+
|
487
487
|
# http://xmpp.org/extensions/xep-0060.html#owner-affiliations-modify
|
488
488
|
# <iq type='set'
|
489
489
|
# from='hamlet@denmark.lit/elsinore'
|
@@ -495,14 +495,14 @@ module Jubjub
|
|
495
495
|
# </affiliations>
|
496
496
|
# </pubsub>
|
497
497
|
# </iq>
|
498
|
-
#
|
498
|
+
#
|
499
499
|
# Expected
|
500
500
|
# <iq type='result'
|
501
501
|
# from='pubsub.shakespeare.lit'
|
502
502
|
# id='ent2'/>
|
503
503
|
def modify_affiliations(pubsub_jid, pubsub_node, *affiliations)
|
504
504
|
affiliations = [affiliations].flatten
|
505
|
-
|
505
|
+
|
506
506
|
request = Nokogiri::XML::Builder.new do |xml|
|
507
507
|
xml.iq_(:to => pubsub_jid, :type => 'set') {
|
508
508
|
xml.pubsub_(:xmlns => namespaces['pubsub_owner']){
|
@@ -514,22 +514,22 @@ module Jubjub
|
|
514
514
|
}
|
515
515
|
}
|
516
516
|
end
|
517
|
-
|
518
|
-
Jubjub::Response.new( write request
|
517
|
+
|
518
|
+
Jubjub::Response.new( write request ){|stanza|
|
519
519
|
stanza.xpath( '/iq[@type="result"]' ).any?
|
520
520
|
}.proxy_result
|
521
521
|
end
|
522
|
-
|
522
|
+
|
523
523
|
private
|
524
|
-
|
524
|
+
|
525
525
|
def subscriber
|
526
526
|
Jubjub::Jid.new @connection.jid.node, @connection.jid.domain
|
527
527
|
end
|
528
|
-
|
528
|
+
|
529
529
|
def pubsub_uri(jid, node)
|
530
530
|
"xmpp:#{jid}?;node=#{node}"
|
531
531
|
end
|
532
|
-
|
532
|
+
|
533
533
|
def namespaces
|
534
534
|
{
|
535
535
|
'disco_items' => 'http://jabber.org/protocol/disco#items',
|
@@ -538,8 +538,8 @@ module Jubjub
|
|
538
538
|
'x_data' => 'jabber:x:data'
|
539
539
|
}
|
540
540
|
end
|
541
|
-
|
541
|
+
|
542
542
|
end
|
543
543
|
end
|
544
544
|
end
|
545
|
-
end
|
545
|
+
end
|