class Eol::Response

Constants

ERROR_CODES
SUCCESS_CODES
UNAUTHORIZED_CODES

Attributes

body[W]
response[RW]
status_code[RW]

Public Class Methods

new(response) click to toggle source
# File lib/eol/response.rb, line 11
def initialize(response)
  @response = response
  raise_and_log_error if fail?
end

Public Instance Methods

body() click to toggle source
# File lib/eol/response.rb, line 20
def body
  @response.body
end
error_message() click to toggle source
# File lib/eol/response.rb, line 44
def error_message
  parsed.error_message
end
fail?() click to toggle source
# File lib/eol/response.rb, line 40
def fail?
  ERROR_CODES.include? status
end
log_error() click to toggle source
# File lib/eol/response.rb, line 48
def log_error
  message = "An error occured, the response had status #{status}. The content of the error was: #{error_message}"
  Eol.error(message)
end
parsed() click to toggle source
# File lib/eol/response.rb, line 24
def parsed
  Parser.new(body)
end
result() click to toggle source
# File lib/eol/response.rb, line 28
def result
  Eol::ResultSet.new(parsed)
end
results() click to toggle source
# File lib/eol/response.rb, line 32
def results
  Eol::ResultSet.new(parsed)
end
status() click to toggle source
# File lib/eol/response.rb, line 36
def status
  @response.status
end
success?() click to toggle source
# File lib/eol/response.rb, line 16
def success?
  @response.success? || SUCCESS_CODES.include?(status)
end

Private Instance Methods

raise_and_log_error() click to toggle source
# File lib/eol/response.rb, line 67
def raise_and_log_error
  log_error
  raise BadRequestException.new(@response, parsed)
end