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

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

Overview

# PubSub Subscriptions Stanza

[XEP-0060 Section 5.6 Retrieve Subscriptions](xmpp.org/extensions/xep-0060.html#entity-subscriptions)

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

#error?, #get?, import, #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, import, #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

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

Overrides the parent to ensure a subscriptions node is created



18
19
20
21
22
23
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 18

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 {|subscription| ... } ⇒ Object

Iterate over the list of subscriptions

Yield Parameters:

  • subscription (Hash)

See Also:

  • Blather::Stanza::PubSub::Subscriptions.{{#list}


47
48
49
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 47

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

#inherit(node) ⇒ Object

Overrides the parent to ensure the subscriptions node is destroyed



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

def inherit(node)
  subscriptions.remove
  super
end

#listHash

Get a hash of subscriptions

Examples:

{ :subscribed => [{:node => 'node1', :jid => '[email protected]'}, {:node => 'node2', :jid => '[email protected]'}],
  :unconfigured => [{:node => 'node3', :jid => '[email protected]'}],
  :pending => [{:node => 'node4', :jid => '[email protected]'}],
  :none => [{:node => 'node5', :jid => '[email protected]'}] }

Returns:

  • (Hash)


67
68
69
70
71
72
73
74
75
76
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 67

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

#sizeFixnum

Get the size of the subscriptions list

Returns:

  • (Fixnum)


54
55
56
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 54

def size
  list.size
end

#subscriptionsBlather::XMPPNode

Get or create the actual subscriptions node

Returns:



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

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