Sha256: 61532348fe247320e2069742fce492796db8100cb44614f774e1198c8c14541a

Contents?: true

Size: 1.17 KB

Versions: 13

Compression:

Stored size: 1.17 KB

Contents

module Blather
class Stanza
class PubSub

  class Subscriptions < PubSub
    register :pubsub_subscriptions, :subscriptions, self.registered_ns

    include Enumerable
    alias_method :find, :xpath

    ##
    # Ensure the namespace is set to the query node
    def self.new(type = nil, host = nil)
      new_node = super type
      new_node.to = host
      new_node.subscriptions
      new_node
    end

    ##
    # Kill the pubsub node before running inherit
    def inherit(node)
      subscriptions.remove
      super
    end

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

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

    def size
      list.size
    end

    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
  end #Subscriptions

end #PubSub
end #Stanza
end #Blather

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
sprsquish-blather-0.4.0 lib/blather/stanza/pubsub/subscriptions.rb
sprsquish-blather-0.4.1 lib/blather/stanza/pubsub/subscriptions.rb
sprsquish-blather-0.4.2 lib/blather/stanza/pubsub/subscriptions.rb
sprsquish-blather-0.4.3 lib/blather/stanza/pubsub/subscriptions.rb
sprsquish-blather-0.4.4 lib/blather/stanza/pubsub/subscriptions.rb
blather-0.4.7 lib/blather/stanza/pubsub/subscriptions.rb
blather-0.4.6 lib/blather/stanza/pubsub/subscriptions.rb
blather-0.4.5 lib/blather/stanza/pubsub/subscriptions.rb
blather-0.4.4 lib/blather/stanza/pubsub/subscriptions.rb
blather-0.4.3 lib/blather/stanza/pubsub/subscriptions.rb
blather-0.4.2 lib/blather/stanza/pubsub/subscriptions.rb
blather-0.4.1 lib/blather/stanza/pubsub/subscriptions.rb
blather-0.4.0 lib/blather/stanza/pubsub/subscriptions.rb