Exception: Vines::StanzaError

Inherits:
XmppError
  • Object
show all
Defined in:
lib/vines/error.rb

Constant Summary collapse

TYPES =
%w[auth cancel continue modify wait].freeze
KINDS =
%w[message presence iq].freeze
NAMESPACE =
'urn:ietf:params:xml:ns:xmpp-stanzas'.freeze

Instance Method Summary collapse

Methods inherited from XmppError

#element_name

Constructor Details

#initialize(el, type, text = nil) ⇒ StanzaError

Returns a new instance of StanzaError.



60
61
62
63
64
65
# File 'lib/vines/error.rb', line 60

def initialize(el, type, text=nil)
  raise "type must be one of: %s"   % TYPES.join(', ') unless TYPES.include?(type)
  raise "stanza must be one of: %s" % KINDS.join(', ') unless KINDS.include?(el.name)
  @stanza_kind, @type, @text = el.name, type, text
  @id, @from, @to = %w[id from to].map {|a| el[a] }
end

Instance Method Details

#to_xmlObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vines/error.rb', line 67

def to_xml
  doc = Document.new
  doc.create_element(@stanza_kind) do |el|
    el['from'] = @to   if @to
    el['id']   = @id   if @id
    el['to']   = @from if @from
    el['type'] = 'error'
    el << doc.create_element('error', 'type' => @type) do |error|
      error << doc.create_element(element_name, 'xmlns' => NAMESPACE)
      if @text
        error << doc.create_element('text', @text, 'xmlns' => NAMESPACE, 'xml:lang' => 'en')
      end
    end
  end.to_xml(:indent => 0).gsub(/\n/, '')
end