sprsquish-blather 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +41 -12
  3. data/examples/echo.rb +1 -1
  4. data/examples/execute.rb +0 -5
  5. data/examples/pubsub/cli.rb +64 -0
  6. data/examples/pubsub/ping_pong.rb +18 -0
  7. data/examples/rosterprint.rb +14 -0
  8. data/examples/xmpp4r/echo.rb +35 -0
  9. data/lib/blather/client/client.rb +19 -13
  10. data/lib/blather/client/dsl/pubsub.rb +133 -0
  11. data/lib/blather/client/dsl.rb +16 -0
  12. data/lib/blather/client.rb +1 -1
  13. data/lib/blather/core_ext/active_support/inheritable_attributes.rb +117 -0
  14. data/lib/blather/core_ext/active_support.rb +1 -117
  15. data/lib/blather/core_ext/nokogiri.rb +35 -0
  16. data/lib/blather/errors/sasl_error.rb +3 -1
  17. data/lib/blather/errors/stanza_error.rb +10 -17
  18. data/lib/blather/errors/stream_error.rb +11 -14
  19. data/lib/blather/errors.rb +3 -20
  20. data/lib/blather/jid.rb +1 -0
  21. data/lib/blather/roster.rb +9 -0
  22. data/lib/blather/roster_item.rb +6 -1
  23. data/lib/blather/stanza/disco/disco_info.rb +45 -33
  24. data/lib/blather/stanza/disco/disco_items.rb +32 -21
  25. data/lib/blather/stanza/disco.rb +7 -1
  26. data/lib/blather/stanza/iq/query.rb +16 -8
  27. data/lib/blather/stanza/iq/roster.rb +33 -22
  28. data/lib/blather/stanza/iq.rb +13 -8
  29. data/lib/blather/stanza/message.rb +20 -31
  30. data/lib/blather/stanza/presence/status.rb +13 -21
  31. data/lib/blather/stanza/presence/subscription.rb +11 -16
  32. data/lib/blather/stanza/presence.rb +3 -5
  33. data/lib/blather/stanza/pubsub/affiliations.rb +50 -0
  34. data/lib/blather/stanza/pubsub/create.rb +43 -0
  35. data/lib/blather/stanza/pubsub/errors.rb +9 -0
  36. data/lib/blather/stanza/pubsub/event.rb +77 -0
  37. data/lib/blather/stanza/pubsub/items.rb +63 -0
  38. data/lib/blather/stanza/pubsub/publish.rb +58 -0
  39. data/lib/blather/stanza/pubsub/retract.rb +53 -0
  40. data/lib/blather/stanza/pubsub/subscribe.rb +42 -0
  41. data/lib/blather/stanza/pubsub/subscription.rb +66 -0
  42. data/lib/blather/stanza/pubsub/subscriptions.rb +55 -0
  43. data/lib/blather/stanza/pubsub/unsubscribe.rb +42 -0
  44. data/lib/blather/stanza/pubsub.rb +63 -0
  45. data/lib/blather/stanza/pubsub_owner/delete.rb +34 -0
  46. data/lib/blather/stanza/pubsub_owner/purge.rb +34 -0
  47. data/lib/blather/stanza/pubsub_owner.rb +41 -0
  48. data/lib/blather/stanza.rb +35 -18
  49. data/lib/blather/stream/client.rb +1 -2
  50. data/lib/blather/stream/component.rb +9 -5
  51. data/lib/blather/stream/features/resource.rb +63 -0
  52. data/lib/blather/stream/{sasl.rb → features/sasl.rb} +53 -52
  53. data/lib/blather/stream/features/session.rb +44 -0
  54. data/lib/blather/stream/features/tls.rb +28 -0
  55. data/lib/blather/stream/features.rb +53 -0
  56. data/lib/blather/stream/parser.rb +70 -46
  57. data/lib/blather/stream.rb +76 -168
  58. data/lib/blather/xmpp_node.rb +113 -52
  59. data/lib/blather.rb +35 -12
  60. data/spec/blather/client/client_spec.rb +44 -58
  61. data/spec/blather/client/dsl/pubsub_spec.rb +465 -0
  62. data/spec/blather/client/dsl_spec.rb +19 -6
  63. data/spec/blather/core_ext/nokogiri_spec.rb +83 -0
  64. data/spec/blather/errors/sasl_error_spec.rb +8 -8
  65. data/spec/blather/errors/stanza_error_spec.rb +25 -33
  66. data/spec/blather/errors/stream_error_spec.rb +21 -16
  67. data/spec/blather/errors_spec.rb +4 -11
  68. data/spec/blather/jid_spec.rb +31 -30
  69. data/spec/blather/roster_item_spec.rb +34 -23
  70. data/spec/blather/roster_spec.rb +27 -12
  71. data/spec/blather/stanza/discos/disco_info_spec.rb +61 -42
  72. data/spec/blather/stanza/discos/disco_items_spec.rb +47 -35
  73. data/spec/blather/stanza/iq/query_spec.rb +34 -11
  74. data/spec/blather/stanza/iq/roster_spec.rb +47 -30
  75. data/spec/blather/stanza/iq_spec.rb +19 -14
  76. data/spec/blather/stanza/message_spec.rb +30 -17
  77. data/spec/blather/stanza/presence/status_spec.rb +43 -20
  78. data/spec/blather/stanza/presence/subscription_spec.rb +41 -21
  79. data/spec/blather/stanza/presence_spec.rb +34 -21
  80. data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
  81. data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
  82. data/spec/blather/stanza/pubsub/event_spec.rb +84 -0
  83. data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
  84. data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
  85. data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
  86. data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
  87. data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
  88. data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
  89. data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +61 -0
  90. data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
  91. data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
  92. data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
  93. data/spec/blather/stanza/pubsub_spec.rb +62 -0
  94. data/spec/blather/stanza_spec.rb +53 -38
  95. data/spec/blather/stream/client_spec.rb +231 -88
  96. data/spec/blather/stream/component_spec.rb +14 -5
  97. data/spec/blather/stream/parser_spec.rb +145 -0
  98. data/spec/blather/xmpp_node_spec.rb +192 -96
  99. data/spec/fixtures/pubsub.rb +311 -0
  100. data/spec/spec_helper.rb +5 -4
  101. metadata +53 -17
  102. data/Rakefile +0 -139
  103. data/ext/extconf.rb +0 -65
  104. data/ext/push_parser.c +0 -209
  105. data/lib/blather/core_ext/libxml.rb +0 -28
  106. data/lib/blather/stream/resource.rb +0 -48
  107. data/lib/blather/stream/session.rb +0 -36
  108. data/lib/blather/stream/stream_handler.rb +0 -39
  109. data/lib/blather/stream/tls.rb +0 -33
  110. data/spec/blather/core_ext/libxml_spec.rb +0 -58
