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.
Files changed (150) hide show
  1. data/.autotest +13 -0
  2. data/.gemtest +0 -0
  3. data/.gitignore +19 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +8 -0
  6. data/CHANGELOG.md +249 -0
  7. data/Gemfile +4 -0
  8. data/Guardfile +5 -0
  9. data/LICENSE +22 -0
  10. data/README.md +413 -0
  11. data/Rakefile +20 -0
  12. data/TODO.md +2 -0
  13. data/blather.gemspec +51 -0
  14. data/examples/certs/README +20 -0
  15. data/examples/certs/ca-bundle.crt +3987 -0
  16. data/examples/echo.rb +19 -0
  17. data/examples/execute.rb +17 -0
  18. data/examples/ping_pong.rb +38 -0
  19. data/examples/print_hierarchy.rb +77 -0
  20. data/examples/rosterprint.rb +15 -0
  21. data/examples/stream_only.rb +28 -0
  22. data/examples/trusted_echo.rb +21 -0
  23. data/examples/xmpp4r/echo.rb +36 -0
  24. data/lib/blather.rb +112 -0
  25. data/lib/blather/cert_store.rb +53 -0
  26. data/lib/blather/client.rb +95 -0
  27. data/lib/blather/client/client.rb +345 -0
  28. data/lib/blather/client/dsl.rb +320 -0
  29. data/lib/blather/client/dsl/pubsub.rb +174 -0
  30. data/lib/blather/core_ext/eventmachine.rb +125 -0
  31. data/lib/blather/core_ext/ipaddr.rb +20 -0
  32. data/lib/blather/errors.rb +69 -0
  33. data/lib/blather/errors/sasl_error.rb +44 -0
  34. data/lib/blather/errors/stanza_error.rb +110 -0
  35. data/lib/blather/errors/stream_error.rb +84 -0
  36. data/lib/blather/file_transfer.rb +107 -0
  37. data/lib/blather/file_transfer/ibb.rb +68 -0
  38. data/lib/blather/file_transfer/s5b.rb +114 -0
  39. data/lib/blather/jid.rb +141 -0
  40. data/lib/blather/roster.rb +118 -0
  41. data/lib/blather/roster_item.rb +146 -0
  42. data/lib/blather/stanza.rb +167 -0
  43. data/lib/blather/stanza/disco.rb +32 -0
  44. data/lib/blather/stanza/disco/capabilities.rb +161 -0
  45. data/lib/blather/stanza/disco/disco_info.rb +205 -0
  46. data/lib/blather/stanza/disco/disco_items.rb +134 -0
  47. data/lib/blather/stanza/iq.rb +144 -0
  48. data/lib/blather/stanza/iq/command.rb +339 -0
  49. data/lib/blather/stanza/iq/ibb.rb +86 -0
  50. data/lib/blather/stanza/iq/ping.rb +50 -0
  51. data/lib/blather/stanza/iq/query.rb +53 -0
  52. data/lib/blather/stanza/iq/roster.rb +185 -0
  53. data/lib/blather/stanza/iq/s5b.rb +208 -0
  54. data/lib/blather/stanza/iq/si.rb +415 -0
  55. data/lib/blather/stanza/iq/vcard.rb +149 -0
  56. data/lib/blather/stanza/message.rb +428 -0
  57. data/lib/blather/stanza/message/muc_user.rb +119 -0
  58. data/lib/blather/stanza/muc/muc_user_base.rb +54 -0
  59. data/lib/blather/stanza/presence.rb +172 -0
  60. data/lib/blather/stanza/presence/c.rb +100 -0
  61. data/lib/blather/stanza/presence/muc.rb +35 -0
  62. data/lib/blather/stanza/presence/muc_user.rb +147 -0
  63. data/lib/blather/stanza/presence/status.rb +218 -0
  64. data/lib/blather/stanza/presence/subscription.rb +100 -0
  65. data/lib/blather/stanza/pubsub.rb +119 -0
  66. data/lib/blather/stanza/pubsub/affiliations.rb +79 -0
  67. data/lib/blather/stanza/pubsub/create.rb +65 -0
  68. data/lib/blather/stanza/pubsub/errors.rb +18 -0
  69. data/lib/blather/stanza/pubsub/event.rb +139 -0
  70. data/lib/blather/stanza/pubsub/items.rb +103 -0
  71. data/lib/blather/stanza/pubsub/publish.rb +103 -0
  72. data/lib/blather/stanza/pubsub/retract.rb +92 -0
  73. data/lib/blather/stanza/pubsub/subscribe.rb +68 -0
  74. data/lib/blather/stanza/pubsub/subscription.rb +135 -0
  75. data/lib/blather/stanza/pubsub/subscriptions.rb +83 -0
  76. data/lib/blather/stanza/pubsub/unsubscribe.rb +84 -0
  77. data/lib/blather/stanza/pubsub_owner.rb +51 -0
  78. data/lib/blather/stanza/pubsub_owner/delete.rb +52 -0
  79. data/lib/blather/stanza/pubsub_owner/purge.rb +52 -0
  80. data/lib/blather/stanza/x.rb +416 -0
  81. data/lib/blather/stream.rb +266 -0
  82. data/lib/blather/stream/client.rb +32 -0
  83. data/lib/blather/stream/component.rb +39 -0
  84. data/lib/blather/stream/features.rb +70 -0
  85. data/lib/blather/stream/features/register.rb +38 -0
  86. data/lib/blather/stream/features/resource.rb +63 -0
  87. data/lib/blather/stream/features/sasl.rb +190 -0
  88. data/lib/blather/stream/features/session.rb +45 -0
  89. data/lib/blather/stream/features/tls.rb +29 -0
  90. data/lib/blather/stream/parser.rb +102 -0
  91. data/lib/blather/version.rb +3 -0
  92. data/lib/blather/xmpp_node.rb +94 -0
  93. data/spec/blather/client/client_spec.rb +687 -0
  94. data/spec/blather/client/dsl/pubsub_spec.rb +492 -0
  95. data/spec/blather/client/dsl_spec.rb +266 -0
  96. data/spec/blather/errors/sasl_error_spec.rb +33 -0
  97. data/spec/blather/errors/stanza_error_spec.rb +129 -0
  98. data/spec/blather/errors/stream_error_spec.rb +108 -0
  99. data/spec/blather/errors_spec.rb +33 -0
  100. data/spec/blather/file_transfer_spec.rb +135 -0
  101. data/spec/blather/jid_spec.rb +87 -0
  102. data/spec/blather/roster_item_spec.rb +134 -0
  103. data/spec/blather/roster_spec.rb +107 -0
  104. data/spec/blather/stanza/discos/disco_info_spec.rb +247 -0
  105. data/spec/blather/stanza/discos/disco_items_spec.rb +154 -0
  106. data/spec/blather/stanza/iq/command_spec.rb +206 -0
  107. data/spec/blather/stanza/iq/ibb_spec.rb +124 -0
  108. data/spec/blather/stanza/iq/ping_spec.rb +45 -0
  109. data/spec/blather/stanza/iq/query_spec.rb +64 -0
  110. data/spec/blather/stanza/iq/roster_spec.rb +139 -0
  111. data/spec/blather/stanza/iq/s5b_spec.rb +57 -0
  112. data/spec/blather/stanza/iq/si_spec.rb +98 -0
  113. data/spec/blather/stanza/iq/vcard_spec.rb +93 -0
  114. data/spec/blather/stanza/iq_spec.rb +61 -0
  115. data/spec/blather/stanza/message/muc_user_spec.rb +152 -0
  116. data/spec/blather/stanza/message_spec.rb +282 -0
  117. data/spec/blather/stanza/presence/c_spec.rb +56 -0
  118. data/spec/blather/stanza/presence/muc_spec.rb +37 -0
  119. data/spec/blather/stanza/presence/muc_user_spec.rb +83 -0
  120. data/spec/blather/stanza/presence/status_spec.rb +144 -0
  121. data/spec/blather/stanza/presence/subscription_spec.rb +102 -0
  122. data/spec/blather/stanza/presence_spec.rb +125 -0
  123. data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
  124. data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
  125. data/spec/blather/stanza/pubsub/event_spec.rb +98 -0
  126. data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
  127. data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
  128. data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
  129. data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
  130. data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
  131. data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
  132. data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +74 -0
  133. data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
  134. data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
  135. data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
  136. data/spec/blather/stanza/pubsub_spec.rb +68 -0
  137. data/spec/blather/stanza/x_spec.rb +231 -0
  138. data/spec/blather/stanza_spec.rb +134 -0
  139. data/spec/blather/stream/client_spec.rb +1090 -0
  140. data/spec/blather/stream/component_spec.rb +108 -0
  141. data/spec/blather/stream/parser_spec.rb +152 -0
  142. data/spec/blather/stream/ssl_spec.rb +32 -0
  143. data/spec/blather/xmpp_node_spec.rb +47 -0
  144. data/spec/blather_spec.rb +34 -0
  145. data/spec/fixtures/pubsub.rb +311 -0
  146. data/spec/spec_helper.rb +17 -0
  147. data/yard/templates/default/class/html/handlers.erb +18 -0
  148. data/yard/templates/default/class/setup.rb +10 -0
  149. data/yard/templates/default/class/text/handlers.erb +1 -0
  150. metadata +459 -0
