Class: Gillbus::BaseResponse

Inherits:
Object
  • Object
show all
Extended by:
Fields
Includes:
UpdateAttrs
Defined in:
lib/gillbus/base_response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Fields

parse, parser, parser_class

Methods included from UpdateAttrs

#initialize, #update_attrs

Instance Attribute Details

#dataObject

Returns the value of attribute data.



8
9
10
# File 'lib/gillbus/base_response.rb', line 8

def data
  @data
end

#error_codeObject

Returns the value of attribute error_code.



11
12
13
# File 'lib/gillbus/base_response.rb', line 11

def error_code
  @error_code
end

#error_messageObject

Returns the value of attribute error_message.



12
13
14
# File 'lib/gillbus/base_response.rb', line 12

def error_message
  @error_message
end

#external_error_messageObject

Returns the value of attribute external_error_message.



13
14
15
# File 'lib/gillbus/base_response.rb', line 13

def external_error_message
  @external_error_message
end

#raw_xmlObject

make accessible for logging and debuging



16
17
18
# File 'lib/gillbus/base_response.rb', line 16

def raw_xml
  @raw_xml
end

#request_timeObject

Returns the value of attribute request_time.



14
15
16
# File 'lib/gillbus/base_response.rb', line 14

def request_time
  @request_time
end

#session_idObject

Returns the value of attribute session_id.



9
10
11
# File 'lib/gillbus/base_response.rb', line 9

def session_id
  @session_id
end

Class Method Details

.parse(data, instance: new, options: {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gillbus/base_response.rb', line 22

def self.parse(data, instance: new, options: {})
  instance.raw_xml = options[:raw_xml] if options[:raw_xml]

  # ugly
  if data['MESSAGE']
    instance.error_code = data['MESSAGE']['CODE'].to_i
    instance.error_message = data['MESSAGE']['TEXT']
    instance.external_error_message = data['MESSAGE']['EXT_TEXT']
  else
    super(data, instance: instance, options: options)
  end
  # for debugging?
  instance.data = data
  instance
end

.parse_string(xml_string, **options) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/gillbus/base_response.rb', line 38

def self.parse_string(xml_string, **options)
  xml = Ox.load(xml_string, mode: :hash, symbolize_keys: false)
  # <DATA/> is a valid response
  return ParseError.new(xml_string, 'DATA attribute missing') unless xml.key?('DATA')
  data = xml['DATA'] || {}
  parse(data, instance: new, options: options.merge(raw_xml: xml_string))
rescue Ox::ParseError, ArgumentError => e
  ParseError.new(xml_string, e.message)
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/gillbus/base_response.rb', line 18

def error?
  !error_code.nil?
end