Class: Blather::Stanza::PubSub::Subscriptions
- Inherits:
-
Blather::Stanza::PubSub
- Object
- Niceogiri::XML::Node
- XMPPNode
- Blather::Stanza
- Iq
- Blather::Stanza::PubSub
- Blather::Stanza::PubSub::Subscriptions
- 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
Constants inherited from XMPPNode
Instance Attribute Summary
Attributes inherited from Blather::Stanza
Class Method Summary collapse
-
.new(type = nil, host = nil) ⇒ Object
Overrides the parent to ensure a subscriptions node is created.
Instance Method Summary collapse
-
#each {|subscription| ... } ⇒ Object
Iterate over the list of subscriptions.
-
#inherit(node) ⇒ Object
Overrides the parent to ensure the subscriptions node is destroyed.
-
#list ⇒ Hash
Get a hash of subscriptions.
-
#size ⇒ Fixnum
Get the size of the subscriptions list.
-
#subscriptions ⇒ Blather::XMPPNode
Get or create the actual subscriptions node.
Methods inherited from Blather::Stanza::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
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 |
#list ⇒ Hash
Get a hash of subscriptions
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 |
#size ⇒ Fixnum
Get the size of the subscriptions list
54 55 56 |
# File 'lib/blather/stanza/pubsub/subscriptions.rb', line 54 def size list.size end |
#subscriptions ⇒ Blather::XMPPNode
Get or create the actual subscriptions node
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 |