Class: Blather::Stanza::PubSub::Event
- Inherits:
-
Message
- Object
- Nokogiri::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
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_ids ⇒ Array<String>
Get the subscription IDs associated with this event.
Methods inherited from Message
#body, #body=, #chat?, #chat_state, #chat_state=, #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=, next_id, register, #reply, #reply!, #to, #to=, #type, #type=
Methods inherited from XMPPNode
class_from_registration, #content_from, import, #inherit_attrs, #inspect, #namespace=, #namespace_href, #nokogiri_namespace=, #read_attr, #read_content, register, #remove_child, #remove_children, #set_content_for, #to_stanza, #write_attr
Methods inherited from Nokogiri::XML::Node
#[]=, #attr_set, #find_first, #nokogiri_xpath, #xpath
Class Method Details
.new(type = nil) ⇒ Object
Ensures the event_node is created
20 21 22 23 24 |
# File 'lib/blather/stanza/pubsub/event.rb', line 20 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
82 83 84 85 86 87 88 89 90 |
# File 'lib/blather/stanza/pubsub/event.rb', line 82 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
28 29 30 31 |
# File 'lib/blather/stanza/pubsub/event.rb', line 28 def inherit(node) event_node.remove super end |
#items ⇒ Array<Blather::Stanza::PubSub::PubSubItem>
Get the list of items attached to this event
59 60 61 62 63 |
# File 'lib/blather/stanza/pubsub/event.rb', line 59 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
68 69 70 |
# File 'lib/blather/stanza/pubsub/event.rb', line 68 def items? !items.empty? end |
#items_node ⇒ Blather::XMPPNode
Get or create the actual items node
95 96 97 98 99 100 101 102 |
# File 'lib/blather/stanza/pubsub/event.rb', line 95 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
36 37 38 |
# File 'lib/blather/stanza/pubsub/event.rb', line 36 def node !purge? ? items_node[:node] : purge_node[:node] end |
#purge? ⇒ XML::Node?
Check if this is a purge stanza
75 76 77 |
# File 'lib/blather/stanza/pubsub/event.rb', line 75 def purge? purge_node end |
#purge_node ⇒ Blather::XMPPNode
Get the actual purge node
107 108 109 |
# File 'lib/blather/stanza/pubsub/event.rb', line 107 def purge_node event_node.find_first('//ns:purge', :ns => self.class.registered_ns) end |
#retractions ⇒ Array<String>
Get a list of retractions
43 44 45 46 47 |
# File 'lib/blather/stanza/pubsub/event.rb', line 43 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
52 53 54 |
# File 'lib/blather/stanza/pubsub/event.rb', line 52 def retractions? !retractions.empty? end |
#subscription_ids ⇒ Array<String>
Get the subscription IDs associated with this event
114 115 116 117 118 |
# File 'lib/blather/stanza/pubsub/event.rb', line 114 def subscription_ids find('//ns:header[@name="SubID"]', :ns => SHIM_NS).map do |n| n.content end end |