@@ -0,0 +1,50 @@
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::PubSubOwner::Purge do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:purge, 'http://jabber.org/protocol/pubsub#owner').must_equal Blather::Stanza::PubSubOwner::Purge
7
+ end
8
+
9
+ it 'can be imported' do
10
+ Blather::XMPPNode.import(parse_stanza(<<-NODE).root).must_be_instance_of Blather::Stanza::PubSubOwner::Purge
11
+ <iq type='set'
12
+ from='hamlet@denmark.lit/elsinore'
13
+ to='pubsub.shakespeare.lit'
14
+ id='purge1'>
15
+ <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
16
+ <purge node='princely_musings'/>
17
+ </pubsub>
18
+ </iq>
19
+ NODE
20
+ end
21
+
22
+ it 'ensures an purge node is present on create' do
23
+ purge = Blather::Stanza::PubSubOwner::Purge.new
24
+ purge.find('//ns:pubsub/ns:purge', :ns => Blather::Stanza::PubSubOwner.registered_ns).wont_be_empty
25
+ end
26
+
27
+ it 'ensures an purge node exists when calling #purge_node' do
28
+ purge = Blather::Stanza::PubSubOwner::Purge.new
29
+ purge.pubsub.remove_children :purge
30
+ purge.find('//ns:pubsub/ns:purge', :ns => Blather::Stanza::PubSubOwner.registered_ns).must_be_empty
31
+
32
+ purge.purge_node.wont_be_nil
33
+ purge.find('//ns:pubsub/ns:purge', :ns => Blather::Stanza::PubSubOwner.registered_ns).wont_be_empty
34
+ end
35
+
36
+ it 'defaults to a set node' do
37
+ purge = Blather::Stanza::PubSubOwner::Purge.new
38
+ purge.type.must_equal :set
39
+ end
40
+
41
+ it 'sets the host if requested' do
42
+ purge = Blather::Stanza::PubSubOwner::Purge.new :set, 'pubsub.jabber.local'
43
+ purge.to.must_equal Blather::JID.new('pubsub.jabber.local')
44
+ end
45
+
46
+ it 'sets the node' do
47
+ purge = Blather::Stanza::PubSubOwner::Purge.new :set, 'host', 'node-name'
48
+ purge.node.must_equal 'node-name'
49
+ end
50
+ end
@@ -0,0 +1,27 @@
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::PubSubOwner do
5
+ it 'registers itself' do
6
+ Blather::XMPPNode.class_from_registration(:pubsub, 'http://jabber.org/protocol/pubsub#owner').must_equal Blather::Stanza::PubSubOwner
7
+ end
8
+
9
+ it 'ensures a pubusb node is present on create' do
10
+ pubsub = Blather::Stanza::PubSubOwner.new
11
+ pubsub.find_first('/iq/ns:pubsub', :ns => Blather::Stanza::PubSubOwner.registered_ns).wont_be_nil
12
+ end
13
+
14
+ it 'ensures a pubsub node exists when calling #pubsub' do
15
+ pubsub = Blather::Stanza::PubSubOwner.new
16
+ pubsub.remove_children :pubsub
17
+ pubsub.find_first('/iq/ns:pubsub', :ns => Blather::Stanza::PubSubOwner.registered_ns).must_be_nil
18
+
19
+ pubsub.pubsub.wont_be_nil
20
+ pubsub.find_first('/iq/ns:pubsub', :ns => Blather::Stanza::PubSubOwner.registered_ns).wont_be_nil
21
+ end
22
+
23
+ it 'sets the host if requested' do
24
+ aff = Blather::Stanza::PubSubOwner.new :get, 'pubsub.jabber.local'
25
+ aff.to.must_equal Blather::JID.new('pubsub.jabber.local')
26
+ end
27
+ end
@@ -0,0 +1,62 @@
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
+ end
@@ -1,34 +1,49 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
2
2
 
