class Blather::Stanza::PubSub::Retract

# PubSub Retract Stanza

[XEP-0060 Section 7.2 - Delete an Item from a Node](xmpp.org/extensions/xep-0060.html#publisher-delete)

@handler :pubsub_retract

Public Class Methods

new(host = nil, node = nil, type = :set, retractions = []) click to toggle source

Createa new Retraction stanza

@param [String] host the host to send the request to @param [String] node the node to retract items from @param [Blather::Stanza::Iq::VALID_TYPES] type the IQ stanza type @param [Array<String>] retractions an array of ids to retract

Calls superclass method Blather::Stanza::PubSub::new
# File lib/blather/stanza/pubsub/retract.rb, line 22
def self.new(host = nil, node = nil, type = :set, retractions = [])
  new_node = super(type, host)
  new_node.node = node
  new_node.retractions = retractions
  new_node
end

Public Instance Methods

each(&block) click to toggle source

Iterate over each retraction ID

@yieldparam [String] id an ID to retract

# File lib/blather/stanza/pubsub/retract.rb, line 78
def each(&block)
  retractions.each &block
end
node() click to toggle source

Get the name of the node to retract from

@return [String]

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

Set the name of the node to retract from

@param [String] node

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

Get or create the actual retract node

@return [Blather::XMPPNode]

# File lib/blather/stanza/pubsub/retract.rb, line 46
def retract
  unless retract = pubsub.find_first('ns:retract', :ns => self.class.registered_ns)
    self.pubsub << (retract = XMPPNode.new('retract', self.document))
    retract.namespace = self.pubsub.namespace
  end
  retract
end
retractions() click to toggle source

Get the list of item IDs to retract

@return [Array<String>]

# File lib/blather/stanza/pubsub/retract.rb, line 69
def retractions
  retract.find('ns:item', :ns => self.class.registered_ns).map do |i|
    i[:id]
  end
end
retractions=(retractions = []) click to toggle source

Set the retraction ids

@overload retractions=(id)

@param [String] id an ID to retract

@overload retractions=(ids)

@param [Array<String>] ids an array of IDs to retract
# File lib/blather/stanza/pubsub/retract.rb, line 60
def retractions=(retractions = [])
  [retractions].flatten.each do |id|
    self.retract << PubSubItem.new(id, nil, self.document)
  end
end
size() click to toggle source

The size of the retractions array

@return [Fixnum]

# File lib/blather/stanza/pubsub/retract.rb, line 85
def size
  retractions.size
end