Sha256: 0d631364512c144832fac58596e0cb831832704715f07f5627d8d82c2765fece

Contents?: true

Size: 772 Bytes

Versions: 1

Compression:

Stored size: 772 Bytes

Contents

# encoding: utf-8

require 'active_support/core_ext/hash/keys'

module HuobiClient
  class Response
    SUCCESS_STATUS = [200, 201, 204]
    attr_reader :original_response, :body, :success

    def initialize(faraday_response)
      @original_response = faraday_response
      @body = faraday_response.body
      @success = false

      begin
        @body = @body.with_indifferent_access if @body.is_a? Hash
      rescue => e
        p e.message
        p e.backtrace.join("\n")
      end

      if SUCCESS_STATUS.include? original_response.status
        @success = @body[:status] == 'ok'
      end
    end

    def success?
      @success
    end

    def headers
      original_response.headers
    end

    def status
      original_response.status
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
huobi_client-0.1.0 lib/huobi_client/response.rb