Class: Blather::Stanza::PubSub::Items
- Inherits:
-
Blather::Stanza::PubSub
- Object
- Nokogiri::XML::Node
- XMPPNode
- Blather::Stanza
- Iq
- Blather::Stanza::PubSub
- Blather::Stanza::PubSub::Items
- Includes:
- Enumerable
- Defined in:
- lib/blather/stanza/pubsub/items.rb
Overview
# PubSub Items Stanza
[XEP-0060 Section 6.5 - Retrieve Items from a Node](xmpp.org/extensions/xep-0060.html#subscriber-retrieve)
Constant Summary
Constants inherited from Iq
Constants inherited from XMPPNode
Class Method Summary collapse
-
.new(type = nil, host = nil) ⇒ Object
Overrides the parent to ensure an items node is created.
-
.request(host, path, list = [], max = nil) ⇒ Blather::Stanza::PubSub::Items
Create a new Items request.
Instance Method Summary collapse
-
#each {|item| ... } ⇒ Object
Iterate over the list of items.
-
#items ⇒ Array<Blather::Stanza::PubSub::PubSubItem>
Get the list of items on this stanza.
-
#items_node ⇒ Blather::XMPPNode
Get or create the actual items node.
-
#max_items ⇒ Fixnum?
Get the max number of items requested.
-
#max_items=(max_items) ⇒ Object
Set the max number of items requested.
-
#node ⇒ String
Get the node name.
-
#node=(node) ⇒ Object
Set the node name.
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=, next_id, register, #reply, #reply!, #to, #to=, #type, #type=
Methods inherited from XMPPNode
class_from_registration, #content_from, import, #inherit, #inherit_attrs, #inspect, #namespace=, #namespace_href, #nokogiri_namespace=, #read_attr, #read_content, register, #remove_child, #remove_children, #set_content_for, #to_stanza, #write_attr
Methods inherited from Nokogiri::XML::Node
#[]=, #attr_set, #find_first, #nokogiri_xpath, #xpath
Class Method Details
.new(type = nil, host = nil) ⇒ Object
Overrides the parent to ensure an items node is created
39 40 41 42 43 |
# 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) ⇒ Blather::Stanza::PubSub::Items
Create a new Items request
24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Method Details
#each {|item| ... } ⇒ Object
Iterate over the list of items
76 77 78 |
# File 'lib/blather/stanza/pubsub/items.rb', line 76 def each(&block) items.each &block end |
#items ⇒ Array<Blather::Stanza::PubSub::PubSubItem>
Get the list of items on this stanza
83 84 85 86 87 |
# 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 ⇒ Blather::XMPPNode
Get or create the actual items node
92 93 94 95 96 97 98 |
# 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 ⇒ Fixnum?
Get the max number of items requested
62 63 64 |
# 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) ⇒ Object
Set the max number of items requested
69 70 71 |
# File 'lib/blather/stanza/pubsub/items.rb', line 69 def max_items=(max_items) items_node[:max_items] = max_items end |
#node ⇒ String
Get the node name
48 49 50 |
# File 'lib/blather/stanza/pubsub/items.rb', line 48 def node items_node[:node] end |
#node=(node) ⇒ Object
Set the node name
55 56 57 |
# File 'lib/blather/stanza/pubsub/items.rb', line 55 def node=(node) items_node[:node] = node end |