Class: Blather::Stanza::PubSub::Event

Inherits:
Message show all
Defined in:
lib/blather/stanza/pubsub/event.rb

Overview

# PubSub Event Stanza

[XEP-0060](xmpp.org/extensions/xep-0060.html)

The PubSub Event stanza is used in many places. Please see the XEP for more information.

Constant Summary collapse

SHIM_NS =
'http://jabber.org/protocol/shim'.freeze

Constants inherited from Message

Message::CHAT_STATE_NS, Message::HTML_BODY_NS, Message::HTML_NS, Message::VALID_CHAT_STATES, Message::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 Message

#body, #body=, #chat?, #chat_state, #chat_state=, #delay, #delayed?, #error?, #form, #groupchat?, #headline?, import, #normal?, #parent_thread, #subject, #subject=, #thread, #thread=, #type=, #xhtml, #xhtml=, #xhtml_node

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(type = nil) ⇒ Object

Ensures the event_node is created



21
22
23
24
25
# File 'lib/blather/stanza/pubsub/event.rb', line 21

def self.new(type = nil)
  node = super
  node.event_node
  node
end

Instance Method Details

#event_nodeBlather::XMPPNode

Get or create the actual event node

Returns:



83
84
85
86
87
88
89
90
91
# File 'lib/blather/stanza/pubsub/event.rb', line 83

def event_node
  node = find_first('//ns:event', :ns => self.class.registered_ns)
  node = find_first('//event', self.class.registered_ns) unless node
  unless node
    (self << (node = XMPPNode.new('event', self.document)))
    node.namespace = self.class.registered_ns
  end
  node
end

#inherit(node) ⇒ Object

Kill the event_node node before running inherit



29
30
31
32
# File 'lib/blather/stanza/pubsub/event.rb', line 29

def inherit(node)
  event_node.remove
  super
end

#itemsArray<Blather::Stanza::PubSub::PubSubItem>

Get the list of items attached to this event



60
61
62
63
64
# File 'lib/blather/stanza/pubsub/event.rb', line 60

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?Boolean

Check if this stanza has items

Returns:

  • (Boolean)


69
70
71
# File 'lib/blather/stanza/pubsub/event.rb', line 69

def items?
  !items.empty?
end

#items_nodeBlather::XMPPNode

Get or create the actual items node

Returns:



96
97
98
99
100
101
102
103
# File 'lib/blather/stanza/pubsub/event.rb', line 96

def items_node
  node = find_first('ns:event/ns:items', :ns => self.class.registered_ns)
  unless node
    (self.event_node << (node = XMPPNode.new('items', self.document)))
    node.namespace = event_node.namespace
  end
  node
end

#nodeString?

Get the name of the node

Returns:

  • (String, nil)


37
38
39
# File 'lib/blather/stanza/pubsub/event.rb', line 37

def node
  !purge? ? items_node[:node] : purge_node[:node]
end

#purge?XML::Node?

Check if this is a purge stanza

Returns:

  • (XML::Node, nil)


76
77
78
# File 'lib/blather/stanza/pubsub/event.rb', line 76

def purge?
  purge_node
end

#purge_nodeBlather::XMPPNode

Get the actual purge node

Returns:



108
109
110
# File 'lib/blather/stanza/pubsub/event.rb', line 108

def purge_node
  event_node.find_first('//ns:purge', :ns => self.class.registered_ns)
end

#retractionsArray<String>

Get a list of retractions

Returns:

  • (Array<String>)


44
45
46
47
48
# File 'lib/blather/stanza/pubsub/event.rb', line 44

def retractions
  items_node.find('//ns:retract', :ns => self.class.registered_ns).map do |i|
    i[:id]
  end
end

#retractions?Boolean

Check if this is a retractions stanza

Returns:

  • (Boolean)


53
54
55
# File 'lib/blather/stanza/pubsub/event.rb', line 53

def retractions?
  !retractions.empty?
end

#subscription?XML::Node?

Check if this is a subscription stanza

Returns:

  • (XML::Node, nil)


124
125
126
# File 'lib/blather/stanza/pubsub/event.rb', line 124

def subscription?
  subscription_node
end

#subscription_idsArray<String>

Get the subscription IDs associated with this event

Returns:

  • (Array<String>)


115
116
117
118
119
# File 'lib/blather/stanza/pubsub/event.rb', line 115

def subscription_ids
  find('//ns:header[@name="SubID"]', :ns => SHIM_NS).map do |n|
    n.content
  end
end

#subscription_nodeBlather::XMPPNode Also known as: subscription

Get the actual subscription node

Returns:



131
132
133
# File 'lib/blather/stanza/pubsub/event.rb', line 131

def subscription_node
  event_node.find_first('//ns:subscription', :ns => self.class.registered_ns)
end