Class: Blather::Stanza

Inherits:
XMPPNode
  • Object
show all
Defined in:
lib/blather/stanza.rb,
lib/blather/stanza/x.rb,
lib/blather/stanza/iq.rb,
lib/blather/stanza/iq/si.rb,
lib/blather/stanza/disco.rb,
lib/blather/stanza/iq/ibb.rb,
lib/blather/stanza/iq/s5b.rb,
lib/blather/stanza/pubsub.rb,
lib/blather/stanza/iq/ping.rb,
lib/blather/stanza/message.rb,
lib/blather/stanza/presence.rb,
lib/blather/stanza/iq/query.rb,
lib/blather/stanza/iq/vcard.rb,
lib/blather/stanza/iq/roster.rb,
lib/blather/stanza/presence/c.rb,
lib/blather/stanza/iq/command.rb,
lib/blather/stanza/pubsub_owner.rb,
lib/blather/stanza/presence/muc.rb,
lib/blather/stanza/pubsub/event.rb,
lib/blather/stanza/pubsub/items.rb,
lib/blather/stanza/pubsub/errors.rb,
lib/blather/stanza/pubsub/create.rb,
lib/blather/stanza/pubsub/publish.rb,
lib/blather/stanza/pubsub/retract.rb,
lib/blather/stanza/presence/status.rb,
lib/blather/stanza/message/muc_user.rb,
lib/blather/stanza/pubsub/subscribe.rb,
lib/blather/stanza/disco/disco_info.rb,
lib/blather/stanza/disco/disco_items.rb,
lib/blather/stanza/muc/muc_user_base.rb,
lib/blather/stanza/presence/muc_user.rb,
lib/blather/stanza/pubsub/unsubscribe.rb,
lib/blather/stanza/disco/capabilities.rb,
lib/blather/stanza/pubsub_owner/purge.rb,
lib/blather/stanza/pubsub/subscription.rb,
lib/blather/stanza/pubsub_owner/delete.rb,
lib/blather/stanza/pubsub/affiliations.rb,
lib/blather/stanza/pubsub/subscriptions.rb,
lib/blather/stanza/presence/subscription.rb

Overview

# Base XMPP Stanza

All stanzas inherit this class. It provides a set of methods and helpers common to all XMPP Stanzas

Direct Known Subclasses

Iq, Message, Presence

Defined Under Namespace

Classes: Capabilities, Disco, DiscoInfo, DiscoItems, Iq, MUC, Message, Presence, PubSub, PubSubErrors, PubSubItem, PubSubOwner, X

Constant Summary

@@last_id =
0
@@handler_list =
[]

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XMPPNode

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

Constructor Details

#initialize(*args) ⇒ Stanza



34
35
36
37
# File 'lib/blather/stanza.rb', line 34

def initialize(*args)
  super
  @handler_hierarchy = []
end

Instance Attribute Details

#handler_hierarchyObject



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

def handler_hierarchy
  @handler_hierarchy + self.class.handler_hierarchy
end

Class Method Details

.handler_listArray<Symbol>

The handler stack for the current stanza class



46
47
48
# File 'lib/blather/stanza.rb', line 46

def self.handler_list
  @@handler_list
end

.next_idString

Helper method that creates a unique ID for stanzas



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

def self.next_id
  @@last_id += 1
  'blather%04x' % @@last_id
end

.register(handler, name = nil, ns = nil) ⇒ Object

Registers a callback onto the callback stack



25
26
27
28
29
30
31
32
# File 'lib/blather/stanza.rb', line 25

def self.register(handler, name = nil, ns = nil)
  @@handler_list << handler
  self.handler_hierarchy ||= [:stanza]
  self.handler_hierarchy = [handler] + self.handler_hierarchy

  name = name || self.registered_name || handler
  super name, ns
end

Instance Method Details

#as_error(name, type, text = nil, extras = []) ⇒ Blather::StanzaError

Create an error stanza from the current stanza

the error



153
154
155
# File 'lib/blather/stanza.rb', line 153

def as_error(name, type, text = nil, extras = [])
  StanzaError.new self, name, type, text, extras
end

#error?true, false

Check if the stanza is an error stanza



61
62
63
# File 'lib/blather/stanza.rb', line 61

def error?
  self.type == :error
end

#fromBlather::JID?

Get the stanza's from



119
120
121
# File 'lib/blather/stanza.rb', line 119

def from
  JID.new(self[:from]) if self[:from]
end

#from=(from) ⇒ Object

Set the stanza's from field



126
127
128
# File 'lib/blather/stanza.rb', line 126

def from=(from)
  write_attr :from, from
end

#idString?

Get the stanza's ID



91
92
93
# File 'lib/blather/stanza.rb', line 91

def id
  read_attr :id
end

#id=(id) ⇒ Object

Set the stanza's ID



98
99
100
# File 'lib/blather/stanza.rb', line 98

def id=(id)
  write_attr :id, id
end

#reply(opts = {}) ⇒ Blather::Stanza

Creates a copy with to and from swapped

Options Hash (opts):

  • :remove_children (Boolean)

    Wether or not to remove child nodes when replying



71
72
73
# File 'lib/blather/stanza.rb', line 71

def reply(opts = {})
  self.dup.reply! opts
end

#reply!(opts = {}) ⇒ self

Swaps from and to

Options Hash (opts):

  • :remove_children (Boolean)

    Wether or not to remove child nodes when replying



81
82
83
84
85
86
# File 'lib/blather/stanza.rb', line 81

def reply!(opts = {})
  opts = {:remove_children => false}.merge opts
  self.to, self.from = self.from, self.to
  self.children.remove if opts[:remove_children]
  self
end

#toBlather::JID?

Get the stanza's to



105
106
107
# File 'lib/blather/stanza.rb', line 105

def to
  JID.new(self[:to]) if self[:to]
end

#to=(to) ⇒ Object

Set the stanza's to field



112
113
114
# File 'lib/blather/stanza.rb', line 112

def to=(to)
  write_attr :to, to
end

#typeSymbol?

Get the stanza's type



133
134
135
# File 'lib/blather/stanza.rb', line 133

def type
  read_attr :type, :to_sym
end

#type=(type) ⇒ Object

Set the stanza's type



140
141
142
# File 'lib/blather/stanza.rb', line 140

def type=(type)
  write_attr :type, type
end