Sha256: 91954ac72708735d1d24dc5c35fea74411f69636f73d2df1e01359dd58113412

Contents?: true

Size: 830 Bytes

Versions: 2

Compression:

Stored size: 830 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 = JSON.parse(@body) unless @body.is_a? Hash
        @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

2 entries across 2 versions & 1 rubygems

Version Path
huobi_client-0.1.2 lib/huobi_client/response.rb
huobi_client-0.1.1 lib/huobi_client/response.rb