Class: Blather::Stanza::PubSub::Publish
- Inherits:
-
Blather::Stanza::PubSub
- Object
- Nokogiri::XML::Node
- XMPPNode
- Blather::Stanza
- Iq
- Blather::Stanza::PubSub
- Blather::Stanza::PubSub::Publish
- Includes:
- Enumerable
- Defined in:
- lib/blather/stanza/pubsub/publish.rb
Overview
# PubSub Publish Stanza
[XEP-0060 Section 7.1 - Publish an Item to a Node](xmpp.org/extensions/xep-0060.html#publisher-publish)
Constant Summary
Constants inherited from Iq
Constants inherited from XMPPNode
Class Method Summary collapse
-
.new(host = nil, node = nil, type = :set, payload = nil) ⇒ Object
Create a new publish node.
Instance Method Summary collapse
-
#each {|item| ... } ⇒ Object
Iterate over the list of items.
-
#items ⇒ Array<Blather::Stanza::PubSub::PubSubItem>
Get the list of items.
-
#node ⇒ String?
Get the name of the node to publish to.
-
#node=(node) ⇒ Object
Set the name of the node to publish to.
-
#payload=(payload) ⇒ Object
Set the payload to publish.
-
#publish ⇒ Blather::XMPPNode
Get or create the actual publish node.
-
#size ⇒ Fixnum
Get the size of the items list.
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(host = nil, node = nil, type = :set, payload = nil) ⇒ Object
Create a new publish node
22 23 24 25 26 27 |
# File 'lib/blather/stanza/pubsub/publish.rb', line 22 def self.new(host = nil, node = nil, type = :set, payload = nil) new_node = super(type, host) new_node.node = node new_node.payload = payload if payload new_node end |
Instance Method Details
#each {|item| ... } ⇒ Object
Iterate over the list of items
89 90 91 |
# File 'lib/blather/stanza/pubsub/publish.rb', line 89 def each(&block) items.each &block end |
#items ⇒ Array<Blather::Stanza::PubSub::PubSubItem>
Get the list of items
79 80 81 82 83 |
# File 'lib/blather/stanza/pubsub/publish.rb', line 79 def items publish.find('ns:item', :ns => self.class.registered_ns).map do |i| PubSubItem.new(nil,nil,self.document).inherit i end end |
#node ⇒ String?
Get the name of the node to publish to
54 55 56 |
# File 'lib/blather/stanza/pubsub/publish.rb', line 54 def node publish[:node] end |
#node=(node) ⇒ Object
Set the name of the node to publish to
61 62 63 |
# File 'lib/blather/stanza/pubsub/publish.rb', line 61 def node=(node) publish[:node] = node end |
#payload=(hash) ⇒ Object #payload=(array) ⇒ Object #payload=(string) ⇒ Object
Set the payload to publish
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/blather/stanza/pubsub/publish.rb', line 40 def payload=(payload) payload = case payload when Hash then payload.to_a when Array then payload.map { |v| [nil, v] } else [[nil, payload]] end payload.each do |id, value| self.publish << PubSubItem.new(id, value, self.document) end end |
#publish ⇒ Blather::XMPPNode
Get or create the actual publish node
68 69 70 71 72 73 74 |
# File 'lib/blather/stanza/pubsub/publish.rb', line 68 def publish unless publish = pubsub.find_first('ns:publish', :ns => self.class.registered_ns) self.pubsub << (publish = XMPPNode.new('publish', self.document)) publish.namespace = self.pubsub.namespace end publish end |
#size ⇒ Fixnum
Get the size of the items list
96 97 98 |
# File 'lib/blather/stanza/pubsub/publish.rb', line 96 def size items.size end |