class Jabber::XMPPStanza

root class of all Jabber XML elements

Public Class Methods

answer(xmppstanza, import=true) click to toggle source

Compose a response by doing the following:

  • Create a new XMPPStanza of the same subclass with the same element-name

  • Import xmppstanza if import is true

  • Swap 'to' and 'from'

  • Copy 'id'

  • Does not take care about the type

Attention: Be careful when answering to stanzas with type == :error - answering to an error may generate another error on the other side, which could be leading to a ping-pong effect quickly!

xmppstanza
XMPPStanza

source

import
true or false

Copy attributes and children of source

result
XMPPStanza

answer stanza

# File lib/xmpp4r/xmppstanza.rb, line 30
def XMPPStanza.answer(xmppstanza, import=true)
  x = xmppstanza.class.new
  if import
    x.import(xmppstanza)
  end
  x.from = xmppstanza.to
  x.to = xmppstanza.from
  x.id = xmppstanza.id
  x
end

Public Instance Methods

answer(import=true) click to toggle source

Compose a response of this XMPPStanza (see ::answer)

result
XMPPStanza

New constructed stanza

# File lib/xmpp4r/xmppstanza.rb, line 51
def answer(import=true)
  XMPPStanza.answer(self, import)
end
error() click to toggle source

Return the first <error/> child

# File lib/xmpp4r/xmppstanza.rb, line 43
def error
  first_element('error')
end
from() click to toggle source

get the from attribute

return
String

the element's from attribute

# File lib/xmpp4r/xmppstanza.rb, line 91
def from
  (a = attribute('from')).nil? ? a : JID.new(a.value)
end
from=(v) click to toggle source

set the from attribute

v
String

the value from set

# File lib/xmpp4r/xmppstanza.rb, line 99
def from= (v)
  add_attribute('from', v ? v.to_s : nil)
end
id() click to toggle source

get the id attribute

return
String

the element's id attribute

# File lib/xmpp4r/xmppstanza.rb, line 116
def id
  (a = attribute('id')).nil? ? a : a.value
end
id=(v) click to toggle source

set the id attribute

v
String

the value id set

# File lib/xmpp4r/xmppstanza.rb, line 124
def id= (v)
  add_attribute('id', v.to_s)
end
normalize() click to toggle source

Makes some changes to the structure of an XML element to help it respect the specification. For example, in a message, we should have <subject/> < <body/> < { rest of tags }

# File lib/xmpp4r/xmppstanza.rb, line 59
def normalize
end
set_from(v) click to toggle source

set the from attribute (chaining-friendly)

v
String

the value from set

# File lib/xmpp4r/xmppstanza.rb, line 107
def set_from(v)
  add_attribute('from', v ? v.to_s : nil)
  self
end
set_id(v) click to toggle source

set the id attribute (chaining-friendly)

v
String

the value id set

# File lib/xmpp4r/xmppstanza.rb, line 132
def set_id(v)
  add_attribute('id', v.to_s)
  self
end
set_to(v) click to toggle source

set the to attribute (chaining-friendly)

v
String

the value to set

# File lib/xmpp4r/xmppstanza.rb, line 82
def set_to(v)
  self.to = v
  self
end
set_type(v) click to toggle source

set the type attribute (chaining-friendly)

v
String

the value type set

# File lib/xmpp4r/xmppstanza.rb, line 157
def set_type(v)
  add_attribute('type', v)
  self
end
to() click to toggle source

get the to attribute

return
String

the element's to attribute

# File lib/xmpp4r/xmppstanza.rb, line 66
def to
  (a = attribute('to')).nil? ? a : JID.new(a.value)
end
to=(v) click to toggle source

set the to attribute

v
String

the value to set

# File lib/xmpp4r/xmppstanza.rb, line 74
def to= (v)
  add_attribute('to', v ? v.to_s : nil)
end
type() click to toggle source

get the type attribute

return
String

the element's type attribute

# File lib/xmpp4r/xmppstanza.rb, line 141
def type
  (a = attribute('type')).nil? ? a : a.value
end
type=(v) click to toggle source

set the type attribute

v
String

the value type set

# File lib/xmpp4r/xmppstanza.rb, line 149
def type= (v)
  add_attribute('type', v)
end