Exception: Blather::StanzaError
- Inherits:
-
BlatherError
- Object
- StandardError
- BlatherError
- Blather::StanzaError
- Defined in:
- lib/blather/errors/stanza_error.rb
Overview
Stanza errors RFC3920 Section 9.3 (xmpp.org/rfcs/rfc3920.html#stanzas-error)
Constant Summary collapse
- STANZA_ERR_NS =
'urn:ietf:params:xml:ns:xmpp-stanzas'
- VALID_TYPES =
[:cancel, :continue, :modify, :auth, :wait].freeze
Instance Attribute Summary collapse
-
#extras ⇒ Object
readonly
Returns the value of attribute extras.
-
#name ⇒ Symbol
readonly
The error name.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.import(node) ⇒ Blather::StanzaError
Factory method for instantiating the proper class for the error.
Instance Method Summary collapse
-
#initialize(original, name, type, text = nil, extras = []) ⇒ StanzaError
constructor
Create a new StanzaError.
- #inspect ⇒ Object (also: #to_s)
-
#to_node ⇒ Blather::XMPPNode
Creates an XML node from the error.
-
#to_xml ⇒ String
Convert the object to a proper node then convert it to a string.
Methods inherited from BlatherError
Constructor Details
#initialize(original, name, type, text = nil, extras = []) ⇒ StanzaError
Create a new StanzaError
[RFC3920](xmpp.org/rfcs/rfc3920.html#rfc.section.9.3.2)
43 44 45 46 47 48 49 |
# File 'lib/blather/errors/stanza_error.rb', line 43 def initialize(original, name, type, text = nil, extras = []) @original = original @name = name self.type = type @text = text @extras = extras end |
Instance Attribute Details
#extras ⇒ Object (readonly)
Returns the value of attribute extras.
13 14 15 |
# File 'lib/blather/errors/stanza_error.rb', line 13 def extras @extras end |
#name ⇒ Symbol (readonly)
The error name
67 68 69 |
# File 'lib/blather/errors/stanza_error.rb', line 67 def name @name end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
13 14 15 |
# File 'lib/blather/errors/stanza_error.rb', line 13 def original @original end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
13 14 15 |
# File 'lib/blather/errors/stanza_error.rb', line 13 def text @text end |
#type ⇒ Object
Returns the value of attribute type.
13 14 15 |
# File 'lib/blather/errors/stanza_error.rb', line 13 def type @type end |
Class Method Details
.import(node) ⇒ Blather::StanzaError
Factory method for instantiating the proper class for the error
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/blather/errors/stanza_error.rb', line 19 def self.import(node) original = node.copy original.remove_child 'error' error_node = node.find_first '//*[local-name()="error"]' name = error_node.find_first('child::*[name()!="text"]', STANZA_ERR_NS).element_name type = error_node['type'] text = node.find_first 'descendant::*[name()="text"]', STANZA_ERR_NS text = text.content if text extras = error_node.find("descendant::*[name()!='text' and name()!='#{name}']").map { |n| n } self.new original, name, type, text, extras end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
100 101 102 |
# File 'lib/blather/errors/stanza_error.rb', line 100 def inspect "Stanza Error (#{@name}): #{self.text} [#{self.extras}]" end |
#to_node ⇒ Blather::XMPPNode
Creates an XML node from the error
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/blather/errors/stanza_error.rb', line 74 def to_node node = self.original.reply node.type = 'error' node << (error_node = XMPPNode.new('error')) error_node << (err = XMPPNode.new(@name, error_node.document)) err.namespace = 'urn:ietf:params:xml:ns:xmpp-stanzas' if self.text error_node << (text = XMPPNode.new('text', error_node.document)) text.namespace = 'urn:ietf:params:xml:ns:xmpp-stanzas' text.content = self.text end self.extras.each { |extra| error_node << extra.dup } node end |
#to_xml ⇒ String
Convert the object to a proper node then convert it to a string
95 96 97 |
# File 'lib/blather/errors/stanza_error.rb', line 95 def to_xml to_node.to_s end |