Class: Blather::Stanza::PubSubOwner

Inherits:
Iq show all
Defined in:
lib/blather/stanza/pubsub_owner.rb,
lib/blather/stanza/pubsub_owner/purge.rb,
lib/blather/stanza/pubsub_owner/delete.rb

Overview

# PubSubOwner Base Class

[XEP-0060 - Publish-Subscribe](xmpp.org/extensions/xep-0060.html)

Direct Known Subclasses

Delete, Purge

Defined Under Namespace

Classes: Delete, Purge

Constant Summary

Constants inherited from Iq

Iq::VALID_TYPES

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Iq

#error?, #get?, #reply!, #result?, #set?, #type=

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

.import(node) ⇒ Object

Creates the proper class from the stana’s child



14
15
16
17
18
19
20
# File 'lib/blather/stanza/pubsub_owner.rb', line 14

def self.import(node)
  klass = nil
  if pubsub = node.document.find_first('//ns:pubsub', :ns => self.registered_ns)
    pubsub.children.each { |e| break if klass = class_from_registration(e.element_name, (e.namespace.href if e.namespace)) }
  end
  (klass || self).new(node[:type]).inherit(node)
end

.new(type = nil, host = nil) ⇒ Object

Overrides the parent to ensure a pubsub node is created



24
25
26
27
28
29
# File 'lib/blather/stanza/pubsub_owner.rb', line 24

def self.new(type = nil, host = nil)
  new_node = super type
  new_node.to = host
  new_node.pubsub
  new_node
end

Instance Method Details

#inherit(node) ⇒ Object

Overrides the parent to ensure the pubsub node is destroyed



33
34
35
36
# File 'lib/blather/stanza/pubsub_owner.rb', line 33

def inherit(node)
  remove_children :pubsub
  super
end

#pubsubBlather::XMPPNode

Get or create the pubsub node on the stanza

Returns:



41
42
43
44
45
46
47
# File 'lib/blather/stanza/pubsub_owner.rb', line 41

def pubsub
  unless p = find_first('ns:pubsub', :ns => self.class.registered_ns)
    self << (p = XMPPNode.new('pubsub', self.document))
    p.namespace = self.class.registered_ns
  end
  p
end