class Blather::Stanza::PubSub::Event

# 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.

@handler :pubsub_event

Constants

SHIM_NS

@private

Public Class Methods

new(type = nil) click to toggle source

Ensures the event_node is created @private

Calls superclass method 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

event_node() click to toggle source

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
inherit(node) click to toggle source

Kill the event_node node before running inherit @private

Calls superclass method Blather::Stanza::Message#inherit
# File lib/blather/stanza/pubsub/event.rb, line 29
def inherit(node)
  event_node.remove
  super
end
items() click to toggle source

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
items?() click to toggle source

Check if this stanza has items

@return [Boolean]

# File lib/blather/stanza/pubsub/event.rb, line 69
def items?
  !items.empty?
end
items_node() click to toggle source

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
node() click to toggle source

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
purge?() click to toggle source

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
purge_node() click to toggle source

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
retractions() click to toggle source

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
retractions?() click to toggle source

Check if this is a retractions stanza

@return [Boolean]

# File lib/blather/stanza/pubsub/event.rb, line 53
def retractions?
  !retractions.empty?
end
subscription()
Alias for: subscription_node
subscription?() click to toggle source

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
subscription_ids() click to toggle source

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
subscription_node() click to toggle source

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
Also aliased as: subscription