class Blather::Stanza::PubSub::Subscriptions
[XEP-0060 Section 5.6 Retrieve Subscriptions](xmpp.org/extensions/xep-0060.html#entity-subscriptions)
@handler :pubsub_subscriptions
Public Class Methods
new(type = nil, host = nil)
click to toggle source
Overrides the parent to ensure a subscriptions node is created @private
Calls superclass method
Blather::Stanza::PubSub::new
# 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
Public Instance Methods
each(&block)
click to toggle source
Iterate over the list of subscriptions
@yieldparam [Hash] subscription @see {#list}
# File lib/blather/stanza/pubsub/subscriptions.rb, line 47 def each(&block) list.each &block end
inherit(node)
click to toggle source
Overrides the parent to ensure the subscriptions node is destroyed @private
Calls superclass method
Blather::Stanza::PubSub#inherit
# File lib/blather/stanza/pubsub/subscriptions.rb, line 27 def inherit(node) subscriptions.remove super end
list()
click to toggle source
Get a hash of subscriptions
@example
{ :subscribed => [{:node => 'node1', :jid => 'francisco@denmark.lit', :subid => 'fd8237yr872h3f289j2'}, {:node => 'node2', :jid => 'francisco@denmark.lit', :subid => 'h8394hf8923ju'}], :unconfigured => [{:node => 'node3', :jid => 'francisco@denmark.lit'}], :pending => [{:node => 'node4', :jid => 'francisco@denmark.lit'}], :none => [{:node => 'node5', :jid => 'francisco@denmark.lit'}] }
@return [Hash]
# 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
size()
click to toggle source
Get the size of the subscriptions list
@return [Fixnum]
# File lib/blather/stanza/pubsub/subscriptions.rb, line 54 def size list.size end
subscriptions()
click to toggle source
Get or create the actual subscriptions node
@return [Blather::XMPPNode]
# File lib/blather/stanza/pubsub/subscriptions.rb, line 35 def subscriptions subs = pubsub.find_first('ns:subscriptions', :ns => self.class.registered_ns) unless subs self.pubsub << (subs = XMPPNode.new('subscriptions', self.document)) end subs end