Sha256: 27596b8fc67ae8729969a8d311586ec19868757da7508ac98c5741caf941dcc7

Contents?: true

Size: 1.28 KB

Versions: 13

Compression:

Stored size: 1.28 KB

Contents

module Blather
class Stanza
class PubSub

  class Items < PubSub
    register :pubsub_items, :items, self.registered_ns

    include Enumerable
    alias_method :find, :xpath

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

      node.node = path
      node.max_items = max

      (list || []).each { |id| node.items_node << PubSubItem.new(id, nil, node.document) }

      node
    end

    def self.new(type = nil, host = nil)
      new_node = super
      new_node.items
      new_node
    end

    def node
      items_node[:node]
    end

    def node=(node)
      items_node[:node] = node
    end

    def max_items
      items_node[:max_items].to_i if items_node[:max_items]
    end

    def max_items=(max_items)
      items_node[:max_items] = max_items
    end

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

    def items
      items_node.find('ns:item', :ns => self.class.registered_ns).map { |i| PubSubItem.new(nil,nil,self.document).inherit i }
    end

    def items_node
      unless node = self.pubsub.find_first('ns:items', :ns => self.class.registered_ns)
        (self.pubsub << (node = XMPPNode.new('items', self.document)))
        node.namespace = self.pubsub.namespace
      end
      node
    end
  end

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/items.rb
sprsquish-blather-0.4.1 lib/blather/stanza/pubsub/items.rb
sprsquish-blather-0.4.2 lib/blather/stanza/pubsub/items.rb
sprsquish-blather-0.4.3 lib/blather/stanza/pubsub/items.rb
sprsquish-blather-0.4.4 lib/blather/stanza/pubsub/items.rb
blather-0.4.7 lib/blather/stanza/pubsub/items.rb
blather-0.4.6 lib/blather/stanza/pubsub/items.rb
blather-0.4.5 lib/blather/stanza/pubsub/items.rb
blather-0.4.4 lib/blather/stanza/pubsub/items.rb
blather-0.4.3 lib/blather/stanza/pubsub/items.rb
blather-0.4.1 lib/blather/stanza/pubsub/items.rb
blather-0.4.2 lib/blather/stanza/pubsub/items.rb
blather-0.4.0 lib/blather/stanza/pubsub/items.rb