class Blather::Stanza::PubSub
# Pubsub Stanza
[XEP-0060 - Publish-Subscribe](xmpp.org/extensions/xep-0060.html)
The base class for all PubSub
nodes. This provides helper methods common to all PubSub
nodes.
@handler :pubsub_node
Public Class Methods
import(node)
click to toggle source
@private
# File lib/blather/stanza/pubsub.rb, line 16 def self.import(node) klass = nil if pubsub = node.document.find_first('//ns:pubsub', :ns => self.registered_ns) pubsub.children.detect do |e| ns = e.namespace ? e.namespace.href : nil klass = class_from_registration(e.element_name, ns) end end (klass || self).new(node[:type]).inherit(node) end
new(type = nil, host = nil)
click to toggle source
Overwrites the parent constructor to ensure a pubsub node is present. Also allows the addition of a host attribute
@param [<Blather::Stanza::Iq::VALID_TYPES>] type the IQ type @param [String, nil] host the host the node should be sent to
Calls superclass method
Blather::Stanza::Iq::new
# File lib/blather/stanza/pubsub.rb, line 32 def self.new(type = nil, host = nil) new_node = super type new_node.to = host new_node.pubsub new_node end
Public Instance Methods
inherit(node)
click to toggle source
Overrides the parent to ensure the current pubsub node is destroyed before inheritting the new content
@private
Calls superclass method
# File lib/blather/stanza/pubsub.rb, line 43 def inherit(node) remove_children :pubsub super end
pubsub()
click to toggle source
Get or create the pubsub node on the stanza
@return [Blather::XMPPNode]
# File lib/blather/stanza/pubsub.rb, line 51 def pubsub p = find_first('ns:pubsub', :ns => self.class.registered_ns) || find_first('pubsub', :ns => self.class.registered_ns) unless p self << (p = XMPPNode.new('pubsub', self.document)) p.namespace = self.class.registered_ns end p end