Class: AgentXmpp::Xmpp::ErrorResponse

Inherits:
Element show all
Defined in:
lib/agent_xmpp/xmpp/error_response.rb

Overview


Constant Summary collapse

@@Errors =

.….….….….….….….….….….….….….….….….….….….….….….….….……

[['bad-request', :modify, 400],
['conflict', :cancel, 409],
['feature-not-implemented', :cancel, 501],
['forbidden', :auth, 403],
['gone', :modify, 302],
['internal-server-error', :wait, 500],
['item-not-found', :cancel, 404],
['jid-malformed', :modify, 400],
['not-acceptable', :modify, 406],
['not-allowed', :cancel, 405],
['not-authorized', :auth, 401],
['payment-required', :auth, 402],
['recipient-unavailable', :wait, 404],
['redirect', :modify, 302],
['registration-required', :auth, 407],
['remote-server-not-found', :cancel, 404],
['remote-server-timeout', :wait, 504],
['resource-constraint', :wait, 500],
['service-unavailable', :cancel, 503],
['subscription-required', :auth, 407],
['undefined-condition', nil, 500],
['unexpected-request', :wait, 400]]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#<<, class_for_name_xmlns, #clone, import, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=, xmpp_attribute, xmpp_child

Methods inherited from REXML::Element

#delete_elements, #first_element, #first_element_text, #import, import, #replace_element_text, #typed_add

Constructor Details

#initialize(errorcondition = nil, text = nil) ⇒ ErrorResponse

.….….….….….….….….….….….….….….….….….….….….….….….….……



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 85

def initialize(errorcondition=nil, text=nil)
  if errorcondition.nil?
    super()
  else
    errortype = nil
    errorcode = nil
    @@Errors.each do |cond,type,code|
      if errorcondition == cond
        errortype = type
        errorcode = code
      end
    end
    raise ArgumentError, "Unknown error condition when initializing ErrorReponse" if errortype.nil? || errorcode.nil?
    super()
    self.error = errorcondition unless errorcondition.nil?
    self.type = errortype unless errortype.nil?
    self.code = errorcode unless errorcode.nil?
  end
  self.text = text unless text.nil?
end

Class Method Details

.feature_not_implemented(request) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



36
37
38
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 36

def feature_not_implemented(request)
  iq_error(request, 'feature-not-implemented', 'feature not implemented')
end

.item_not_found(request) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



46
47
48
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 46

def item_not_found(request)
  query_error(request, 'item-not-found', 'item not found')
end

.no_route(params) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



31
32
33
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 31

def no_route(params)
  command_error(params, 'item-not-found', 'no route for specified command node')
end

.service_unavailable(request) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



41
42
43
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 41

def service_unavailable(request)
  query_error(request, 'service-unavailable', 'service unavailable')
end

.unsupported_payload(params) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



26
27
28
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 26

def unsupported_payload(params)
  command_error(params, 'bad-request', 'unsupported payload')
end

Instance Method Details

#codeObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



107
108
109
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 107

def code
  (c = attributes['code']).nil? ? nil : c.to_i
end

#code=(i) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



112
113
114
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 112

def code=(i)
  attributes['code'] = i.nil? ? nil : i.to_s
end

#errorObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



117
118
119
120
121
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 117

def error
  name = nil
  each_element {|e| name = e.name if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
  name
end

#error=(s) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



124
125
126
127
128
129
130
131
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 124

def error=(s)
  xe = nil
  each_element {|e| xe = e if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
  unless xe.nil?
    delete_element(xe)
  end
  add_element(s).add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
end

#textObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



134
135
136
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 134

def text
  first_element_text('text') || super
end

#text=(s) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



139
140
141
142
143
144
145
146
# File 'lib/agent_xmpp/xmpp/error_response.rb', line 139

def text=(s)
  delete_elements('text')
  unless s.nil?
    e = add_element('text')
    e.add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
    e.text = s
  end
end