Exception: Blather::StreamError
- Inherits:
-
BlatherError
- Object
- StandardError
- BlatherError
- Blather::StreamError
- Defined in:
- lib/blather/errors/stream_error.rb
Overview
Stream Errors RFC3920 Section 9.3 (xmpp.org/rfcs/rfc3920.html#streams-error-rules)
Constant Summary collapse
- STREAM_ERR_NS =
'urn:ietf:params:xml:ns:xmpp-streams'
Instance Attribute Summary collapse
-
#extras ⇒ Object
readonly
Returns the value of attribute extras.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
-
.import(node) ⇒ Object
Factory method for instantiating the proper class for the error.
Instance Method Summary collapse
-
#initialize(name, text = nil, extras = []) ⇒ StreamError
constructor
text
is the (optional) error message. -
#inspect ⇒ Object
(also: #to_s)
:nodoc:.
- #name ⇒ Object
-
#to_node ⇒ Object
Creates an XML node from the error.
-
#to_xml ⇒ Object
Turns the object into XML fit to be sent over the stream.
Methods inherited from BlatherError
Constructor Details
#initialize(name, text = nil, extras = []) ⇒ StreamError
text
is the (optional) error message. extras
should be an array of nodes to attach to the error each extra should be in an application specific namespace see RFC3920 Section 4.7.2 (xmpp.org/rfcs/rfc3920.html#rfc.section.4.7.2)
32 33 34 35 36 |
# File 'lib/blather/errors/stream_error.rb', line 32 def initialize(name, text = nil, extras = []) @name = name @text = text @extras = extras end |
Instance Attribute Details
#extras ⇒ Object (readonly)
Returns the value of attribute extras.
11 12 13 |
# File 'lib/blather/errors/stream_error.rb', line 11 def extras @extras end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
11 12 13 |
# File 'lib/blather/errors/stream_error.rb', line 11 def text @text end |
Class Method Details
.import(node) ⇒ Object
Factory method for instantiating the proper class for the error
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/blather/errors/stream_error.rb', line 16 def self.import(node) name = node.find_first('descendant::*[name()!="text"]', STREAM_ERR_NS).element_name text = node.find_first 'descendant::*[name()="text"]', STREAM_ERR_NS text = text.content if text extras = node.find("descendant::*[namespace-uri()!='#{STREAM_ERR_NS}']").map { |n| n } self.new name, text, extras end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
:nodoc:
66 67 68 |
# File 'lib/blather/errors/stream_error.rb', line 66 def inspect # :nodoc: "Stream Error (#{@name}): #{self.text}" + (self.extras.empty? ? '' : " [#{self.extras}]") end |
#name ⇒ Object
38 39 40 |
# File 'lib/blather/errors/stream_error.rb', line 38 def name @name.gsub('-','_').to_sym end |
#to_node ⇒ Object
Creates an XML node from the error
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/blather/errors/stream_error.rb', line 44 def to_node node = XMPPNode.new('stream:error') node << (err = XMPPNode.new(@name, node.document)) err.namespace = 'urn:ietf:params:xml:ns:xmpp-streams' if self.text node << (text = XMPPNode.new('text', node.document)) text.namespace = 'urn:ietf:params:xml:ns:xmpp-streams' text.content = self.text end self.extras.each { |extra| node << extra.dup } node end |
#to_xml ⇒ Object
Turns the object into XML fit to be sent over the stream
62 63 64 |
# File 'lib/blather/errors/stream_error.rb', line 62 def to_xml to_node.to_s end |