Class: Blather::Stanza::PubSub::Event
- Inherits:
-
Message
- Object
- Niceogiri::XML::Node
- XMPPNode
- Blather::Stanza
- Message
- Blather::Stanza::PubSub::Event
- Defined in:
- lib/blather/stanza/pubsub/event.rb
Overview
# PubSub Event Stanza
[XEP-0060](xmpp.org/extensions/xep-0060.html)
The PubSub Event stanza is used in many places. Please see the XEP for more information.
Constant Summary collapse
- SHIM_NS =
'http://jabber.org/protocol/shim'.freeze
Constants inherited from Message
Message::CHAT_STATE_NS, Message::HTML_BODY_NS, Message::HTML_NS, Message::VALID_CHAT_STATES, Message::VALID_TYPES
Constants inherited from XMPPNode
Instance Attribute Summary
Attributes inherited from Blather::Stanza
Class Method Summary collapse
-
.new(type = nil) ⇒ Object
Ensures the event_node is created.
Instance Method Summary collapse
-
#event_node ⇒ Blather::XMPPNode
Get or create the actual event node.
-
#inherit(node) ⇒ Object
Kill the event_node node before running inherit.
-
#items ⇒ Array<Blather::Stanza::PubSub::PubSubItem>
Get the list of items attached to this event.
-
#items? ⇒ Boolean
Check if this stanza has items.
-
#items_node ⇒ Blather::XMPPNode
Get or create the actual items node.
-
#node ⇒ String?
Get the name of the node.
-
#purge? ⇒ XML::Node?
Check if this is a purge stanza.
-
#purge_node ⇒ Blather::XMPPNode
Get the actual purge node.
-
#retractions ⇒ Array<String>
Get a list of retractions.
-
#retractions? ⇒ Boolean
Check if this is a retractions stanza.
-
#subscription? ⇒ XML::Node?
Check if this is a subscription stanza.
-
#subscription_ids ⇒ Array<String>
Get the subscription IDs associated with this event.
-
#subscription_node ⇒ Blather::XMPPNode
(also: #subscription)
Get the actual subscription node.
Methods inherited from Message
#body, #body=, #chat?, #chat_state, #chat_state=, #delay, #delayed?, #error?, #form, #groupchat?, #headline?, import, #normal?, #parent_thread, #subject, #subject=, #thread, #thread=, #type=, #xhtml, #xhtml=, #xhtml_node
Methods inherited from Blather::Stanza
#as_error, #error?, #from, #from=, handler_list, #id, #id=, #initialize, next_id, register, #reply, #reply!, #to, #to=, #type, #type=
Methods inherited from XMPPNode
class_from_registration, #decorate, decorator_modules, import, parse, register, #to_stanza
Constructor Details
This class inherits a constructor from Blather::Stanza
Class Method Details
.new(type = nil) ⇒ Object
Ensures the event_node is created
21 22 23 24 25 |
# File 'lib/blather/stanza/pubsub/event.rb', line 21 def self.new(type = nil) node = super node.event_node node end |
Instance Method Details
#event_node ⇒ Blather::XMPPNode
Get or create the actual event node
83 84 85 86 87 88 89 90 91 |
# File 'lib/blather/stanza/pubsub/event.rb', line 83 def event_node node = find_first('//ns:event', :ns => self.class.registered_ns) node = find_first('//event', self.class.registered_ns) unless node unless node (self << (node = XMPPNode.new('event', self.document))) node.namespace = self.class.registered_ns end node end |
#inherit(node) ⇒ Object
Kill the event_node node before running inherit
29 30 31 32 |
# File 'lib/blather/stanza/pubsub/event.rb', line 29 def inherit(node) event_node.remove super end |
#items ⇒ Array<Blather::Stanza::PubSub::PubSubItem>
Get the list of items attached to this event
60 61 62 63 64 |
# File 'lib/blather/stanza/pubsub/event.rb', line 60 def items items_node.find('//ns:item', :ns => self.class.registered_ns).map do |i| PubSubItem.new(nil,nil,self.document).inherit i end end |
#items? ⇒ Boolean
Check if this stanza has items
69 70 71 |
# File 'lib/blather/stanza/pubsub/event.rb', line 69 def items? !items.empty? end |
#items_node ⇒ Blather::XMPPNode
Get or create the actual items node
96 97 98 99 100 101 102 103 |
# File 'lib/blather/stanza/pubsub/event.rb', line 96 def items_node node = find_first('ns:event/ns:items', :ns => self.class.registered_ns) unless node (self.event_node << (node = XMPPNode.new('items', self.document))) node.namespace = event_node.namespace end node end |
#node ⇒ String?
Get the name of the node
37 38 39 |
# File 'lib/blather/stanza/pubsub/event.rb', line 37 def node !purge? ? items_node[:node] : purge_node[:node] end |
#purge? ⇒ XML::Node?
Check if this is a purge stanza
76 77 78 |
# File 'lib/blather/stanza/pubsub/event.rb', line 76 def purge? purge_node end |
#purge_node ⇒ Blather::XMPPNode
Get the actual purge node
108 109 110 |
# File 'lib/blather/stanza/pubsub/event.rb', line 108 def purge_node event_node.find_first('//ns:purge', :ns => self.class.registered_ns) end |
#retractions ⇒ Array<String>
Get a list of retractions
44 45 46 47 48 |
# File 'lib/blather/stanza/pubsub/event.rb', line 44 def retractions items_node.find('//ns:retract', :ns => self.class.registered_ns).map do |i| i[:id] end end |
#retractions? ⇒ Boolean
Check if this is a retractions stanza
53 54 55 |
# File 'lib/blather/stanza/pubsub/event.rb', line 53 def retractions? !retractions.empty? end |
#subscription? ⇒ XML::Node?
Check if this is a subscription stanza
124 125 126 |
# File 'lib/blather/stanza/pubsub/event.rb', line 124 def subscription? subscription_node end |
#subscription_ids ⇒ Array<String>
Get the subscription IDs associated with this event
115 116 117 118 119 |
# File 'lib/blather/stanza/pubsub/event.rb', line 115 def subscription_ids find('//ns:header[@name="SubID"]', :ns => SHIM_NS).map do |n| n.content end end |
#subscription_node ⇒ Blather::XMPPNode Also known as: subscription
Get the actual subscription node
131 132 133 |
# File 'lib/blather/stanza/pubsub/event.rb', line 131 def subscription_node event_node.find_first('//ns:subscription', :ns => self.class.registered_ns) end |