tp-blather 0.8.2
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/.autotest +13 -0
- data/.gemtest +0 -0
- data/.gitignore +19 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +249 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +413 -0
- data/Rakefile +20 -0
- data/TODO.md +2 -0
- data/blather.gemspec +51 -0
- data/examples/certs/README +20 -0
- data/examples/certs/ca-bundle.crt +3987 -0
- data/examples/echo.rb +19 -0
- data/examples/execute.rb +17 -0
- data/examples/ping_pong.rb +38 -0
- data/examples/print_hierarchy.rb +77 -0
- data/examples/rosterprint.rb +15 -0
- data/examples/stream_only.rb +28 -0
- data/examples/trusted_echo.rb +21 -0
- data/examples/xmpp4r/echo.rb +36 -0
- data/lib/blather.rb +112 -0
- data/lib/blather/cert_store.rb +53 -0
- data/lib/blather/client.rb +95 -0
- data/lib/blather/client/client.rb +345 -0
- data/lib/blather/client/dsl.rb +320 -0
- data/lib/blather/client/dsl/pubsub.rb +174 -0
- data/lib/blather/core_ext/eventmachine.rb +125 -0
- data/lib/blather/core_ext/ipaddr.rb +20 -0
- data/lib/blather/errors.rb +69 -0
- data/lib/blather/errors/sasl_error.rb +44 -0
- data/lib/blather/errors/stanza_error.rb +110 -0
- data/lib/blather/errors/stream_error.rb +84 -0
- data/lib/blather/file_transfer.rb +107 -0
- data/lib/blather/file_transfer/ibb.rb +68 -0
- data/lib/blather/file_transfer/s5b.rb +114 -0
- data/lib/blather/jid.rb +141 -0
- data/lib/blather/roster.rb +118 -0
- data/lib/blather/roster_item.rb +146 -0
- data/lib/blather/stanza.rb +167 -0
- data/lib/blather/stanza/disco.rb +32 -0
- data/lib/blather/stanza/disco/capabilities.rb +161 -0
- data/lib/blather/stanza/disco/disco_info.rb +205 -0
- data/lib/blather/stanza/disco/disco_items.rb +134 -0
- data/lib/blather/stanza/iq.rb +144 -0
- data/lib/blather/stanza/iq/command.rb +339 -0
- data/lib/blather/stanza/iq/ibb.rb +86 -0
- data/lib/blather/stanza/iq/ping.rb +50 -0
- data/lib/blather/stanza/iq/query.rb +53 -0
- data/lib/blather/stanza/iq/roster.rb +185 -0
- data/lib/blather/stanza/iq/s5b.rb +208 -0
- data/lib/blather/stanza/iq/si.rb +415 -0
- data/lib/blather/stanza/iq/vcard.rb +149 -0
- data/lib/blather/stanza/message.rb +428 -0
- data/lib/blather/stanza/message/muc_user.rb +119 -0
- data/lib/blather/stanza/muc/muc_user_base.rb +54 -0
- data/lib/blather/stanza/presence.rb +172 -0
- data/lib/blather/stanza/presence/c.rb +100 -0
- data/lib/blather/stanza/presence/muc.rb +35 -0
- data/lib/blather/stanza/presence/muc_user.rb +147 -0
- data/lib/blather/stanza/presence/status.rb +218 -0
- data/lib/blather/stanza/presence/subscription.rb +100 -0
- data/lib/blather/stanza/pubsub.rb +119 -0
- data/lib/blather/stanza/pubsub/affiliations.rb +79 -0
- data/lib/blather/stanza/pubsub/create.rb +65 -0
- data/lib/blather/stanza/pubsub/errors.rb +18 -0
- data/lib/blather/stanza/pubsub/event.rb +139 -0
- data/lib/blather/stanza/pubsub/items.rb +103 -0
- data/lib/blather/stanza/pubsub/publish.rb +103 -0
- data/lib/blather/stanza/pubsub/retract.rb +92 -0
- data/lib/blather/stanza/pubsub/subscribe.rb +68 -0
- data/lib/blather/stanza/pubsub/subscription.rb +135 -0
- data/lib/blather/stanza/pubsub/subscriptions.rb +83 -0
- data/lib/blather/stanza/pubsub/unsubscribe.rb +84 -0
- data/lib/blather/stanza/pubsub_owner.rb +51 -0
- data/lib/blather/stanza/pubsub_owner/delete.rb +52 -0
- data/lib/blather/stanza/pubsub_owner/purge.rb +52 -0
- data/lib/blather/stanza/x.rb +416 -0
- data/lib/blather/stream.rb +266 -0
- data/lib/blather/stream/client.rb +32 -0
- data/lib/blather/stream/component.rb +39 -0
- data/lib/blather/stream/features.rb +70 -0
- data/lib/blather/stream/features/register.rb +38 -0
- data/lib/blather/stream/features/resource.rb +63 -0
- data/lib/blather/stream/features/sasl.rb +190 -0
- data/lib/blather/stream/features/session.rb +45 -0
- data/lib/blather/stream/features/tls.rb +29 -0
- data/lib/blather/stream/parser.rb +102 -0
- data/lib/blather/version.rb +3 -0
- data/lib/blather/xmpp_node.rb +94 -0
- data/spec/blather/client/client_spec.rb +687 -0
- data/spec/blather/client/dsl/pubsub_spec.rb +492 -0
- data/spec/blather/client/dsl_spec.rb +266 -0
- data/spec/blather/errors/sasl_error_spec.rb +33 -0
- data/spec/blather/errors/stanza_error_spec.rb +129 -0
- data/spec/blather/errors/stream_error_spec.rb +108 -0
- data/spec/blather/errors_spec.rb +33 -0
- data/spec/blather/file_transfer_spec.rb +135 -0
- data/spec/blather/jid_spec.rb +87 -0
- data/spec/blather/roster_item_spec.rb +134 -0
- data/spec/blather/roster_spec.rb +107 -0
- data/spec/blather/stanza/discos/disco_info_spec.rb +247 -0
- data/spec/blather/stanza/discos/disco_items_spec.rb +154 -0
- data/spec/blather/stanza/iq/command_spec.rb +206 -0
- data/spec/blather/stanza/iq/ibb_spec.rb +124 -0
- data/spec/blather/stanza/iq/ping_spec.rb +45 -0
- data/spec/blather/stanza/iq/query_spec.rb +64 -0
- data/spec/blather/stanza/iq/roster_spec.rb +139 -0
- data/spec/blather/stanza/iq/s5b_spec.rb +57 -0
- data/spec/blather/stanza/iq/si_spec.rb +98 -0
- data/spec/blather/stanza/iq/vcard_spec.rb +93 -0
- data/spec/blather/stanza/iq_spec.rb +61 -0
- data/spec/blather/stanza/message/muc_user_spec.rb +152 -0
- data/spec/blather/stanza/message_spec.rb +282 -0
- data/spec/blather/stanza/presence/c_spec.rb +56 -0
- data/spec/blather/stanza/presence/muc_spec.rb +37 -0
- data/spec/blather/stanza/presence/muc_user_spec.rb +83 -0
- data/spec/blather/stanza/presence/status_spec.rb +144 -0
- data/spec/blather/stanza/presence/subscription_spec.rb +102 -0
- data/spec/blather/stanza/presence_spec.rb +125 -0
- data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
- data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
- data/spec/blather/stanza/pubsub/event_spec.rb +98 -0
- data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
- data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
- data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
- data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
- data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
- data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
- data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +74 -0
- data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
- data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
- data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
- data/spec/blather/stanza/pubsub_spec.rb +68 -0
- data/spec/blather/stanza/x_spec.rb +231 -0
- data/spec/blather/stanza_spec.rb +134 -0
- data/spec/blather/stream/client_spec.rb +1090 -0
- data/spec/blather/stream/component_spec.rb +108 -0
- data/spec/blather/stream/parser_spec.rb +152 -0
- data/spec/blather/stream/ssl_spec.rb +32 -0
- data/spec/blather/xmpp_node_spec.rb +47 -0
- data/spec/blather_spec.rb +34 -0
- data/spec/fixtures/pubsub.rb +311 -0
- data/spec/spec_helper.rb +17 -0
- data/yard/templates/default/class/html/handlers.erb +18 -0
- data/yard/templates/default/class/setup.rb +10 -0
- data/yard/templates/default/class/text/handlers.erb +1 -0
- metadata +459 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'fixtures/pubsub'
|
|
3
|
+
require 'blather/client/dsl'
|
|
4
|
+
|
|
5
|
+
describe Blather::DSL::PubSub do
|
|
6
|
+
before do
|
|
7
|
+
@host = 'host.name'
|
|
8
|
+
@client = mock()
|
|
9
|
+
@client.stubs(:jid).returns Blather::JID.new('n@d/r')
|
|
10
|
+
@pubsub = Blather::DSL::PubSub.new @client, @host
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'raises an error when trying to send a stanza without a host' do
|
|
14
|
+
@pubsub.host = nil
|
|
15
|
+
proc { @pubsub.affiliations }.should raise_error RuntimeError
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'requests affiliations' do
|
|
19
|
+
@client.expects(:write_with_handler).with do |n|
|
|
20
|
+
n.should be_instance_of Blather::Stanza::PubSub::Affiliations
|
|
21
|
+
n.find('//ns:pubsub/ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
22
|
+
n.to.should == Blather::JID.new(@host)
|
|
23
|
+
n.type.should == :get
|
|
24
|
+
end
|
|
25
|
+
@pubsub.affiliations
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'requests affiliations from a specified host' do
|
|
29
|
+
host = 'another.host'
|
|
30
|
+
@client.expects(:write_with_handler).with do |n|
|
|
31
|
+
n.should be_instance_of Blather::Stanza::PubSub::Affiliations
|
|
32
|
+
n.find('//ns:pubsub/ns:affiliations', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
33
|
+
n.to.should == Blather::JID.new(host)
|
|
34
|
+
n.type.should == :get
|
|
35
|
+
end
|
|
36
|
+
@pubsub.affiliations host
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'requests subscriptions' do
|
|
40
|
+
@client.expects(:write_with_handler).with do |n|
|
|
41
|
+
n.should be_instance_of Blather::Stanza::PubSub::Subscriptions
|
|
42
|
+
n.find('//ns:pubsub/ns:subscriptions', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
43
|
+
n.to.should == Blather::JID.new(@host)
|
|
44
|
+
n.type.should == :get
|
|
45
|
+
end
|
|
46
|
+
@pubsub.subscriptions
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'requests subscriptions from a specified host' do
|
|
50
|
+
host = 'another.host'
|
|
51
|
+
@client.expects(:write_with_handler).with do |n|
|
|
52
|
+
n.should be_instance_of Blather::Stanza::PubSub::Subscriptions
|
|
53
|
+
n.find('//ns:pubsub/ns:subscriptions', :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
54
|
+
n.to.should == Blather::JID.new(host)
|
|
55
|
+
n.type.should == :get
|
|
56
|
+
end
|
|
57
|
+
@pubsub.subscriptions host
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'requests nodes defaulting to "/"' do
|
|
61
|
+
@client.expects(:write_with_handler).with do |n|
|
|
62
|
+
n.should be_instance_of Blather::Stanza::DiscoItems
|
|
63
|
+
n.find("/iq/ns:query[@node='/']", :ns => Blather::Stanza::DiscoItems.registered_ns).should_not be_empty
|
|
64
|
+
n.to.should == Blather::JID.new(@host)
|
|
65
|
+
n.type.should == :get
|
|
66
|
+
end
|
|
67
|
+
@pubsub.nodes nil
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'requests nodes from a specified host' do
|
|
71
|
+
host = 'another.host'
|
|
72
|
+
@client.expects(:write_with_handler).with do |n|
|
|
73
|
+
n.should be_instance_of Blather::Stanza::DiscoItems
|
|
74
|
+
n.find("/iq/ns:query[@node='/']", :ns => Blather::Stanza::DiscoItems.registered_ns).should_not be_empty
|
|
75
|
+
n.to.should == Blather::JID.new(host)
|
|
76
|
+
n.type.should == :get
|
|
77
|
+
end
|
|
78
|
+
@pubsub.nodes nil, host
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'requests nodes under a specified path' do
|
|
82
|
+
@client.expects(:write_with_handler).with do |n|
|
|
83
|
+
n.should be_instance_of Blather::Stanza::DiscoItems
|
|
84
|
+
n.find("/iq/ns:query[@node='/path/to/nodes']", :ns => Blather::Stanza::DiscoItems.registered_ns).should_not be_empty
|
|
85
|
+
n.to.should == Blather::JID.new(@host)
|
|
86
|
+
n.type.should == :get
|
|
87
|
+
end
|
|
88
|
+
@pubsub.nodes '/path/to/nodes'
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'requests information on a node' do
|
|
92
|
+
@client.expects(:write_with_handler).with do |n|
|
|
93
|
+
n.should be_instance_of Blather::Stanza::DiscoInfo
|
|
94
|
+
n.find("/iq/ns:query[@node='/path/to/node']", :ns => Blather::Stanza::DiscoInfo.registered_ns).should_not be_empty
|
|
95
|
+
n.to.should == Blather::JID.new(@host)
|
|
96
|
+
n.type.should == :get
|
|
97
|
+
end
|
|
98
|
+
@pubsub.node '/path/to/node'
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'requests all items from a node' do
|
|
102
|
+
@client.expects(:write_with_handler).with do |n|
|
|
103
|
+
n.should be_instance_of Blather::Stanza::PubSub::Items
|
|
104
|
+
n.find("/iq/ns:pubsub/ns:items[@node='/path/to/node']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
105
|
+
n.to.should == Blather::JID.new(@host)
|
|
106
|
+
n.type.should == :get
|
|
107
|
+
end
|
|
108
|
+
@pubsub.items '/path/to/node'
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'requests specific items from a node' do
|
|
112
|
+
@client.expects(:write_with_handler).with do |n|
|
|
113
|
+
n.should be_instance_of Blather::Stanza::PubSub::Items
|
|
114
|
+
n.find("/iq/ns:pubsub/ns:items[@node='/path/to/node'][ns:item[@id='item1']][ns:item[@id='item2']]", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
115
|
+
n.to.should == Blather::JID.new(@host)
|
|
116
|
+
n.type.should == :get
|
|
117
|
+
end
|
|
118
|
+
@pubsub.items '/path/to/node', %w[item1 item2]
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it 'requests some items from a node' do
|
|
122
|
+
@client.expects(:write_with_handler).with do |n|
|
|
123
|
+
n.should be_instance_of Blather::Stanza::PubSub::Items
|
|
124
|
+
n.find("/iq/ns:pubsub/ns:items[@node='/path/to/node' and @max_items='2']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
125
|
+
n.to.should == Blather::JID.new(@host)
|
|
126
|
+
n.type.should == :get
|
|
127
|
+
end
|
|
128
|
+
@pubsub.items '/path/to/node', nil, 2
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'can publish items to a node with a hash' do
|
|
132
|
+
@client.expects(:write_with_handler).with do |n|
|
|
133
|
+
n.should be_instance_of Blather::Stanza::PubSub::Publish
|
|
134
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:publish[@node='/path/to/node' and ns:item[@id='id1' and .='payload1'] and ns:item[@id='id2' and .='payload2']]", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
135
|
+
n.to.should == Blather::JID.new(@host)
|
|
136
|
+
n.type.should == :set
|
|
137
|
+
end
|
|
138
|
+
@pubsub.publish '/path/to/node', {'id1' => 'payload1', 'id2' => 'payload2'}
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'can publish items to a node with an array' do
|
|
142
|
+
@client.expects(:write_with_handler).with do |n|
|
|
143
|
+
n.should be_instance_of Blather::Stanza::PubSub::Publish
|
|
144
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:publish[@node='/path/to/node' and ns:item[.='payload1'] and ns:item[.='payload2']]", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
145
|
+
n.to.should == Blather::JID.new(@host)
|
|
146
|
+
n.type.should == :set
|
|
147
|
+
end
|
|
148
|
+
@pubsub.publish '/path/to/node', %w[payload1 payload2]
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it 'can publish items to a node with a string' do
|
|
152
|
+
@client.expects(:write_with_handler).with do |n|
|
|
153
|
+
n.should be_instance_of Blather::Stanza::PubSub::Publish
|
|
154
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:publish[@node='/path/to/node' and ns:item[.='payload']]", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
155
|
+
n.to.should == Blather::JID.new(@host)
|
|
156
|
+
n.type.should == :set
|
|
157
|
+
end
|
|
158
|
+
@pubsub.publish '/path/to/node', 'payload'
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it 'can retract an item with an array' do
|
|
162
|
+
@client.expects(:write_with_handler).with do |n|
|
|
163
|
+
n.should be_instance_of Blather::Stanza::PubSub::Retract
|
|
164
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:retract[@node='/path/to/node' and ns:item[@id='id1'] and ns:item[@id='id2']]", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
165
|
+
n.to.should == Blather::JID.new(@host)
|
|
166
|
+
n.type.should == :set
|
|
167
|
+
end
|
|
168
|
+
@pubsub.retract '/path/to/node', %w[id1 id2]
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'can retract an item with a string' do
|
|
172
|
+
@client.expects(:write_with_handler).with do |n|
|
|
173
|
+
n.should be_instance_of Blather::Stanza::PubSub::Retract
|
|
174
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:retract[@node='/path/to/node' and ns:item[@id='id1']]", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
175
|
+
n.to.should == Blather::JID.new(@host)
|
|
176
|
+
n.type.should == :set
|
|
177
|
+
end
|
|
178
|
+
@pubsub.retract '/path/to/node', 'id1'
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it 'can subscribe to a node with the default jid' do
|
|
182
|
+
@client.expects(:write_with_handler).with do |n|
|
|
183
|
+
n.should be_instance_of Blather::Stanza::PubSub::Subscribe
|
|
184
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:subscribe[@node='/path/to/node' and @jid='#{@client.jid.stripped}']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
185
|
+
n.to.should == Blather::JID.new(@host)
|
|
186
|
+
n.type.should == :set
|
|
187
|
+
end
|
|
188
|
+
@pubsub.subscribe '/path/to/node'
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it 'can subscribe to a node with a specified jid as a string' do
|
|
192
|
+
@client.expects(:write_with_handler).with do |n|
|
|
193
|
+
n.should be_instance_of Blather::Stanza::PubSub::Subscribe
|
|
194
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:subscribe[@node='/path/to/node' and @jid='jid@d/r']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
195
|
+
n.to.should == Blather::JID.new(@host)
|
|
196
|
+
n.type.should == :set
|
|
197
|
+
end
|
|
198
|
+
@pubsub.subscribe '/path/to/node', 'jid@d/r'
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it 'can subscribe to a node with a specified jid as a Blather::JID' do
|
|
202
|
+
@client.expects(:write_with_handler).with do |n|
|
|
203
|
+
n.should be_instance_of Blather::Stanza::PubSub::Subscribe
|
|
204
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:subscribe[@node='/path/to/node' and @jid='jid@d/r']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
205
|
+
n.to.should == Blather::JID.new(@host)
|
|
206
|
+
n.type.should == :set
|
|
207
|
+
end
|
|
208
|
+
@pubsub.subscribe '/path/to/node', Blather::JID.new('jid@d/r')
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it 'can unsubscribe to a node with the default jid' do
|
|
212
|
+
@client.expects(:write_with_handler).with do |n|
|
|
213
|
+
n.should be_instance_of Blather::Stanza::PubSub::Unsubscribe
|
|
214
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:unsubscribe[@node='/path/to/node' and @jid='#{@client.jid.stripped}']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
215
|
+
n.to.should == Blather::JID.new(@host)
|
|
216
|
+
n.type.should == :set
|
|
217
|
+
end
|
|
218
|
+
@pubsub.unsubscribe '/path/to/node'
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
it 'can unsubscribe to a node with a specified jid as a string' do
|
|
222
|
+
@client.expects(:write_with_handler).with do |n|
|
|
223
|
+
n.should be_instance_of Blather::Stanza::PubSub::Unsubscribe
|
|
224
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:unsubscribe[@node='/path/to/node' and @jid='jid@d/r']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
225
|
+
n.to.should == Blather::JID.new(@host)
|
|
226
|
+
n.type.should == :set
|
|
227
|
+
end
|
|
228
|
+
@pubsub.unsubscribe '/path/to/node', 'jid@d/r'
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
it 'can unsubscribe to a node with a specified jid as a Blather::JID' do
|
|
232
|
+
@client.expects(:write_with_handler).with do |n|
|
|
233
|
+
n.should be_instance_of Blather::Stanza::PubSub::Unsubscribe
|
|
234
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:unsubscribe[@node='/path/to/node' and @jid='jid@d/r']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
235
|
+
n.to.should == Blather::JID.new(@host)
|
|
236
|
+
n.type.should == :set
|
|
237
|
+
end
|
|
238
|
+
@pubsub.unsubscribe '/path/to/node', Blather::JID.new('jid@d/r')
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
it 'can unsubscribe with a particular subscription id' do
|
|
242
|
+
@client.expects(:write_with_handler).with do |n|
|
|
243
|
+
n.should be_instance_of Blather::Stanza::PubSub::Unsubscribe
|
|
244
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:unsubscribe[@node='/path/to/node' and @jid='jid@d/r' and @subid='subid']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
245
|
+
n.subid.should == 'subid'
|
|
246
|
+
n.type.should == :set
|
|
247
|
+
end
|
|
248
|
+
@pubsub.unsubscribe '/path/to/node', 'jid@d/r', 'subid'
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
it 'can purge a node' do
|
|
252
|
+
@client.expects(:write_with_handler).with do |n|
|
|
253
|
+
n.should be_instance_of Blather::Stanza::PubSubOwner::Purge
|
|
254
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:purge[@node='/path/to/node']", :ns => Blather::Stanza::PubSubOwner.registered_ns).should_not be_empty
|
|
255
|
+
n.to.should == Blather::JID.new(@host)
|
|
256
|
+
n.type.should == :set
|
|
257
|
+
end
|
|
258
|
+
@pubsub.purge '/path/to/node'
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
it 'can create a node' do
|
|
262
|
+
@client.expects(:write_with_handler).with do |n|
|
|
263
|
+
n.should be_instance_of Blather::Stanza::PubSub::Create
|
|
264
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:create[@node='/path/to/node']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
265
|
+
n.to.should == Blather::JID.new(@host)
|
|
266
|
+
n.type.should == :set
|
|
267
|
+
end
|
|
268
|
+
@pubsub.create '/path/to/node'
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
it 'can create a node with configuration' do
|
|
272
|
+
pubsub_configure = Blather::Stanza::X.new({
|
|
273
|
+
:type => :submit,
|
|
274
|
+
:fields => [
|
|
275
|
+
{ :var => "FORM_TYPE", :type => 'hidden', :value => "http://jabber.org/protocol/pubsub#node_config" },
|
|
276
|
+
{ :var => "pubsub#persist_items", :value => "0" },
|
|
277
|
+
{ :var => "pubsub#max_items", :value => "0" },
|
|
278
|
+
{ :var => "pubsub#notify_retract", :value => "0" },
|
|
279
|
+
{ :var => "pubsub#publish_model", :value => "open" }]
|
|
280
|
+
})
|
|
281
|
+
@client.expects(:write_with_handler).with do |n|
|
|
282
|
+
n.should be_instance_of Blather::Stanza::PubSub::Create
|
|
283
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:create[@node='/path/to/node']", :ns => Blather::Stanza::PubSub.registered_ns).should_not be_empty
|
|
284
|
+
n.to.should == Blather::JID.new(@host)
|
|
285
|
+
n.type.should == :set
|
|
286
|
+
n.configure_node.should == pubsub_configure
|
|
287
|
+
end
|
|
288
|
+
@pubsub.create '/path/to/node', nil, pubsub_configure
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
it 'can delete a node' do
|
|
292
|
+
@client.expects(:write_with_handler).with do |n|
|
|
293
|
+
n.should be_instance_of Blather::Stanza::PubSubOwner::Delete
|
|
294
|
+
n.find("/iq[@type='set']/ns:pubsub/ns:delete[@node='/path/to/node']", :ns => Blather::Stanza::PubSubOwner.registered_ns).should_not be_empty
|
|
295
|
+
n.to.should == Blather::JID.new(@host)
|
|
296
|
+
n.type.should == :set
|
|
297
|
+
end
|
|
298
|
+
@pubsub.delete '/path/to/node'
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
describe 'Blather::DSL::PubSub callbacks' do
|
|
303
|
+
before do
|
|
304
|
+
@host = 'host.name'
|
|
305
|
+
@client = Blather::Client.setup Blather::JID.new('n@d/r'), 'pass'
|
|
306
|
+
@pubsub = Blather::DSL::PubSub.new @client, @host
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
it 'returns a list of affiliations when requesting affiliations' do
|
|
310
|
+
affiliations = Blather::XMPPNode.parse(affiliations_xml)
|
|
311
|
+
response = mock()
|
|
312
|
+
response.expects(:call).with { |n| n.should == affiliations.list }
|
|
313
|
+
@client.stubs(:write).with do |n|
|
|
314
|
+
affiliations.id = n.id
|
|
315
|
+
@client.receive_data affiliations
|
|
316
|
+
true
|
|
317
|
+
end
|
|
318
|
+
@pubsub.affiliations { |n| response.call n }
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
it 'returns a list of subscriptions when requesting subscriptions' do
|
|
322
|
+
subscriptions = Blather::XMPPNode.parse(subscriptions_xml)
|
|
323
|
+
response = mock()
|
|
324
|
+
response.expects(:call).with { |n| n.should == subscriptions.list }
|
|
325
|
+
@client.stubs(:write).with do |n|
|
|
326
|
+
subscriptions.id = n.id
|
|
327
|
+
@client.receive_data subscriptions
|
|
328
|
+
true
|
|
329
|
+
end
|
|
330
|
+
@pubsub.subscriptions { |n| response.call n }
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
it 'returns a list of node items when requesting nodes' do
|
|
334
|
+
nodes = Blather::XMPPNode.parse(<<-NODES)
|
|
335
|
+
<iq type='result'
|
|
336
|
+
from='pubsub.shakespeare.lit'
|
|
337
|
+
to='francisco@denmark.lit/barracks'
|
|
338
|
+
id='nodes1'>
|
|
339
|
+
<query xmlns='http://jabber.org/protocol/disco#items'>
|
|
340
|
+
<item jid='pubsub.shakespeare.lit'
|
|
341
|
+
node='blogs'
|
|
342
|
+
name='Weblog updates'/>
|
|
343
|
+
<item jid='pubsub.shakespeare.lit'
|
|
344
|
+
node='news'
|
|
345
|
+
name='News and announcements'/>
|
|
346
|
+
</query>
|
|
347
|
+
</iq>
|
|
348
|
+
NODES
|
|
349
|
+
response = mock()
|
|
350
|
+
response.expects(:call).with { |n| n.should == nodes.items }
|
|
351
|
+
@client.stubs(:write).with do |n|
|
|
352
|
+
nodes.id = n.id
|
|
353
|
+
@client.receive_data nodes
|
|
354
|
+
true
|
|
355
|
+
end
|
|
356
|
+
@pubsub.nodes { |n| response.call n }
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
it 'returns a DiscoInfo node when requesting a node' do
|
|
360
|
+
node = Blather::XMPPNode.parse(<<-NODES)
|
|
361
|
+
<iq type='result'
|
|
362
|
+
from='pubsub.shakespeare.lit'
|
|
363
|
+
to='francisco@denmark.lit/barracks'
|
|
364
|
+
id='meta1'>
|
|
365
|
+
<query xmlns='http://jabber.org/protocol/disco#info'
|
|
366
|
+
node='blogs'>
|
|
367
|
+
<identity category='pubsub' type='collection'/>
|
|
368
|
+
</query>
|
|
369
|
+
</iq>
|
|
370
|
+
NODES
|
|
371
|
+
response = mock()
|
|
372
|
+
response.expects(:call).with { |n| n.should == node }
|
|
373
|
+
@client.stubs(:write).with do |n|
|
|
374
|
+
node.id = n.id
|
|
375
|
+
@client.receive_data node
|
|
376
|
+
true
|
|
377
|
+
end
|
|
378
|
+
@pubsub.node('blogs') { |n| response.call n }
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
it 'returns a set of items when requesting items' do
|
|
382
|
+
items = Blather::XMPPNode.parse(items_all_nodes_xml)
|
|
383
|
+
response = mock()
|
|
384
|
+
response.expects(:call).with { |n| n.map{|i|i.to_s}.should == items.items.map{|i|i.to_s} }
|
|
385
|
+
@client.stubs(:write).with do |n|
|
|
386
|
+
items.id = n.id
|
|
387
|
+
@client.receive_data items
|
|
388
|
+
true
|
|
389
|
+
end
|
|
390
|
+
@pubsub.items('princely_musings') { |n| response.call n }
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
it 'returns aa subscription node when subscribing' do
|
|
394
|
+
subscription = Blather::XMPPNode.parse(subscription_xml)
|
|
395
|
+
response = mock()
|
|
396
|
+
response.expects(:call).with { |n| n.should == subscription }
|
|
397
|
+
@client.stubs(:write).with do |n|
|
|
398
|
+
subscription.id = n.id
|
|
399
|
+
@client.receive_data subscription
|
|
400
|
+
true
|
|
401
|
+
end
|
|
402
|
+
@pubsub.subscribe('princely_musings') { |n| response.call n }
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
it 'returns aa unsubscribe node when unsubscribing' do
|
|
406
|
+
unsubscribe = Blather::XMPPNode.parse(unsubscribe_xml)
|
|
407
|
+
response = mock()
|
|
408
|
+
response.expects(:call).with { |n| n.should == unsubscribe }
|
|
409
|
+
@client.stubs(:write).with do |n|
|
|
410
|
+
unsubscribe.id = n.id
|
|
411
|
+
@client.receive_data unsubscribe
|
|
412
|
+
true
|
|
413
|
+
end
|
|
414
|
+
@pubsub.unsubscribe('princely_musings') { |n| response.call n }
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
it 'returns a publish result when publishing to a node' do
|
|
418
|
+
result = Blather::XMPPNode.parse(<<-NODE)
|
|
419
|
+
<iq type='result'
|
|
420
|
+
from='pubsub.shakespeare.lit'
|
|
421
|
+
to='hamlet@denmark.lit/blogbot'
|
|
422
|
+
id='publish1'>
|
|
423
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
|
424
|
+
<publish node='princely_musings'>
|
|
425
|
+
<item id='ae890ac52d0df67ed7cfdf51b644e901'/>
|
|
426
|
+
</publish>
|
|
427
|
+
</pubsub>
|
|
428
|
+
</iq>
|
|
429
|
+
NODE
|
|
430
|
+
response = mock()
|
|
431
|
+
response.expects(:call).with { |n| n.should == result }
|
|
432
|
+
@client.stubs(:write).with do |n|
|
|
433
|
+
result.id = n.id
|
|
434
|
+
@client.receive_data result
|
|
435
|
+
true
|
|
436
|
+
end
|
|
437
|
+
@pubsub.publish('princely_musings', 'payload') { |n| response.call n }
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
it 'returns a create result when creating a node' do
|
|
441
|
+
result = Blather::XMPPNode.parse(<<-NODE)
|
|
442
|
+
<iq type='result'
|
|
443
|
+
from='pubsub.shakespeare.lit'
|
|
444
|
+
to='hamlet@denmark.lit/elsinore'
|
|
445
|
+
id='create2'>
|
|
446
|
+
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
|
447
|
+
<create node='25e3d37dabbab9541f7523321421edc5bfeb2dae'/>
|
|
448
|
+
</pubsub>
|
|
449
|
+
</iq>
|
|
450
|
+
NODE
|
|
451
|
+
response = mock()
|
|
452
|
+
response.expects(:call).with { |n| n.should == result }
|
|
453
|
+
@client.stubs(:write).with do |n|
|
|
454
|
+
result.id = n.id
|
|
455
|
+
@client.receive_data result
|
|
456
|
+
true
|
|
457
|
+
end
|
|
458
|
+
@pubsub.create('princely_musings') { |n| response.call n }
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
it 'returns a purge result when purging a node' do
|
|
462
|
+
result = Blather::XMPPNode.parse(<<-NODE)
|
|
463
|
+
<iq type='result'
|
|
464
|
+
from='pubsub.shakespeare.lit'
|
|
465
|
+
id='purge1'/>
|
|
466
|
+
NODE
|
|
467
|
+
response = mock()
|
|
468
|
+
response.expects(:call).with { |n| n.should == result }
|
|
469
|
+
@client.stubs(:write).with do |n|
|
|
470
|
+
result.id = n.id
|
|
471
|
+
@client.receive_data result
|
|
472
|
+
true
|
|
473
|
+
end
|
|
474
|
+
@pubsub.purge('princely_musings') { |n| response.call n }
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
it 'returns a delete result when deleting a node' do
|
|
478
|
+
result = Blather::XMPPNode.parse(<<-NODE)
|
|
479
|
+
<iq type='result'
|
|
480
|
+
from='pubsub.shakespeare.lit'
|
|
481
|
+
id='delete1'/>
|
|
482
|
+
NODE
|
|
483
|
+
response = mock()
|
|
484
|
+
response.expects(:call).with { |n| n.should == result }
|
|
485
|
+
@client.stubs(:write).with do |n|
|
|
486
|
+
result.id = n.id
|
|
487
|
+
@client.receive_data result
|
|
488
|
+
true
|
|
489
|
+
end
|
|
490
|
+
@pubsub.delete('princely_musings') { |n| response.call n }
|
|
491
|
+
end
|
|
492
|
+
end
|