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

Instance Attribute Summary

Attributes inherited from Blather::Stanza

#handler_hierarchy

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

Methods inherited from XMPPNode

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

Constructor Details

This class inherits a constructor from Blather::Stanza

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]', :subid => 'fd8237yr872h3f289j2'}, {:node => 'node2', :jid => '[email protected]', :subid => 'h8394hf8923ju'}],
  :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
77
78
# 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] ||= []
    sub = {
      :node => item[:node],
      :jid => item[:jid]
    }
    sub[:subid] = item[:subid] if item[:subid]
    hash[item[:subscription].to_sym] << sub
    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