class Gillbus::BaseResponse

Attributes

data[RW]
error_code[RW]
error_message[RW]
external_error_message[RW]
raw_xml[RW]
request_time[RW]
session_id[RW]

Public Class Methods

parse(data, instance: new, options: {}) click to toggle source
Calls superclass method
# 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) click to toggle source
# 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

Public Instance Methods

error?() click to toggle source
# File lib/gillbus/base_response.rb, line 18
def error?
  !error_code.nil?
end