class Blather::StreamError

Stream Errors [RFC3920 Section 9.3](xmpp.org/rfcs/rfc3920.html#streams-error-rules)

@handler :stream_error

Constants

STREAM_ERR_NS

@private

Attributes

extras[R]
text[R]

Public Class Methods

import(node) click to toggle source

Factory method for instantiating the proper class for the error

@param [Blather::XMPPNode] node the importable node

# File lib/blather/errors/stream_error.rb, line 18
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
new(name, text = nil, extras = []) click to toggle source

Create a new Stream Error [RFC3920 Section 4.7.2](xmpp.org/rfcs/rfc3920.html#rfc.section.4.7.2)

@param [String] name the error name @param [String, nil] text optional error text @param [Array<Blather::XMPPNode>] extras an array of extras to attach to the error

# File lib/blather/errors/stream_error.rb, line 36
def initialize(name, text = nil, extras = [])
  @name = name
  @text = text
  @extras = extras
end

Public Instance Methods

inspect() click to toggle source

@private

# File lib/blather/errors/stream_error.rb, line 77
def inspect
  "Stream Error (#{@name}): #{self.text}" + (self.extras.empty? ? '' : " [#{self.extras}]")
end
Also aliased as: to_s
name() click to toggle source

The error name

@return [Symbol]

# File lib/blather/errors/stream_error.rb, line 45
def name
  @name.gsub('-','_').to_sym
end
to_node() click to toggle source

Creates an XML node from the error

@return [Blather::XMPPNode]

# File lib/blather/errors/stream_error.rb, line 52
def to_node
  node = XMPPNode.new('error')
  node.namespace = {'stream' => Blather::Stream::STREAM_NS}

  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_s()

@private

Alias for: inspect
to_xml(*args) click to toggle source

Convert the object to a proper node then convert it to a string

@return [String]

# File lib/blather/errors/stream_error.rb, line 72
def to_xml(*args)
  to_node.to_xml(*args)
end