Class: Blather::Stanza::PubSub::Subscriptions

Inherits:
Blather::Stanza::PubSub show all
Includes:
Enumerable
Defined in:
lib/blather/stanza/pubsub/subscriptions.rb

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 Blather::Stanza::PubSub

import, #pubsub

Methods inherited from Iq

import, #type=

Methods inherited from Blather::Stanza

#as_error, attribute_helpers_for, #from, handler_list, next_id, register, #reply, #reply!, #to

Methods inherited from XMPPNode

attribute_accessor, attribute_reader, attribute_writer, class_from_registration, content_attr_accessor, content_attr_reader, content_attr_writer, #content_from, import, #inherit_attrs, #namespace=, #namespace_href, #nokogiri_namespace=, register, #remove_child, #remove_children, #set_content_for, #to_stanza

Methods inherited from Nokogiri::XML::Node

#[]=, #attr_set, #find_first, #nokogiri_xpath, #xpath

Class Method Details

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

Ensure the namespace is set to the query node



13
14
15
16
17
18
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 13

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

Instance Method Details

#each(&block) ⇒ Object



33
34
35
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 33

def each(&block)
  list.each &block
end

#inherit(node) ⇒ Object

Kill the pubsub node before running inherit



22
23
24
25
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 22

def inherit(node)
  subscriptions.remove
  super
end

#listObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 41

def list
  subscriptions.find('//ns:subscription', :ns => self.class.registered_ns).inject({}) do |hash, item|
    hash[item[:subscription].to_sym] ||= []
    hash[item[:subscription].to_sym] << {
      :node => item[:node],
      :jid => item[:jid]
    }
    hash
  end
end

#sizeObject



37
38
39
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 37

def size
  list.size
end

#subscriptionsObject



27
28
29
30
31
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 27

def subscriptions
  aff = pubsub.find_first('subscriptions', self.class.registered_ns)
  (self.pubsub << (aff = XMPPNode.new('subscriptions', self.document))) unless aff
  aff
end