Sha256: b9b9e984c8a9eae9bd76ca1f2a737d19603b2b2401f75df6fbabb075e77579d8

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Blather
class Stanza
class PubSub

  class Items < PubSub
    register :pubsub_items, :pubsub_items, self.ns

    include Enumerable

    def self.request(host, path, list = [], max = nil)
      node = self.new :get, host

      node.items.attributes[:node] = path
      node.items.attributes[:max_items] = max

      (list || []).each do |id|
        item = XMPPNode.new 'item'
        item.attributes[:id] = id
        node.items << item
      end

      node
    end

    def initialize(type = nil, host = nil)
      super
      items
    end

    ##
    # Kill the items node before running inherit
    def inherit(node)
      items.remove!
      super
    end

    def [](id)
      items[id]
    end

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

    def size
      items.size
    end

    def items
      items = pubsub.find_first('//items', self.class.ns)
      items = pubsub.find_first('//pubsub_ns:items', :pubsub_ns => self.class.ns) unless items
      (self.pubsub << (items = XMPPNode.new('items'))) unless items
      items
    end
  end

end #PubSub
end #Stanza
end #Blather

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blather-0.2.2 lib/blather/stanza/pubsub/items.rb