Sha256: efdeb50bbf8c77af76259ff5a789cabbde81d443328c48d82fd46d2e9b4bff2f
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
require 'multi_xml' class Gillbus class BaseResponse extend Fields include UpdateAttrs attr_accessor :data attr_accessor :session_id attr_accessor :error_code attr_accessor :error_message attr_accessor :external_error_message attr_accessor :request_time def error? !error_code.nil? end def self.parse(data, instance: new, options: {}) # 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 def self.parse_string(xml_string, **options) xml = MultiXml.parse(xml_string) # <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) rescue MultiXml::ParseError, ArgumentError => e ParseError.new(xml_string, e.message) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gillbus-0.17.6 | lib/gillbus/base_response.rb |