module Locked::API::Response

parses api response

Constants

RESPONSE_ERRORS

Public Class Methods

call(response) click to toggle source
# File lib/locked/api/response.rb, line 17
def call(response)
  verify!(response)

  return {} if response.body.nil? || response.body.empty?

  begin
    JSON.parse(response.body, symbolize_names: true)
  rescue JSON::ParserError
    raise Locked::ApiError, 'Invalid response from Locked API'
  end
end
verify!(response) click to toggle source
# File lib/locked/api/response.rb, line 29
def verify!(response)
  return if response.code.to_i.between?(200, 299)

  raise Locked::InternalServerError if response.code.to_i.between?(500, 599)

  error = RESPONSE_ERRORS.fetch(response.code.to_i, Locked::ApiError)
  raise error, response[:message]
end