class Blather::Stanza::PubSub::Event
[XEP-0060](xmpp.org/extensions/xep-0060.html)
The PubSub
Event
stanza is used in many places. Please see the XEP for more information.
@handler :pubsub_event
Constants
- SHIM_NS
@private
Public Class Methods
Ensures the event_node
is created @private
Blather::Stanza::Message::new
# File lib/blather/stanza/pubsub/event.rb, line 21 def self.new(type = nil) node = super node.event_node node end
Public Instance Methods
Get or create the actual event node
@return [Blather::XMPPNode]
# 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
Kill the event_node
node before running inherit @private
Blather::Stanza::Message#inherit
# File lib/blather/stanza/pubsub/event.rb, line 29 def inherit(node) event_node.remove super end
Get the list of items attached to this event
@return [Array<Blather::Stanza::PubSub::PubSubItem>]
# 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
Check if this stanza has items
@return [Boolean]
# File lib/blather/stanza/pubsub/event.rb, line 69 def items? !items.empty? end
Get or create the actual items node
@return [Blather::XMPPNode]
# 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
Get the name of the node
@return [String, nil]
# File lib/blather/stanza/pubsub/event.rb, line 37 def node !purge? ? items_node[:node] : purge_node[:node] end
Check if this is a purge stanza
@return [XML::Node, nil]
# File lib/blather/stanza/pubsub/event.rb, line 76 def purge? purge_node end
Get the actual purge node
@return [Blather::XMPPNode]
# File lib/blather/stanza/pubsub/event.rb, line 108 def purge_node event_node.find_first('//ns:purge', :ns => self.class.registered_ns) end
Get a list of retractions
@return [Array<String>]
# 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
Check if this is a retractions stanza
@return [Boolean]
# File lib/blather/stanza/pubsub/event.rb, line 53 def retractions? !retractions.empty? end
Check if this is a subscription stanza
@return [XML::Node, nil]
# File lib/blather/stanza/pubsub/event.rb, line 124 def subscription? subscription_node end
Get the subscription IDs associated with this event
@return [Array<String>]
# 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
Get the actual subscription node
@return [Blather::XMPPNode]
# File lib/blather/stanza/pubsub/event.rb, line 131 def subscription_node event_node.find_first('//ns:subscription', :ns => self.class.registered_ns) end