shingara-blather 0.4.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/LICENSE +22 -0
- data/README.md +162 -0
- data/examples/echo.rb +18 -0
- data/examples/execute.rb +16 -0
- data/examples/ping_pong.rb +37 -0
- data/examples/print_hierarchy.rb +76 -0
- data/examples/rosterprint.rb +14 -0
- data/examples/stream_only.rb +27 -0
- data/examples/xmpp4r/echo.rb +35 -0
- data/lib/blather/client/client.rb +310 -0
- data/lib/blather/client/dsl/pubsub.rb +170 -0
- data/lib/blather/client/dsl.rb +264 -0
- data/lib/blather/client.rb +87 -0
- data/lib/blather/core_ext/nokogiri.rb +40 -0
- data/lib/blather/errors/sasl_error.rb +43 -0
- data/lib/blather/errors/stanza_error.rb +107 -0
- data/lib/blather/errors/stream_error.rb +82 -0
- data/lib/blather/errors.rb +69 -0
- data/lib/blather/jid.rb +142 -0
- data/lib/blather/roster.rb +111 -0
- data/lib/blather/roster_item.rb +122 -0
- data/lib/blather/stanza/disco/disco_info.rb +176 -0
- data/lib/blather/stanza/disco/disco_items.rb +132 -0
- data/lib/blather/stanza/disco.rb +25 -0
- data/lib/blather/stanza/iq/query.rb +53 -0
- data/lib/blather/stanza/iq/roster.rb +179 -0
- data/lib/blather/stanza/iq.rb +138 -0
- data/lib/blather/stanza/message.rb +332 -0
- data/lib/blather/stanza/presence/status.rb +212 -0
- data/lib/blather/stanza/presence/subscription.rb +101 -0
- data/lib/blather/stanza/presence.rb +163 -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 +123 -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 +134 -0
- data/lib/blather/stanza/pubsub/subscriptions.rb +81 -0
- data/lib/blather/stanza/pubsub/unsubscribe.rb +68 -0
- data/lib/blather/stanza/pubsub.rb +129 -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/pubsub_owner.rb +51 -0
- data/lib/blather/stanza.rb +149 -0
- data/lib/blather/stream/client.rb +31 -0
- data/lib/blather/stream/component.rb +38 -0
- data/lib/blather/stream/features/resource.rb +63 -0
- data/lib/blather/stream/features/sasl.rb +187 -0
- data/lib/blather/stream/features/session.rb +44 -0
- data/lib/blather/stream/features/tls.rb +28 -0
- data/lib/blather/stream/features.rb +53 -0
- data/lib/blather/stream/parser.rb +102 -0
- data/lib/blather/stream.rb +231 -0
- data/lib/blather/xmpp_node.rb +218 -0
- data/lib/blather.rb +78 -0
- data/spec/blather/client/client_spec.rb +559 -0
- data/spec/blather/client/dsl/pubsub_spec.rb +462 -0
- data/spec/blather/client/dsl_spec.rb +143 -0
- data/spec/blather/core_ext/nokogiri_spec.rb +83 -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/jid_spec.rb +87 -0
- data/spec/blather/roster_item_spec.rb +96 -0
- data/spec/blather/roster_spec.rb +103 -0
- data/spec/blather/stanza/discos/disco_info_spec.rb +226 -0
- data/spec/blather/stanza/discos/disco_items_spec.rb +148 -0
- data/spec/blather/stanza/iq/query_spec.rb +64 -0
- data/spec/blather/stanza/iq/roster_spec.rb +140 -0
- data/spec/blather/stanza/iq_spec.rb +45 -0
- data/spec/blather/stanza/message_spec.rb +132 -0
- data/spec/blather/stanza/presence/status_spec.rb +132 -0
- data/spec/blather/stanza/presence/subscription_spec.rb +105 -0
- data/spec/blather/stanza/presence_spec.rb +66 -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 +84 -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 +61 -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 +67 -0
- data/spec/blather/stanza_spec.rb +116 -0
- data/spec/blather/stream/client_spec.rb +1011 -0
- data/spec/blather/stream/component_spec.rb +95 -0
- data/spec/blather/stream/parser_spec.rb +145 -0
- data/spec/blather/xmpp_node_spec.rb +231 -0
- data/spec/fixtures/pubsub.rb +311 -0
- data/spec/spec_helper.rb +43 -0
- metadata +249 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
|
|
2
|
+
require File.join(File.dirname(__FILE__), *%w[.. .. fixtures pubsub])
|
|
3
|
+
|
|
4
|
+
describe Blather::Stanza::PubSub do
|
|
5
|
+
it 'registers itself' do
|
|
6
|
+
Blather::XMPPNode.class_from_registration(:pubsub, 'http://jabber.org/protocol/pubsub').must_equal Blather::Stanza::PubSub
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'ensures a pubusb node is present on create' do
|
|
10
|
+
pubsub = Blather::Stanza::PubSub.new
|
|
11
|
+
pubsub.find_first('/iq/ns:pubsub', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_nil
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'ensures a pubsub node exists when calling #pubsub' do
|
|
15
|
+
pubsub = Blather::Stanza::PubSub.new
|
|
16
|
+
pubsub.remove_children :pubsub
|
|
17
|
+
pubsub.find_first('/iq/ns:pubsub', :ns => Blather::Stanza::PubSub.registered_ns).must_be_nil
|
|
18
|
+
|
|
19
|
+
pubsub.pubsub.wont_be_nil
|
|
20
|
+
pubsub.find_first('/iq/ns:pubsub', :ns => Blather::Stanza::PubSub.registered_ns).wont_be_nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'sets the host if requested' do
|
|
24
|
+
aff = Blather::Stanza::PubSub.new :get, 'pubsub.jabber.local'
|
|
25
|
+
aff.to.must_equal Blather::JID.new('pubsub.jabber.local')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'ensures newly inherited items are PubSubItem objects' do
|
|
29
|
+
pubsub = Blather::XMPPNode.import(parse_stanza(items_all_nodes_xml).root)
|
|
30
|
+
pubsub.items.map { |i| i.class }.uniq.must_equal [Blather::Stanza::PubSub::PubSubItem]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe Blather::Stanza::PubSub::PubSubItem do
|
|
35
|
+
it 'can be initialized with just an ID' do
|
|
36
|
+
id = 'foobarbaz'
|
|
37
|
+
item = Blather::Stanza::PubSub::Items::PubSubItem.new id
|
|
38
|
+
item.id.must_equal id
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'can be initialized with a payload' do
|
|
42
|
+
payload = 'foobarbaz'
|
|
43
|
+
item = Blather::Stanza::PubSub::Items::PubSubItem.new 'foo', payload
|
|
44
|
+
item.payload.must_equal payload
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'allows the payload to be set' do
|
|
48
|
+
item = Blather::Stanza::PubSub::Items::PubSubItem.new
|
|
49
|
+
item.payload.must_be_nil
|
|
50
|
+
item.payload = 'testing'
|
|
51
|
+
item.payload.must_equal 'testing'
|
|
52
|
+
item.content.must_equal 'testing'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'allows the payload to be unset' do
|
|
56
|
+
payload = 'foobarbaz'
|
|
57
|
+
item = Blather::Stanza::PubSub::Items::PubSubItem.new 'foo', payload
|
|
58
|
+
item.payload.must_equal payload
|
|
59
|
+
item.payload = nil
|
|
60
|
+
item.payload.must_be_nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'must have an entry child to item' do
|
|
64
|
+
item = Blather::Stanza::PubSub::Items::PubSubItem.new 'foo', 'payload'
|
|
65
|
+
item.find_first('ns:entry', :ns => 'http://www.w3.org/2005/Atom').wont_be_nil
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
|
|
2
|
+
|
|
3
|
+
describe Blather::Stanza do
|
|
4
|
+
it 'provides .next_id helper for generating new IDs' do
|
|
5
|
+
proc { Blather::Stanza.next_id }.must_change 'Blather::Stanza.next_id'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'provides a handler registration mechanism' do
|
|
9
|
+
class Registration < Blather::Stanza; register :handler_test, :handler, 'test:namespace'; end
|
|
10
|
+
Registration.handler_hierarchy.must_include :handler_test
|
|
11
|
+
Blather::Stanza.handler_list.must_include :handler_test
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'can register based on handler' do
|
|
15
|
+
class RegisterHandler < Blather::Stanza; register :register_handler; end
|
|
16
|
+
Blather::Stanza.class_from_registration(:register_handler, nil).must_equal RegisterHandler
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'can register based on given name' do
|
|
20
|
+
class RegisterName < Blather::Stanza; register :handler, :registered_name; end
|
|
21
|
+
Blather::Stanza.class_from_registration(:registered_name, nil).must_equal RegisterName
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'can register subclass handlers' do
|
|
25
|
+
class SuperClassRegister < Blather::Stanza; register :super_class; end
|
|
26
|
+
class SubClassRegister < SuperClassRegister; register :sub_class; end
|
|
27
|
+
SuperClassRegister.handler_hierarchy.wont_include :sub_class
|
|
28
|
+
SubClassRegister.handler_hierarchy.must_include :super_class
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'can import a node' do
|
|
32
|
+
s = Blather::Stanza.import Blather::XMPPNode.new('foo')
|
|
33
|
+
s.element_name.must_equal 'foo'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'provides an #error? helper' do
|
|
37
|
+
s = Blather::Stanza.new('message')
|
|
38
|
+
s.error?.must_equal false
|
|
39
|
+
s.type = :error
|
|
40
|
+
s.error?.must_equal true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'will generate a reply' do
|
|
44
|
+
s = Blather::Stanza.new('message')
|
|
45
|
+
s.from = f = Blather::JID.new('n@d/r')
|
|
46
|
+
s.to = t = Blather::JID.new('d@n/r')
|
|
47
|
+
|
|
48
|
+
r = s.reply
|
|
49
|
+
r.object_id.wont_equal s.object_id
|
|
50
|
+
r.from.must_equal t
|
|
51
|
+
r.to.must_equal f
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'convert to a reply' do
|
|
55
|
+
s = Blather::Stanza.new('message')
|
|
56
|
+
s.from = f = Blather::JID.new('n@d/r')
|
|
57
|
+
s.to = t = Blather::JID.new('d@n/r')
|
|
58
|
+
|
|
59
|
+
r = s.reply!
|
|
60
|
+
r.object_id.must_equal s.object_id
|
|
61
|
+
r.from.must_equal t
|
|
62
|
+
r.to.must_equal f
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'provides "attr_accessor" for id' do
|
|
66
|
+
s = Blather::Stanza.new('message')
|
|
67
|
+
s.id.must_be_nil
|
|
68
|
+
s[:id].must_be_nil
|
|
69
|
+
|
|
70
|
+
s.id = '123'
|
|
71
|
+
s.id.must_equal '123'
|
|
72
|
+
s[:id].must_equal '123'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'provides "attr_accessor" for to' do
|
|
76
|
+
s = Blather::Stanza.new('message')
|
|
77
|
+
s.to.must_be_nil
|
|
78
|
+
s[:to].must_be_nil
|
|
79
|
+
|
|
80
|
+
s.to = Blather::JID.new('n@d/r')
|
|
81
|
+
s.to.wont_be_nil
|
|
82
|
+
s.to.must_be_kind_of Blather::JID
|
|
83
|
+
|
|
84
|
+
s[:to].wont_be_nil
|
|
85
|
+
s[:to].must_equal 'n@d/r'
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'provides "attr_accessor" for from' do
|
|
89
|
+
s = Blather::Stanza.new('message')
|
|
90
|
+
s.from.must_be_nil
|
|
91
|
+
s[:from].must_be_nil
|
|
92
|
+
|
|
93
|
+
s.from = Blather::JID.new('n@d/r')
|
|
94
|
+
s.from.wont_be_nil
|
|
95
|
+
s.from.must_be_kind_of Blather::JID
|
|
96
|
+
|
|
97
|
+
s[:from].wont_be_nil
|
|
98
|
+
s[:from].must_equal 'n@d/r'
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'provides "attr_accessor" for type' do
|
|
102
|
+
s = Blather::Stanza.new('message')
|
|
103
|
+
s.type.must_be_nil
|
|
104
|
+
s[:type].must_be_nil
|
|
105
|
+
|
|
106
|
+
s.type = 'testing'
|
|
107
|
+
s.type.wont_be_nil
|
|
108
|
+
s[:type].wont_be_nil
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'can be converted into an error by error name' do
|
|
112
|
+
s = Blather::Stanza.new('message')
|
|
113
|
+
err = s.as_error 'internal-server-error', 'cancel'
|
|
114
|
+
err.name.must_equal :internal_server_error
|
|
115
|
+
end
|
|
116
|
+
end
|