Exception: Vines::StanzaError
- Defined in:
- lib/vines/error.rb
Direct Known Subclasses
Vines::StanzaErrors::BadRequest, Vines::StanzaErrors::Conflict, Vines::StanzaErrors::FeatureNotImplemented, Vines::StanzaErrors::Forbidden, Vines::StanzaErrors::Gone, Vines::StanzaErrors::InternalServerError, Vines::StanzaErrors::ItemNotFound, Vines::StanzaErrors::JidMalformed, Vines::StanzaErrors::NotAcceptable, Vines::StanzaErrors::NotAllowed, Vines::StanzaErrors::NotAuthorized, Vines::StanzaErrors::PolicyViolation, Vines::StanzaErrors::RecipientUnavailable, Vines::StanzaErrors::Redirect, Vines::StanzaErrors::RegistrationRequired, Vines::StanzaErrors::RemoteServerNotFound, Vines::StanzaErrors::RemoteServerTimeout, Vines::StanzaErrors::ResourceConstraint, Vines::StanzaErrors::ServiceUnavailable, Vines::StanzaErrors::SubscriptionRequired, Vines::StanzaErrors::UndefinedCondition, Vines::StanzaErrors::UnexpectedRequest
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
-
#initialize(el, type, text = nil) ⇒ StanzaError
constructor
A new instance of StanzaError.
- #to_xml ⇒ Object
Methods inherited from XmppError
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_xml ⇒ Object
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 |