Sha256: 78b6a4e1a715227fe698c8687833a2dd868df61b19755dc87e858b694e67a505

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 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)
      # 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)
      end
      # for debugging?
      instance.data = data
      instance
    end

    def self.parse_string(xml_string)
      xml = MultiXml.parse(xml_string)
      # <DATA/> is a valid response
      xml.key?("DATA") or return ParseError.new(xml_string)
      data = xml["DATA"] || {}
      parse(data)
    rescue MultiXml::ParseError, ArgumentError
      ParseError.new(xml_string)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gillbus-0.16.7 lib/gillbus/base_response.rb
gillbus-0.16.6 lib/gillbus/base_response.rb
gillbus-0.16.5 lib/gillbus/base_response.rb