Sha256: 8684bc7391b0377dfa3c54996e49a22d6661fe87241395a4d21e0866f78875e2

Contents?: true

Size: 906 Bytes

Versions: 4

Compression:

Stored size: 906 Bytes

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

    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"]
      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

4 entries across 4 versions & 1 rubygems

Version Path
gillbus-0.14.10 lib/gillbus/base_response.rb
gillbus-0.14.9 lib/gillbus/base_response.rb
gillbus-0.14.8 lib/gillbus/base_response.rb
gillbus-0.14.7 lib/gillbus/base_response.rb