Sha256: 856719587066570d207a1944f9e957aa23da57985bbad22e43fae2ae33128590

Contents?: true

Size: 761 Bytes

Versions: 4

Compression:

Stored size: 761 Bytes

Contents

module XEClient
  class BaseResponse

    include APIClientBase::Response.module
    attribute :raw_response
    attribute(:response_body, IndifferentHash, {
      lazy: true,
      default: :default_response_body,
    })
    attribute :code, Integer, lazy: true, default: :default_code
    attribute :message, String, lazy: true, default: :default_message
    attribute :error, Object, lazy: true, default: :default_error

    private

    def default_code
      response_body[:code]
    end

    def default_message
      response_body[:message]
    end

    def default_error
      Error.new_from_response(self)
    end

    def default_response_body
      JSON.parse(raw_response.body)
    end

    def default_success
      error.blank?
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
xe_client-1.1.1 lib/xe_client/responses/base_response.rb
xe_client-1.1.0 lib/xe_client/responses/base_response.rb
xe_client-1.0.1 lib/xe_client/responses/base_response.rb
xe_client-1.0.0 lib/xe_client/responses/base_response.rb