class CoinMarketPro::Client::Result

Status object to capture result from an HTTP request

Gives callers context of the result and allows them to implement successful strategies to handle success/failure

Attributes

body[RW]
code[R]
headers[R]
raw[R]
status[R]

Public Class Methods

failed(response) click to toggle source
# File lib/coin_market_pro/client/result.rb, line 16
def self.failed(response)
  new(:failed, response)
end
new(status, response) click to toggle source
# File lib/coin_market_pro/client/result.rb, line 23
def initialize(status, response)
  @raw = raw_parse(response.body)
  @status = @raw[:status]&.merge(result: status) || { result: status }
  @code = response.code
  @body = @raw[:data]
  @headers = response.headers # e.g. "Content-Type" will become :content_type.
end
success(response) click to toggle source
# File lib/coin_market_pro/client/result.rb, line 12
def self.success(response)
  new(:success, response)
end

Public Instance Methods

failure?() click to toggle source
# File lib/coin_market_pro/client/result.rb, line 35
def failure?
  @status[:result] == :failed
end
method_missing(method, *args, &blk) click to toggle source
# File lib/coin_market_pro/client/result.rb, line 45
def method_missing(method, *args, &blk)
  to_h.send(method, *args, &blk)
end
raw_parse(body) click to toggle source

@param body [JSON] Raw JSON body

# File lib/coin_market_pro/client/result.rb, line 54
def raw_parse(body)
  JSON.parse(body, symbolize_names: true)
rescue StandardError => e
  raise ResponseBodyParseError.new(error: 'JSON parse error', message: e.message, body: body)
end
respond_to_missing?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/coin_market_pro/client/result.rb, line 49
def respond_to_missing?(method, include_private = false)
  to_h.respond_to?(method) || super
end
success?() click to toggle source
# File lib/coin_market_pro/client/result.rb, line 31
def success?
  @status[:result] == :success
end
to_h() click to toggle source
# File lib/coin_market_pro/client/result.rb, line 39
def to_h
  { status: @status, code: @code, headers: @headers, body: @body }
end
Also aliased as: to_hash
to_hash()
Alias for: to_h