class Blather::Stanza::PubSub::Items

# PubSub Items Stanza

[XEP-0060 Section 6.5 - Retrieve Items from a Node](xmpp.org/extensions/xep-0060.html#subscriber-retrieve)

@handler :pubsub_items

Public Class Methods

new(type = nil, host = nil) click to toggle source

Overrides the parent to ensure an items node is created @private

Calls superclass method Blather::Stanza::PubSub::new
# File lib/blather/stanza/pubsub/items.rb, line 39
def self.new(type = nil, host = nil)
  new_node = super
  new_node.items
  new_node
end
request(host, path, list = [], max = nil) click to toggle source

Create a new Items request

@param [String] host the pubsub host to send the request to @param [String] path the path of the node @param [Array<String>] list an array of IDs to request @param [#to_s] max the maximum number of items to return

@return [Blather::Stanza::PubSub::Items]

# File lib/blather/stanza/pubsub/items.rb, line 24
def self.request(host, path, list = [], max = nil)
  node = self.new :get, host

  node.node = path
  node.max_items = max

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

  node
end

Public Instance Methods

each(&block) click to toggle source

Iterate over the list of items

@yieldparam [Blather::Stanza::PubSub::PubSubItem] item

# File lib/blather/stanza/pubsub/items.rb, line 76
def each(&block)
  items.each &block
end
items() click to toggle source

Get the list of items on this stanza

@return [Array<Blather::Stanza::PubSub::PubSubItem>]

# File lib/blather/stanza/pubsub/items.rb, line 83
def items
  items_node.find('ns:item', :ns => self.class.registered_ns).map do |i|
    PubSubItem.new(nil,nil,self.document).inherit i
  end
end
items_node() click to toggle source

Get or create the actual items node

@return [Blather::XMPPNode]

# File lib/blather/stanza/pubsub/items.rb, line 92
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
max_items() click to toggle source

Get the max number of items requested

@return [Fixnum, nil]

# File lib/blather/stanza/pubsub/items.rb, line 62
def max_items
  items_node[:max_items].to_i if items_node[:max_items]
end
max_items=(max_items) click to toggle source

Set the max number of items requested

@param [Fixnum, nil] max_items

# File lib/blather/stanza/pubsub/items.rb, line 69
def max_items=(max_items)
  items_node[:max_items] = max_items
end
node() click to toggle source

Get the node name

@return [String]

# File lib/blather/stanza/pubsub/items.rb, line 48
def node
  items_node[:node]
end
node=(node) click to toggle source

Set the node name

@param [String, nil] node

# File lib/blather/stanza/pubsub/items.rb, line 55
def node=(node)
  items_node[:node] = node
end