Class: Blather::Stanza::PubSub::Retract

Inherits:
Blather::Stanza::PubSub show all
Includes:
Enumerable
Defined in:
lib/blather/stanza/pubsub/retract.rb

Overview

# PubSub Retract Stanza

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

Constant Summary

Constants inherited from Iq

Iq::VALID_TYPES

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Instance Attribute Summary

Attributes inherited from Blather::Stanza

#handler_hierarchy

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Blather::Stanza::PubSub

import, #inherit, #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=, #initialize, next_id, register, #reply, #reply!, #to, #to=, #type, #type=

Methods inherited from XMPPNode

class_from_registration, #decorate, decorator_modules, import, parse, register, #to_stanza

Constructor Details

This class inherits a constructor from Blather::Stanza

Class Method Details

.new(host = nil, node = nil, type = :set, retractions = []) ⇒ Object

Createa new Retraction stanza

Parameters:

  • host (String) (defaults to: nil)

    the host to send the request to

  • node (String) (defaults to: nil)

    the node to retract items from

  • type (Blather::Stanza::Iq::VALID_TYPES) (defaults to: :set)

    the IQ stanza type

  • retractions (Array<String>) (defaults to: [])

    an array of ids to retract



22
23
24
25
26
27
# 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

Instance Method Details

#each {|id| ... } ⇒ Object

Iterate over each retraction ID

Yield Parameters:

  • id (String)

    an ID to retract



78
79
80
# File 'lib/blather/stanza/pubsub/retract.rb', line 78

def each(&block)
  retractions.each &block
end

#nodeString

Get the name of the node to retract from

Returns:

  • (String)


32
33
34
# File 'lib/blather/stanza/pubsub/retract.rb', line 32

def node
  retract[:node]
end

#node=(node) ⇒ Object

Set the name of the node to retract from

Parameters:

  • node (String)


39
40
41
# File 'lib/blather/stanza/pubsub/retract.rb', line 39

def node=(node)
  retract[:node] = node
end

#retractBlather::XMPPNode

Get or create the actual retract node

Returns:



46
47
48
49
50
51
52
# 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

#retractionsArray<String>

Get the list of item IDs to retract

Returns:

  • (Array<String>)


69
70
71
72
73
# 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=(id) ⇒ Object #retractions=(ids) ⇒ Object

Set the retraction ids

Overloads:

  • #retractions=(id) ⇒ Object

    Parameters:

    • id (String)

      an ID to retract

  • #retractions=(ids) ⇒ Object

    Parameters:

    • ids (Array<String>)

      an array of IDs to retract



60
61
62
63
64
# 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

#sizeFixnum

The size of the retractions array

Returns:

  • (Fixnum)


85
86
87
# File 'lib/blather/stanza/pubsub/retract.rb', line 85

def size
  retractions.size
end