jubjub 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.mdown +42 -6
- data/lib/jubjub/connection/xmpp_gateway/muc.rb +4 -20
- data/lib/jubjub/connection/xmpp_gateway/pubsub.rb +194 -13
- data/lib/jubjub/data_form.rb +30 -0
- data/lib/jubjub/muc.rb +4 -93
- data/lib/jubjub/muc/collection.rb +55 -0
- data/lib/jubjub/muc/configuration.rb +5 -0
- data/lib/jubjub/muc/muc.rb +37 -0
- data/lib/jubjub/pubsub.rb +8 -201
- data/lib/jubjub/pubsub/affiliation.rb +83 -0
- data/lib/jubjub/pubsub/affiliation_collection.rb +38 -0
- data/lib/jubjub/pubsub/collection.rb +68 -0
- data/lib/jubjub/pubsub/configuration.rb +5 -0
- data/lib/jubjub/pubsub/item.rb +35 -0
- data/lib/jubjub/pubsub/item_collection.rb +35 -0
- data/lib/jubjub/pubsub/pubsub.rb +66 -0
- data/lib/jubjub/pubsub/subscription.rb +24 -0
- data/lib/jubjub/user.rb +2 -2
- data/spec/connection/xmpp_gateway_muc_spec.rb +3 -3
- data/spec/connection/xmpp_gateway_pubsub_spec.rb +167 -11
- data/spec/fixtures/dataform_1.xml +65 -0
- data/spec/fixtures/vcr_cassettes/pubsub_default_configuration.yml +118 -0
- data/spec/fixtures/vcr_cassettes/pubsub_modify_affiliations.yml +275 -0
- data/spec/fixtures/vcr_cassettes/pubsub_purge.yml +68 -0
- data/spec/fixtures/vcr_cassettes/pubsub_retrieve_affiliations.yml +99 -0
- data/spec/mixins/user_spec.rb +8 -8
- data/spec/models/muc_collection_spec.rb +17 -12
- data/spec/models/muc_configuration_spec.rb +1 -1
- data/spec/models/pubsub_affiliation_collection_spec.rb +86 -0
- data/spec/models/pubsub_affiliation_spec.rb +244 -0
- data/spec/models/pubsub_collection_spec.rb +50 -18
- data/spec/models/pubsub_item_collection_spec.rb +12 -12
- data/spec/models/pubsub_item_spec.rb +9 -2
- data/spec/models/pubsub_spec.rb +27 -2
- data/spec/models/pubsub_subscription_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/helpers.rb +7 -0
- data/spec/support/shared_examples.rb +30 -0
- metadata +46 -19
@@ -0,0 +1,55 @@
|
|
1
|
+
# Uses proxy pattern for syntax sugar
|
2
|
+
# and delaying expensive operations until
|
3
|
+
# required
|
4
|
+
class Jubjub::Muc::Collection
|
5
|
+
|
6
|
+
attr_reader :jid
|
7
|
+
|
8
|
+
def initialize(jid, connection)
|
9
|
+
@jid = Jubjub::Jid.new(jid)
|
10
|
+
@connection = connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(node, nick = nil, &block)
|
14
|
+
full_jid = Jubjub::Jid.new node, @jid.domain, nick || @connection.jid.node
|
15
|
+
|
16
|
+
if block_given?
|
17
|
+
# Reserved room
|
18
|
+
config = @connection.muc.configuration full_jid
|
19
|
+
yield config
|
20
|
+
@connection.muc.create full_jid, config
|
21
|
+
else
|
22
|
+
# Instant room
|
23
|
+
result = @connection.muc.create full_jid
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def [](jid_node_num)
|
29
|
+
case jid_node_num
|
30
|
+
when Fixnum
|
31
|
+
list[jid_node_num]
|
32
|
+
when Jubjub::Jid
|
33
|
+
list.find{|m| m.jid == jid_node_num } || Jubjub::Muc.new( jid_node_num, nil, @connection )
|
34
|
+
else
|
35
|
+
j = Jubjub::Jid.new jid_node_num, jid.domain
|
36
|
+
list.find{|m| m.jid == j } || Jubjub::Muc.new( j, nil, @connection )
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Hint that methods are actually applied to list using method_missing
|
41
|
+
def inspect
|
42
|
+
list.inspect
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def method_missing(name, *args, &block)
|
48
|
+
list.send(name, *args, &block)
|
49
|
+
end
|
50
|
+
|
51
|
+
def list
|
52
|
+
@list ||= @connection.muc.list @jid
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Jubjub
|
2
|
+
class Muc
|
3
|
+
|
4
|
+
attr_reader :jid, :name
|
5
|
+
|
6
|
+
def initialize(jid, name = nil, connection = nil)
|
7
|
+
@jid = Jubjub::Jid.new(jid)
|
8
|
+
@name = name
|
9
|
+
@connection = connection
|
10
|
+
end
|
11
|
+
|
12
|
+
def exit(nick = nil)
|
13
|
+
full_jid = Jubjub::Jid.new @jid.node, @jid.domain, nick || @connection.jid.node
|
14
|
+
|
15
|
+
@connection.muc.exit(full_jid)
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def destroy
|
20
|
+
@connection.muc.destroy(@jid)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Hide the connection details and show jid as string for compactness
|
24
|
+
def inspect
|
25
|
+
obj_id = "%x" % (object_id << 1)
|
26
|
+
"#<#{self.class}:0x#{obj_id} @jid=\"#{@jid}\" @name=#{@name.inspect}>"
|
27
|
+
end
|
28
|
+
|
29
|
+
def ==(other)
|
30
|
+
other.is_a?( self.class ) &&
|
31
|
+
other.jid == self.jid &&
|
32
|
+
other.name == self.name
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/jubjub/pubsub.rb
CHANGED
@@ -1,202 +1,9 @@
|
|
1
1
|
require "jubjub/connection/xmpp_gateway/pubsub"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@jid = Jubjub::Jid.new jid
|
11
|
-
@node = node
|
12
|
-
@connection = connection
|
13
|
-
end
|
14
|
-
|
15
|
-
def destroy(redirect_jid = nil, redirect_node = nil)
|
16
|
-
redirect_jid = Jubjub::Jid.new(redirect_jid) if redirect_jid
|
17
|
-
@connection.pubsub.destroy jid, node, redirect_jid, redirect_node
|
18
|
-
end
|
19
|
-
|
20
|
-
def subscribe
|
21
|
-
@connection.pubsub.subscribe jid, node
|
22
|
-
end
|
23
|
-
|
24
|
-
def unsubscribe(subid = nil)
|
25
|
-
@connection.pubsub.unsubscribe jid, node, subid
|
26
|
-
end
|
27
|
-
|
28
|
-
def publish(data, item_id = nil)
|
29
|
-
@connection.pubsub.publish jid, node, data, item_id
|
30
|
-
end
|
31
|
-
|
32
|
-
def retract(item_id)
|
33
|
-
@connection.pubsub.retract jid, node, item_id
|
34
|
-
end
|
35
|
-
|
36
|
-
# Hide the connection details and show jid as string for compactness
|
37
|
-
def inspect
|
38
|
-
obj_id = "%x" % (object_id << 1)
|
39
|
-
"#<#{self.class}:0x#{obj_id} @jid=\"#{jid}\" @node=#{node.inspect}>"
|
40
|
-
end
|
41
|
-
|
42
|
-
def items
|
43
|
-
PubsubItemCollection.new jid, node, @connection
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def method_missing(name, *args, &block)
|
49
|
-
items.send(name, *args, &block)
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
class PubsubItemCollection
|
55
|
-
|
56
|
-
attr_reader :jid, :node
|
57
|
-
|
58
|
-
def initialize(jid,node,connection)
|
59
|
-
@jid = Jubjub::Jid.new jid
|
60
|
-
@node = node
|
61
|
-
@connection = connection
|
62
|
-
end
|
63
|
-
|
64
|
-
def [](item_num)
|
65
|
-
case item_num
|
66
|
-
when Fixnum
|
67
|
-
items[item_num]
|
68
|
-
else
|
69
|
-
items.find{|i| i.item_id == item_num }
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# Hint that methods are actually applied to list using method_missing
|
74
|
-
def inspect
|
75
|
-
items.inspect
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def method_missing(name, *args, &block)
|
81
|
-
items.send(name, *args, &block)
|
82
|
-
end
|
83
|
-
|
84
|
-
def items
|
85
|
-
@items ||= @connection.pubsub.retrieve_items( @jid, @node )
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
class PubsubItem
|
91
|
-
|
92
|
-
attr_reader :jid, :node, :item_id, :data
|
93
|
-
|
94
|
-
def initialize(jid, node, item_id, data, connection)
|
95
|
-
@jid = Jubjub::Jid.new jid
|
96
|
-
@node = node
|
97
|
-
@item_id = item_id
|
98
|
-
@data = data
|
99
|
-
@connection = connection
|
100
|
-
end
|
101
|
-
|
102
|
-
# Hide the connection details and show jid as string for compactness
|
103
|
-
def inspect
|
104
|
-
obj_id = "%x" % (object_id << 1)
|
105
|
-
"#<#{self.class}:0x#{obj_id} @jid=\"#{jid}\" @node=#{node.inspect} @item_id=#{item_id.inspect} @data=#{data.inspect}>"
|
106
|
-
end
|
107
|
-
|
108
|
-
def retract
|
109
|
-
@connection.pubsub.retract jid, node, item_id
|
110
|
-
end
|
111
|
-
|
112
|
-
def ==(other)
|
113
|
-
other.is_a?( self.class ) &&
|
114
|
-
other.jid == self.jid &&
|
115
|
-
other.node == self.node &&
|
116
|
-
other.item_id == self.item_id &&
|
117
|
-
other.data == self.data
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
class PubsubSubscription
|
123
|
-
|
124
|
-
attr_reader :jid, :node, :subscriber, :subid, :subscription
|
125
|
-
|
126
|
-
def initialize(jid, node, subscriber, subid, subscription, connection)
|
127
|
-
@jid = Jubjub::Jid.new jid
|
128
|
-
@node = node
|
129
|
-
@subscriber = Jubjub::Jid.new subscriber
|
130
|
-
@subid = subid
|
131
|
-
@subscription = subscription
|
132
|
-
@connection = connection
|
133
|
-
end
|
134
|
-
|
135
|
-
def unsubscribe
|
136
|
-
@connection.pubsub.unsubscribe jid, node, subid
|
137
|
-
end
|
138
|
-
|
139
|
-
# Hide the connection details and show jid as string for compactness
|
140
|
-
def inspect
|
141
|
-
obj_id = "%x" % (object_id << 1)
|
142
|
-
"#<#{self.class}:0x#{obj_id} @jid=\"#{jid}\" @node=#{node.inspect} @subscriber=\"#{subscriber}\" @subid=#{subid.inspect} @subscription=#{subscription.inspect}>"
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
# Uses proxy pattern for syntax sugar
|
148
|
-
# and delaying expensive operations until
|
149
|
-
# required
|
150
|
-
class PubsubCollection
|
151
|
-
|
152
|
-
attr_reader :jid
|
153
|
-
|
154
|
-
def initialize(jid, connection)
|
155
|
-
@jid = Jubjub::Jid.new jid
|
156
|
-
@connection = connection
|
157
|
-
end
|
158
|
-
|
159
|
-
def create(node)
|
160
|
-
@connection.pubsub.create jid, node
|
161
|
-
end
|
162
|
-
|
163
|
-
def destroy(node, redirect_jid = nil, redirect_node = nil)
|
164
|
-
redirect_jid = Jubjub::Jid.new(redirect_jid) if redirect_jid
|
165
|
-
@connection.pubsub.destroy jid, node, redirect_jid, redirect_node
|
166
|
-
end
|
167
|
-
|
168
|
-
def subscribe(node)
|
169
|
-
@connection.pubsub.subscribe jid, node
|
170
|
-
end
|
171
|
-
|
172
|
-
def unsubscribe(node, subid=nil)
|
173
|
-
@connection.pubsub.unsubscribe jid, node, subid
|
174
|
-
end
|
175
|
-
|
176
|
-
def [](node_num)
|
177
|
-
case node_num
|
178
|
-
when Fixnum
|
179
|
-
list[node_num]
|
180
|
-
else
|
181
|
-
list.find{|p| p.node == node_num }
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
# Hint that methods are actually applied to list using method_missing
|
186
|
-
def inspect
|
187
|
-
list.inspect
|
188
|
-
end
|
189
|
-
|
190
|
-
private
|
191
|
-
|
192
|
-
def method_missing(name, *args, &block)
|
193
|
-
list.send(name, *args, &block)
|
194
|
-
end
|
195
|
-
|
196
|
-
def list
|
197
|
-
@list ||= @connection.pubsub.list jid
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
2
|
+
require "jubjub/pubsub/pubsub"
|
3
|
+
require "jubjub/pubsub/configuration"
|
4
|
+
require "jubjub/pubsub/collection"
|
5
|
+
require "jubjub/pubsub/affiliation"
|
6
|
+
require "jubjub/pubsub/affiliation_collection"
|
7
|
+
require "jubjub/pubsub/item"
|
8
|
+
require "jubjub/pubsub/item_collection"
|
9
|
+
require "jubjub/pubsub/subscription"
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class Jubjub::Pubsub::Affiliation
|
2
|
+
|
3
|
+
attr_reader :pubsub_jid, :pubsub_node, :jid, :affiliation
|
4
|
+
|
5
|
+
def initialize(pubsub_jid, pubsub_node, jid, affiliation, connection)
|
6
|
+
@pubsub_jid = Jubjub::Jid.new pubsub_jid
|
7
|
+
@pubsub_node = pubsub_node
|
8
|
+
@jid = Jubjub::Jid.new jid
|
9
|
+
@affiliation = affiliation
|
10
|
+
@connection = connection
|
11
|
+
end
|
12
|
+
|
13
|
+
# Hide the connection details and show jid as string for compactness
|
14
|
+
def inspect
|
15
|
+
obj_id = "%x" % (object_id << 1)
|
16
|
+
"#<#{self.class}:0x#{obj_id} @pubsub_jid=\"#{pubsub_jid}\" @pubsub_node=#{@pubsub_node} @jid=\"#{jid}\" @affiliation=#{affiliation.inspect}>"
|
17
|
+
end
|
18
|
+
|
19
|
+
def owner?
|
20
|
+
affiliation == "owner"
|
21
|
+
end
|
22
|
+
|
23
|
+
def publisher?
|
24
|
+
affiliation == "publisher"
|
25
|
+
end
|
26
|
+
|
27
|
+
def publish_only?
|
28
|
+
affiliation == "publish-only"
|
29
|
+
end
|
30
|
+
|
31
|
+
def member?
|
32
|
+
affiliation == "member"
|
33
|
+
end
|
34
|
+
|
35
|
+
def none?
|
36
|
+
affiliation == "none"
|
37
|
+
end
|
38
|
+
|
39
|
+
def outcast?
|
40
|
+
affiliation == "outcast"
|
41
|
+
end
|
42
|
+
|
43
|
+
def set(new_affiliation)
|
44
|
+
old_affiliation = @affiliation
|
45
|
+
@affiliation = new_affiliation
|
46
|
+
r = @connection.pubsub.modify_affiliations pubsub_jid, pubsub_node, self
|
47
|
+
@affiliation = old_affiliation unless r
|
48
|
+
r
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_owner
|
52
|
+
set 'owner'
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_publisher
|
56
|
+
set 'publisher'
|
57
|
+
end
|
58
|
+
|
59
|
+
def set_publish_only
|
60
|
+
set 'publish-only'
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_member
|
64
|
+
set 'member'
|
65
|
+
end
|
66
|
+
|
67
|
+
def set_none
|
68
|
+
set 'none'
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_outcast
|
72
|
+
set 'outcast'
|
73
|
+
end
|
74
|
+
|
75
|
+
def ==(other)
|
76
|
+
other.is_a?( self.class ) &&
|
77
|
+
other.pubsub_jid == self.pubsub_jid &&
|
78
|
+
other.pubsub_node == self.pubsub_node &&
|
79
|
+
other.jid == self.jid &&
|
80
|
+
other.affiliation == self.affiliation
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Jubjub::Pubsub::AffiliationCollection
|
2
|
+
|
3
|
+
attr_reader :jid, :node
|
4
|
+
|
5
|
+
def initialize(jid,node,connection)
|
6
|
+
@jid = Jubjub::Jid.new jid
|
7
|
+
@node = node
|
8
|
+
@connection = connection
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](jid_num)
|
12
|
+
case jid_num
|
13
|
+
when Fixnum
|
14
|
+
affiliations[jid_num]
|
15
|
+
when Jubjub::Jid
|
16
|
+
affiliations.find{|i| i.jid == jid_num } || Jubjub::Pubsub::Affiliation.new( jid, node, jid_num, 'none', @connection )
|
17
|
+
else
|
18
|
+
j = Jubjub::Jid.new( jid_num )
|
19
|
+
affiliations.find{|i| i.jid == j } || Jubjub::Pubsub::Affiliation.new( jid, node, j, 'none', @connection )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Hint that methods are actually applied to list using method_missing
|
24
|
+
def inspect
|
25
|
+
affiliations.inspect
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def method_missing(name, *args, &block)
|
31
|
+
affiliations.send(name, *args, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
def affiliations
|
35
|
+
@affiliations ||= @connection.pubsub.retrieve_affiliations( @jid, @node )
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Uses proxy pattern for syntax sugar
|
2
|
+
# and delaying expensive operations until
|
3
|
+
# required
|
4
|
+
class Jubjub::Pubsub::Collection
|
5
|
+
|
6
|
+
attr_reader :jid
|
7
|
+
|
8
|
+
def initialize(jid, connection)
|
9
|
+
@jid = Jubjub::Jid.new jid
|
10
|
+
@connection = connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(node)
|
14
|
+
@connection.pubsub.create jid, node
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(node, &block)
|
18
|
+
config = nil
|
19
|
+
if block_given?
|
20
|
+
# Configure node
|
21
|
+
config = @connection.pubsub.default_configuration jid
|
22
|
+
yield config
|
23
|
+
end
|
24
|
+
@connection.pubsub.create jid, node, config
|
25
|
+
end
|
26
|
+
|
27
|
+
def destroy(node, redirect_jid = nil, redirect_node = nil)
|
28
|
+
redirect_jid = Jubjub::Jid.new(redirect_jid) if redirect_jid
|
29
|
+
@connection.pubsub.destroy jid, node, redirect_jid, redirect_node
|
30
|
+
end
|
31
|
+
|
32
|
+
def purge(node)
|
33
|
+
@connection.pubsub.purge jid, node
|
34
|
+
end
|
35
|
+
|
36
|
+
def subscribe(node)
|
37
|
+
@connection.pubsub.subscribe jid, node
|
38
|
+
end
|
39
|
+
|
40
|
+
def unsubscribe(node, subid=nil)
|
41
|
+
@connection.pubsub.unsubscribe jid, node, subid
|
42
|
+
end
|
43
|
+
|
44
|
+
def [](node_num)
|
45
|
+
case node_num
|
46
|
+
when Fixnum
|
47
|
+
list[node_num]
|
48
|
+
else
|
49
|
+
list.find{|p| p.node == node_num } || Jubjub::Pubsub.new( jid, node_num, @connection )
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Hint that methods are actually applied to list using method_missing
|
54
|
+
def inspect
|
55
|
+
list.inspect
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def method_missing(name, *args, &block)
|
61
|
+
list.send(name, *args, &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
def list
|
65
|
+
@list ||= @connection.pubsub.list jid
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|