Class: Blather::Stanza::PubSub

Inherits:
Iq show all
Defined in:
lib/blather/stanza/pubsub.rb,
lib/blather/stanza/pubsub/event.rb,
lib/blather/stanza/pubsub/items.rb,
lib/blather/stanza/pubsub/create.rb,
lib/blather/stanza/pubsub/publish.rb,
lib/blather/stanza/pubsub/retract.rb,
lib/blather/stanza/pubsub/subscribe.rb,
lib/blather/stanza/pubsub/unsubscribe.rb,
lib/blather/stanza/pubsub/affiliations.rb,
lib/blather/stanza/pubsub/subscription.rb,
lib/blather/stanza/pubsub/subscriptions.rb

Overview

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

Defined Under Namespace

Classes: Affiliations, Create, Event, Items, Publish, Retract, Subscribe, Subscription, Subscriptions, Unsubscribe

Constant Summary

Constants inherited from Iq

Iq::VALID_TYPES

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Instance Attribute Summary

Attributes inherited from Blather::Stanza

#handler_hierarchy

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=, #initialize, next_id, register, #reply, #reply!, #to, #to=, #type, #type=

Methods inherited from XMPPNode

class_from_registration, #decorate, decorator_modules, parse, register, #to_stanza

Constructor Details

This class inherits a constructor from Blather::Stanza

Class Method Details

.import(node) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# 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) ⇒ Object

Overwrites the parent constructor to ensure a pubsub node is present. Also allows the addition of a host attribute

Parameters:



32
33
34
35
36
37
# 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

Instance Method Details

#inherit(node) ⇒ Object

Overrides the parent to ensure the current pubsub node is destroyed before inheritting the new content



43
44
45
46
# File 'lib/blather/stanza/pubsub.rb', line 43

def inherit(node)
  remove_children :pubsub
  super
end

#pubsubBlather::XMPPNode

Get or create the pubsub node on the stanza

Returns:



51
52
53
54
55
56
57
58
59
60
# 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