shingara-blather 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/LICENSE +22 -0
  2. data/README.md +162 -0
  3. data/examples/echo.rb +18 -0
  4. data/examples/execute.rb +16 -0
  5. data/examples/ping_pong.rb +37 -0
  6. data/examples/print_hierarchy.rb +76 -0
  7. data/examples/rosterprint.rb +14 -0
  8. data/examples/stream_only.rb +27 -0
  9. data/examples/xmpp4r/echo.rb +35 -0
  10. data/lib/blather/client/client.rb +310 -0
  11. data/lib/blather/client/dsl/pubsub.rb +170 -0
  12. data/lib/blather/client/dsl.rb +264 -0
  13. data/lib/blather/client.rb +87 -0
  14. data/lib/blather/core_ext/nokogiri.rb +40 -0
  15. data/lib/blather/errors/sasl_error.rb +43 -0
  16. data/lib/blather/errors/stanza_error.rb +107 -0
  17. data/lib/blather/errors/stream_error.rb +82 -0
  18. data/lib/blather/errors.rb +69 -0
  19. data/lib/blather/jid.rb +142 -0
  20. data/lib/blather/roster.rb +111 -0
  21. data/lib/blather/roster_item.rb +122 -0
  22. data/lib/blather/stanza/disco/disco_info.rb +176 -0
  23. data/lib/blather/stanza/disco/disco_items.rb +132 -0
  24. data/lib/blather/stanza/disco.rb +25 -0
  25. data/lib/blather/stanza/iq/query.rb +53 -0
  26. data/lib/blather/stanza/iq/roster.rb +179 -0
  27. data/lib/blather/stanza/iq.rb +138 -0
  28. data/lib/blather/stanza/message.rb +332 -0
  29. data/lib/blather/stanza/presence/status.rb +212 -0
  30. data/lib/blather/stanza/presence/subscription.rb +101 -0
  31. data/lib/blather/stanza/presence.rb +163 -0
  32. data/lib/blather/stanza/pubsub/affiliations.rb +79 -0
  33. data/lib/blather/stanza/pubsub/create.rb +65 -0
  34. data/lib/blather/stanza/pubsub/errors.rb +18 -0
  35. data/lib/blather/stanza/pubsub/event.rb +123 -0
  36. data/lib/blather/stanza/pubsub/items.rb +103 -0
  37. data/lib/blather/stanza/pubsub/publish.rb +103 -0
  38. data/lib/blather/stanza/pubsub/retract.rb +92 -0
  39. data/lib/blather/stanza/pubsub/subscribe.rb +68 -0
  40. data/lib/blather/stanza/pubsub/subscription.rb +134 -0
  41. data/lib/blather/stanza/pubsub/subscriptions.rb +81 -0
  42. data/lib/blather/stanza/pubsub/unsubscribe.rb +68 -0
  43. data/lib/blather/stanza/pubsub.rb +129 -0
  44. data/lib/blather/stanza/pubsub_owner/delete.rb +52 -0
  45. data/lib/blather/stanza/pubsub_owner/purge.rb +52 -0
  46. data/lib/blather/stanza/pubsub_owner.rb +51 -0
  47. data/lib/blather/stanza.rb +149 -0
  48. data/lib/blather/stream/client.rb +31 -0
  49. data/lib/blather/stream/component.rb +38 -0
  50. data/lib/blather/stream/features/resource.rb +63 -0
  51. data/lib/blather/stream/features/sasl.rb +187 -0
  52. data/lib/blather/stream/features/session.rb +44 -0
  53. data/lib/blather/stream/features/tls.rb +28 -0
  54. data/lib/blather/stream/features.rb +53 -0
  55. data/lib/blather/stream/parser.rb +102 -0
  56. data/lib/blather/stream.rb +231 -0
  57. data/lib/blather/xmpp_node.rb +218 -0
  58. data/lib/blather.rb +78 -0
  59. data/spec/blather/client/client_spec.rb +559 -0
  60. data/spec/blather/client/dsl/pubsub_spec.rb +462 -0
  61. data/spec/blather/client/dsl_spec.rb +143 -0
  62. data/spec/blather/core_ext/nokogiri_spec.rb +83 -0
  63. data/spec/blather/errors/sasl_error_spec.rb +33 -0
  64. data/spec/blather/errors/stanza_error_spec.rb +129 -0
  65. data/spec/blather/errors/stream_error_spec.rb +108 -0
  66. data/spec/blather/errors_spec.rb +33 -0
  67. data/spec/blather/jid_spec.rb +87 -0
  68. data/spec/blather/roster_item_spec.rb +96 -0
  69. data/spec/blather/roster_spec.rb +103 -0
  70. data/spec/blather/stanza/discos/disco_info_spec.rb +226 -0
  71. data/spec/blather/stanza/discos/disco_items_spec.rb +148 -0
  72. data/spec/blather/stanza/iq/query_spec.rb +64 -0
  73. data/spec/blather/stanza/iq/roster_spec.rb +140 -0
  74. data/spec/blather/stanza/iq_spec.rb +45 -0
  75. data/spec/blather/stanza/message_spec.rb +132 -0
  76. data/spec/blather/stanza/presence/status_spec.rb +132 -0
  77. data/spec/blather/stanza/presence/subscription_spec.rb +105 -0
  78. data/spec/blather/stanza/presence_spec.rb +66 -0
  79. data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
  80. data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
  81. data/spec/blather/stanza/pubsub/event_spec.rb +84 -0
  82. data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
  83. data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
  84. data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
  85. data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
  86. data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
  87. data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
  88. data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +61 -0
  89. data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
  90. data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
  91. data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
  92. data/spec/blather/stanza/pubsub_spec.rb +67 -0
  93. data/spec/blather/stanza_spec.rb +116 -0
  94. data/spec/blather/stream/client_spec.rb +1011 -0
  95. data/spec/blather/stream/component_spec.rb +95 -0
  96. data/spec/blather/stream/parser_spec.rb +145 -0
  97. data/spec/blather/xmpp_node_spec.rb +231 -0
  98. data/spec/fixtures/pubsub.rb +311 -0
  99. data/spec/spec_helper.rb +43 -0
  100. 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