3
- describe 'Blather::Stanza' do
3
+ describe Blather::Stanza do
4
4
  it 'provides .next_id helper for generating new IDs' do
5
- proc { Stanza.next_id }.must_change 'Stanza.next_id'
5
+ proc { Blather::Stanza.next_id }.must_change 'Blather::Stanza.next_id'
6
6
  end
7
7
 
8
- it 'can import a node' do
9
- s = Stanza.import XMPPNode.new('foo')
10
- s.element_name.must_equal 'foo'
8
+ it 'provides a handler registration mechanism' do
9
+ class Registration < Blather::Stanza; register :handler_test, :handler, 'test:namespace'; end
10
+ Registration.handler_heirarchy.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
11
22
  end
12
23
 
13
- it 'sets the ID when created' do
14
- Stanza.new('message').id.wont_be_nil
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_heirarchy.wont_include :sub_class
28
+ SubClassRegister.handler_heirarchy.must_include :super_class
15
29
  end
16
30
 
17
- it 'sets the document when created' do
18
- Stanza.new('message').doc.wont_be_nil
31
+ it 'can import a node' do
32
+ s = Blather::Stanza.import Blather::XMPPNode.new('foo')
33
+ s.element_name.must_equal 'foo'
19
34
  end
20
35
 
21
36
  it 'provides an #error? helper' do