@@ -0,0 +1,68 @@
1
+ module Blather
2
+ class Stanza
3
+ class PubSub
4
+
5
+ # # PubSub Subscribe Stanza
6
+ #
7
+ # [XEP-0060 Section 6.1 - Subscribe to a Node](http://xmpp.org/extensions/xep-0060.html#subscriber-subscribe)
8
+ #
9
+ # @handler :pubsub_subscribe
10
+ class Subscribe < PubSub
11
+ register :pubsub_subscribe, :subscribe, self.registered_ns
12
+
13
+ # Create a new subscription node
14
+ #
15
+ # @param [Blather::Stanza::Iq::VALID_TYPES] type the IQ stanza type
16
+ # @param [String] host the host name to send the request to
17
+ # @param [String] node the node to subscribe to
18
+ # @param [Blather::JID, #to_s] jid see {#jid=}
19
+ def self.new(type = :set, host = nil, node = nil, jid = nil)
20
+ new_node = super(type, host)
21
+ new_node.node = node
22
+ new_node.jid = jid
23
+ new_node
24
+ end
25
+
26
+ # Get the JID of the entity to subscribe
27
+ #
28
+ # @return [Blather::JID]
29
+ def jid
30
+ JID.new(subscribe[:jid])
31
+ end
32
+
33
+ # Set the JID of the entity to subscribe
34
+ #
35
+ # @param [Blather::JID, #to_s] jid
36
+ def jid=(jid)
37
+ subscribe[:jid] = jid
38
+ end
39
+
40
+ # Get the name of the node to subscribe to
41
+ #
42
+ # @return [String]
43
+ def node
44
+ subscribe[:node]
45
+ end
46
+
47
+ # Set the name of the node to subscribe to
48
+ #
49
+ # @param [String] node
50
+ def node=(node)
51
+ subscribe[:node] = node
52
+ end
53
+
54
+ # Get or create the actual subscribe node on the stanza
55
+ #
56
+ # @return [Blather::XMPPNode]
57
+ def subscribe
58
+ unless subscribe = pubsub.find_first('ns:subscribe', :ns => self.class.registered_ns)
59
+ self.pubsub << (subscribe = XMPPNode.new('subscribe', self.document))
60
+ subscribe.namespace = self.pubsub.namespace
61
+ end
62
+ subscribe
63
+ end
64
+ end # Subscribe
65
+
66
+ end # PubSub
67
+ end # Stanza
68
+ end # Blather
@@ -0,0 +1,135 @@
1
+ module Blather
2
+ class Stanza
3
+ class PubSub
4
+
5
+ # # PubSub Subscription Stanza
6
+ #
7
+ # [XEP-0060 Section 8.8 Manage Subscriptions](http://xmpp.org/extensions/xep-0060.html#owner-subscriptions)
8
+ #
9
+ # @handler :pubsub_subscription
10
+ class Subscription < PubSub
11
+ # @private
12
+ VALID_TYPES = [:none, :pending, :subscribed, :unconfigured]
13
+
14
+ register :pubsub_subscription, :subscription, self.registered_ns
15
+
16
+ # Create a new subscription request node
17
+ #
18
+ # @param [Blather::Stanza::Iq::VALID_TYPES] type the IQ type
19
+ # @param [String] host the host to send the request to
20
+ # @param [String] node the node to look for requests on
21
+ # @param [Blather::JID, #to_s] jid the JID of the subscriber
22
+ # @param [String] subid the subscription ID
23
+ # @param [VALID_TYPES] subscription the subscription type
24
+ def self.new(type = :result, host = nil, node = nil, jid = nil, subid = nil, subscription = nil)
25
+ new_node = super(type, host)
26
+ new_node.node = node
27
+ new_node.jid = jid
28
+ new_node.subid = subid
29
+ new_node.subscription = subscription
30
+ new_node
31
+ end
32
+
33
+ # Check if the type is none
34
+ #
35
+ # @return [Boolean]
36
+ def none?
37
+ self.subscription == :none
38
+ end
39
+
40
+ # Check if the type is pending
41
+ #
42
+ # @return [Boolean]
43
+ def pending?
44
+ self.subscription == :pending
45
+ end
46
+
47
+ # Check if the type is subscribed
48
+ #
49
+ # @return [Boolean]
50
+ def subscribed?
51
+ self.subscription == :subscribed
52
+ end
53
+
54
+ # Check if the type is unconfigured
55
+ #
56
+ # @return [Boolean]
57
+ def unconfigured?
58
+ self.subscription == :unconfigured
59
+ end
60
+
61
+ # Get the JID of the subscriber
62
+ #
63
+ # @return [Blather::JID]
64
+ def jid
65
+ JID.new(subscription_node[:jid])
66
+ end
67
+
68
+ # Set the JID of the subscriber
69
+ #
70
+ # @param [Blather::JID, #to_s] jid
71
+ def jid=(jid)
72
+ subscription_node[:jid] = jid
73
+ end
74
+
75
+ # Get the name of the subscription node
76
+ #
77
+ # @return [String]
78
+ def node
79
+ subscription_node[:node]
80
+ end
81
+
82
+ # Set the name of the subscription node
83
+ #
84
+ # @param [String] node
85
+ def node=(node)
86
+ subscription_node[:node] = node
87
+ end
88
+
89
+ # Get the ID of the subscription
90
+ #
91
+ # @return [String]
92
+ def subid
93
+ subscription_node[:subid]
94
+ end
95
+
96
+ # Set the ID of the subscription
97
+ #
98
+ # @param [String] subid
99
+ def subid=(subid)
100
+ subscription_node[:subid] = subid
101
+ end
102
+
103
+ # Get the subscription type
104
+ #
105
+ # @return [VALID_TYPES, nil]
106
+ def subscription
107
+ s = subscription_node[:subscription]
108
+ s.to_sym if s
109
+ end
110
+
111
+ # Set the subscription type
112
+ #
113
+ # @param [VALID_TYPES, nil] subscription
114
+ def subscription=(subscription)
115
+ if subscription && !VALID_TYPES.include?(subscription.to_sym)
116
+ raise ArgumentError, "Invalid Type (#{type}), use: #{VALID_TYPES*' '}"
117
+ end
118
+ subscription_node[:subscription] = subscription
119
+ end
120
+
121
+ # Get or create the actual subscription node
122
+ #
123
+ # @return [Blather::XMPPNode]
124
+ def subscription_node
125
+ unless subscription = pubsub.find_first('ns:subscription', :ns => self.class.registered_ns)
126
+ self.pubsub << (subscription = XMPPNode.new('subscription', self.document))
127
+ subscription.namespace = self.pubsub.namespace
128
+ end
129
+ subscription
130
+ end
131
+ end # Subscribe
132
+
133
+ end # PubSub
134
+ end # Stanza
135
+ end # Blather
@@ -0,0 +1,83 @@
1
+ module Blather
2
+ class Stanza
3
+ class PubSub
4
+
5
+ # # PubSub Subscriptions Stanza
6
+ #
7
+ # [XEP-0060 Section 5.6 Retrieve Subscriptions](http://xmpp.org/extensions/xep-0060.html#entity-subscriptions)
8
+ #
9
+ # @handler :pubsub_subscriptions
10
+ class Subscriptions < PubSub
11
+ register :pubsub_subscriptions, :subscriptions, self.registered_ns
12
+
13
+ include Enumerable
14
+ alias_method :find, :xpath
15
+
16
+ # Overrides the parent to ensure a subscriptions node is created
17
+ # @private
18
+ def self.new(type = nil, host = nil)
19
+ new_node = super type
20
+ new_node.to = host
21
+ new_node.subscriptions
22
+ new_node
23
+ end
24
+
25
+ # Overrides the parent to ensure the subscriptions node is destroyed
26
+ # @private
27
+ def inherit(node)
28
+ subscriptions.remove
29
+ super
30
+ end
31
+
32
+ # Get or create the actual subscriptions node
33
+ #
34
+ # @return [Blather::XMPPNode]
35
+ def subscriptions
36
+ aff = pubsub.find_first('subscriptions', self.class.registered_ns)
37
+ unless aff
38
+ (self.pubsub << (aff = XMPPNode.new('subscriptions', self.document)))
39
+ end
40
+ aff
41
+ end
42
+
43
+ # Iterate over the list of subscriptions
44
+ #
45
+ # @yieldparam [Hash] subscription
46
+ # @see {#list}
47
+ def each(&block)
48
+ list.each &block
49
+ end
50
+
51
+ # Get the size of the subscriptions list
52
+ #
53
+ # @return [Fixnum]
54
+ def size
55
+ list.size
56
+ end
57
+
58
+ # Get a hash of subscriptions
59
+ #
60
+ # @example
61
+ # { :subscribed => [{:node => 'node1', :jid => 'francisco@denmark.lit', :subid => 'fd8237yr872h3f289j2'}, {:node => 'node2', :jid => 'francisco@denmark.lit', :subid => 'h8394hf8923ju'}],
62
+ # :unconfigured => [{:node => 'node3', :jid => 'francisco@denmark.lit'}],
63
+ # :pending => [{:node => 'node4', :jid => 'francisco@denmark.lit'}],
64
+ # :none => [{:node => 'node5', :jid => 'francisco@denmark.lit'}] }
65
+ #
66
+ # @return [Hash]
67
+ def list
68
+ subscriptions.find('//ns:subscription', :ns => self.class.registered_ns).inject({}) do |hash, item|
69
+ hash[item[:subscription].to_sym] ||= []
70
+ sub = {
71
+ :node => item[:node],
72
+ :jid => item[:jid]
73
+ }
74
+ sub[:subid] = item[:subid] if item[:subid]
75
+ hash[item[:subscription].to_sym] << sub
76
+ hash
77
+ end
78
+ end
79
+ end # Subscriptions
80
+
81
+ end # PubSub
82
+ end # Stanza
83
+ end # Blather
@@ -0,0 +1,84 @@
1
+ module Blather
2
+ class Stanza
3
+ class PubSub
4
+
5
+ # # PubSub Unsubscribe Stanza
6
+ #
7
+ # [XEP-0060 Section 6.2 - Unsubscribe from a Node](http://xmpp.org/extensions/xep-0060.html#subscriber-unsubscribe)
8
+ #
9
+ # @handler :pubsub_unsubscribe
10
+ class Unsubscribe < PubSub
11
+ register :pubsub_unsubscribe, :unsubscribe, self.registered_ns
12
+
13
+ # Create a new unsubscribe node
14
+ #
15
+ # @param [Blather::Stanza::Iq::VALID_TYPES] type the IQ stanza type
16
+ # @param [String] host the host to send the request to
17
+ # @param [String] node the node to unsubscribe from
18
+ # @param [Blather::JID, #to_s] jid the JID of the unsubscription
19
+ # @param [String] subid the subscription ID of the unsubscription
20
+ def self.new(type = :set, host = nil, node = nil, jid = nil, subid = nil)
21
+ new_node = super(type, host)
22
+ new_node.node = node
23
+ new_node.jid = jid
24
+ new_node.subid = subid
25
+ new_node
26
+ end
27
+
28
+ # Get the JID of the unsubscription
29
+ #
30
+ # @return [Blather::JID]
31
+ def jid
32
+ JID.new(unsubscribe[:jid])
33
+ end
34
+
35
+ # Set the JID of the unsubscription
36
+ #
37
+ # @param [Blather::JID, #to_s] jid
38
+ def jid=(jid)
39
+ unsubscribe[:jid] = jid
40
+ end
41
+
42
+ # Get the name of the node to unsubscribe from
43
+ #
44
+ # @return [String]
45
+ def node
46
+ unsubscribe[:node]
47
+ end
48
+
49
+ # Set the name of the node to unsubscribe from
50
+ #
51
+ # @param [String] node
52
+ def node=(node)
53
+ unsubscribe[:node] = node
54
+ end
55
+
56
+ # Get the subscription ID to unsubscribe from
57
+ #
58
+ # @return [String]
59
+ def subid
60
+ unsubscribe[:subid]
61
+ end
62
+
63
+ # Set the subscription ID to unsubscribe from
64
+ #
65
+ # @param [String] node
66
+ def subid=(subid)
67
+ unsubscribe[:subid] = subid
68
+ end
69
+
70
+ # Get or create the actual unsubscribe node
71
+ #
72
+ # @return [Blather::XMPPNode]
73
+ def unsubscribe
74
+ unless unsubscribe = pubsub.find_first('ns:unsubscribe', :ns => self.class.registered_ns)
75
+ self.pubsub << (unsubscribe = XMPPNode.new('unsubscribe', self.document))
76
+ unsubscribe.namespace = self.pubsub.namespace
77
+ end
78
+ unsubscribe
79
+ end
80
+ end # Unsubscribe
81
+
82
+ end # PubSub
83
+ end # Stanza
84
+ end # Blather
@@ -0,0 +1,51 @@
1
+ module Blather
2
+ class Stanza
3
+
4
+ # # PubSubOwner Base Class
5
+ #
6
+ # [XEP-0060 - Publish-Subscribe](http://xmpp.org/extensions/xep-0060.html)
7
+ #
8
+ # @handler :pubsub_owner
9
+ class PubSubOwner < Iq
10
+ register :pubsub_owner, :pubsub, 'http://jabber.org/protocol/pubsub#owner'
11
+
12
+ # Creates the proper class from the stana's child
13
+ # @private
14
+ def self.import(node)
15
+ klass = nil
16
+ if pubsub = node.document.find_first('//ns:pubsub', :ns => self.registered_ns)
17
+ pubsub.children.each { |e| break if klass = class_from_registration(e.element_name, (e.namespace.href if e.namespace)) }
18
+ end
19
+ (klass || self).new(node[:type]).inherit(node)
20
+ end
21
+
22
+ # Overrides the parent to ensure a pubsub node is created
23
+ # @private
24
+ def self.new(type = nil, host = nil)
25
+ new_node = super type
26
+ new_node.to = host
27
+ new_node.pubsub
28
+ new_node
29
+ end
30
+
31
+ # Overrides the parent to ensure the pubsub node is destroyed
32
+ # @private
33
+ def inherit(node)
34
+ remove_children :pubsub
35
+ super
36
+ end
37
+
38
+ # Get or create the pubsub node on the stanza
39
+ #
40
+ # @return [Blather::XMPPNode]
41
+ def pubsub
42
+ unless p = find_first('ns:pubsub', :ns => self.class.registered_ns)
43
+ self << (p = XMPPNode.new('pubsub', self.document))
44
+ p.namespace = self.class.registered_ns
45
+ end
46
+ p
47
+ end
48
+ end # PubSubOwner
49
+
50
+ end # Stanza
51
+ end # Blather
@@ -0,0 +1,52 @@
1
+ module Blather
2
+ class Stanza
3
+ class PubSubOwner
4
+
5
+ # # PubSubOwner Delete Stanza
6
+ #
7
+ # [XEP-0060 Section 8.4 Delete a Node](http://xmpp.org/extensions/xep-0060.html#owner-delete)
8
+ #
9
+ # @handler :pubsub_delete
10
+ class Delete < PubSubOwner
11
+ register :pubsub_delete, :delete, self.registered_ns
12
+
13
+ # Create a new delete stanza
14
+ #
15
+ # @param [Blather::Stanza::Iq::VALID_TYPES] type the IQ stanza type
16
+ # @param [String] host the host to send the request to
17
+ # @param [String] node the name of the node to delete
18
+ def self.new(type = :set, host = nil, node = nil)
19
+ new_node = super(type, host)
20
+ new_node.node = node
21
+ new_node
22
+ end
23
+
24
+ # Get the name of the node to delete
25
+ #
26
+ # @return [String]
27
+ def node
28
+ delete_node[:node]
29
+ end
30
+
31
+ # Set the name of the node to delete
32
+ #
33
+ # @param [String] node
34
+ def node=(node)
35
+ delete_node[:node] = node
36
+ end
37
+
38
+ # Get or create the actual delete node on the stanza
39
+ #
40
+ # @return [Blather::XMPPNode]
41
+ def delete_node
42
+ unless delete_node = pubsub.find_first('ns:delete', :ns => self.class.registered_ns)
43
+ self.pubsub << (delete_node = XMPPNode.new('delete', self.document))
44
+ delete_node.namespace = self.pubsub.namespace
45
+ end
46
+ delete_node
47
+ end
48
+ end # Retract
49
+
50
+ end # PubSub
51
+ end # Stanza
52
+ end # Blather