class Eezee::Response

Attributes

original[R]

Public Class Methods

new(original) click to toggle source
# File lib/eezee/response.rb, line 10
def initialize(original)
  @original = original
end

Public Instance Methods

body() click to toggle source
# File lib/eezee/response.rb, line 14
def body
  return {} if timeout?

  @body ||= parsed_body
end
code() click to toggle source
# File lib/eezee/response.rb, line 26
def code
  return if timeout?

  @code ||= success_response? ? @original.status : @original.response[:status]
end
log() click to toggle source
# File lib/eezee/response.rb, line 38
def log
  Eezee::Logger.response(self)
end
success?() click to toggle source
# File lib/eezee/response.rb, line 20
def success?
  return false if timeout?

  @success ||= success_response? && @original&.success?
end
timeout?() click to toggle source
# File lib/eezee/response.rb, line 32
def timeout?
  @original.is_a?(Faraday::TimeoutError) ||
    @original.is_a?(Net::ReadTimeout)    ||
    @original.is_a?(Faraday::ConnectionFailed)
end

Private Instance Methods

faraday_response() click to toggle source
# File lib/eezee/response.rb, line 58
def faraday_response
  success_response? ? @original.body : @original.response[:body]
end
handled_faraday_response() click to toggle source
# File lib/eezee/response.rb, line 54
def handled_faraday_response
  faraday_response.nil? || faraday_response.empty? ? '{}' : faraday_response
end
parsed_body() click to toggle source
# File lib/eezee/response.rb, line 44
def parsed_body
  JSON.parse(handled_faraday_response, symbolize_names: true)
rescue StandardError
  { response: faraday_response }
end
success_response?() click to toggle source
# File lib/eezee/response.rb, line 50
def success_response?
  @original.is_a?(Faraday::Response)
end