class Blather::Stanza::PubSub::Publish

# PubSub Publish Stanza

[XEP-0060 Section 7.1 - Publish an Item to a Node](xmpp.org/extensions/xep-0060.html#publisher-publish)

@handler :pubsub_publish

Public Class Methods

new(host = nil, node = nil, type = :set, payload = nil) click to toggle source

Create a new publish node

@param [String, nil] host the host to pushlish the node to @param [String, nil] node the name of the node to publish to @param [Blather::Stanza::Iq::VALID_TYPES] type the node type @param [#to_s] payload the payload to publish see {#payload=}

Calls superclass method Blather::Stanza::PubSub::new
# 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

Public Instance Methods

each(&block) click to toggle source

Iterate over the list of items

@yield [item] a block to accept each item @yieldparam [Blather::Stanza::PubSub::PubSubItem]

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

Get the list of items

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

# 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() click to toggle source

Get the name of the node to publish to

@return [String, nil]

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

Set the name of the node to publish to

@param [String, nil] node

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

Set the payload to publish

@overload payload=(hash)

Set the payload as a set of ID => payload entries
@param [Hash<id => payload>] hash

@overload payload=(array)

Set the list of payloads all at once
@param [Array<#to_s>] array

@overload payload=(string)

Set the payload as a string
@param [#to_s] string
# 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() click to toggle source

Get or create the actual publish node

@return [Blather::XMPPNode]

# 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() click to toggle source

Get the size of the items list

@return [Fixnum]

# File lib/blather/stanza/pubsub/publish.rb, line 96
def size
  items.size
end