22
- s = Stanza.new('message')
37
+ s = Blather::Stanza.new('message')
23
38
  s.error?.must_equal false
24
39
  s.type = :error
25
40
  s.error?.must_equal true
26
41
  end
27
42
 
28
43
  it 'will generate a reply' do
29
- s = Stanza.new('message')
30
- s.from = f = JID.new('n@d/r')
31
- s.to = t = JID.new('d@n/r')
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')
32
47
 
33
48
  r = s.reply
34
49
  r.object_id.wont_equal s.object_id
@@ -37,9 +52,9 @@ describe 'Blather::Stanza' do
37
52
  end
38
53
 
39
54
  it 'convert to a reply' do
40
- s = Stanza.new('message')
41
- s.from = f = JID.new('n@d/r')
42
- s.to = t = JID.new('d@n/r')
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')
43
58
 
44
59
  r = s.reply!
45
60
  r.object_id.must_equal s.object_id
@@ -48,53 +63,53 @@ describe 'Blather::Stanza' do
48
63
  end
49
64
 
50
65
  it 'provides "attr_accessor" for id' do
51
- s = Stanza.new('message')
52
- s.id.wont_be_nil
53
- s['id'].wont_be_nil
54
-
55
- s.id = nil
66
+ s = Blather::Stanza.new('message')
56
67
  s.id.must_be_nil
57
- 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'
58
73
  end
59
74
 
60
75
  it 'provides "attr_accessor" for to' do
61
- s = Stanza.new('message')
76
+ s = Blather::Stanza.new('message')
62
77
  s.to.must_be_nil
63
- s['to'].must_be_nil
78
+ s[:to].must_be_nil
64
79
 
65
- s.to = JID.new('n@d/r')
80
+ s.to = Blather::JID.new('n@d/r')
66
81
  s.to.wont_be_nil
67
- s.to.must_be_kind_of JID
82
+ s.to.must_be_kind_of Blather::JID
68
83
 
69
- s['to'].wont_be_nil
70
- s['to'].must_equal 'n@d/r'
84
+ s[:to].wont_be_nil
85
+ s[:to].must_equal 'n@d/r'
71
86
  end
72
87
 
73
88
  it 'provides "attr_accessor" for from' do
74
- s = Stanza.new('message')
89
+ s = Blather::Stanza.new('message')
75
90
  s.from.must_be_nil
76
- s['from'].must_be_nil
91
+ s[:from].must_be_nil
77
92
 
78
- s.from = JID.new('n@d/r')
93
+ s.from = Blather::JID.new('n@d/r')
79
94
  s.from.wont_be_nil
80
- s.from.must_be_kind_of JID
95
+ s.from.must_be_kind_of Blather::JID
81
96
 
82
- s['from'].wont_be_nil
83
- s['from'].must_equal 'n@d/r'
97
+ s[:from].wont_be_nil
98
+ s[:from].must_equal 'n@d/r'
84
99
  end
85
100
 
86
101
  it 'provides "attr_accessor" for type' do
87
- s = Stanza.new('message')
102
+ s = Blather::Stanza.new('message')
88
103
  s.type.must_be_nil
89
- s['type'].must_be_nil
104
+ s[:type].must_be_nil
90
105
 
91
106
  s.type = 'testing'
92
107
  s.type.wont_be_nil
93
- s['type'].wont_be_nil
108
+ s[:type].wont_be_nil
94
109
  end
95
110
 
96
111
  it 'can be converted into an error by error name' do
97
- s = Stanza.new('message')
112
+ s = Blather::Stanza.new('message')
98
113
  err = s.as_error 'internal-server-error', 'cancel'
99
114
  err.name.must_equal :internal_server_error
100
115
  end