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)
45 46 47 48 49 50 51 |
# File 'lib/blather/errors/stanza_error.rb', line 45 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.
15 16 17 |
# File 'lib/blather/errors/stanza_error.rb', line 15 def extras @extras end |
#name ⇒ Symbol (readonly)
The error name
69 70 71 |
# File 'lib/blather/errors/stanza_error.rb', line 69 def name @name end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
15 16 17 |
# File 'lib/blather/errors/stanza_error.rb', line 15 def original @original end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
15 16 17 |
# File 'lib/blather/errors/stanza_error.rb', line 15 def text @text end |
#type ⇒ Object
Returns the value of attribute type.
15 16 17 |
# File 'lib/blather/errors/stanza_error.rb', line 15 def type @type end |
Class Method Details
.import(node) ⇒ Blather::StanzaError
Factory method for instantiating the proper class for the error
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/blather/errors/stanza_error.rb', line 21 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
103 104 105 |
# File 'lib/blather/errors/stanza_error.rb', line 103 def inspect "Stanza Error (#{@name}): #{self.text} [#{self.extras}]" end |
#to_node ⇒ Blather::XMPPNode
Creates an XML node from the error
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/blather/errors/stanza_error.rb', line 76 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)) error_node['type'] = self.type 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
98 99 100 |
# File 'lib/blather/errors/stanza_error.rb', line 98 def to_xml to_node.to_s end |