class HubriseClient::Response

Attributes

code[R]
data[R]
error_message[R]
error_type[R]
errors[R]
failed[R]
failed?[R]
http_response[R]

Public Class Methods

new(http_response) click to toggle source
# File lib/hubrise_client/response.rb, line 6
def initialize(http_response)
  @http_response  = http_response
  @code           = http_response.code

  json_body = begin
                JSON.parse(http_response.body)
              rescue StandardError
                nil
              end

  @data = json_body || http_response.body

  case http_response
  when Net::HTTPSuccess
    @failed  = false
  else
    @failed  = true
    if json_body
      @errors         = json_body["errors"]
      @error_type     = json_body["error_type"]
      @error_message  = json_body["message"]
    end
  end
end

Public Instance Methods

retry_after() click to toggle source
# File lib/hubrise_client/response.rb, line 31
def retry_after
  http_response.is_a?(Net::HTTPTooManyRequests) && http_response["retry-after"].to_i
end