class BikeReg::Resource

Attributes

client[R]

Public Class Methods

new(client) click to toggle source
# File lib/bike_reg/resource.rb, line 7
def initialize(client)
  @client = client
end

Private Instance Methods

get_request(url, params: {}, headers: {}) click to toggle source
# File lib/bike_reg/resource.rb, line 13
def get_request(url, params: {}, headers: {})
  handle_response client.connection.get(url, params, headers)
end
handle_response(response) click to toggle source

rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength

# File lib/bike_reg/resource.rb, line 18
   def handle_response(response)
     case response.status
     when 400
       raise Error, "Your request was malformed. #{response.body['error']}"
     when 401
       raise Error, "You did not supply valid authentication credentials. #{response.body['error']}"
     when 403
       raise Error, "You are not allowed to perform that action. #{response.body['error']}"
     when 404
       raise Error, "No results were found for your request. #{response.body['error']}"
     when 429
       raise Error, "Your request exceeded the API rate limit. #{response.body['error']}"
     when 500
       raise Error, "We were unable to perform the request due to server-side problems. #{response.body['error']}"
     when 503
       raise Error,
             "The server is currently unable to handle the request due to a temporary overloading or maintenance of the
server. #{response.body['error']}"
     end

     response
   end