class ErgastClient

Constants

BASE_URL

Public Class Methods

new(endpoint_path) click to toggle source
# File lib/ergast_f1/ergast_client.rb, line 4
def initialize(endpoint_path)
  # TODO: SUPPORT OTHER FORMATS BESIDES JSON
  @endpoint = BASE_URL + endpoint_path + ".json"
end

Public Instance Methods

api_get_request() click to toggle source
# File lib/ergast_f1/ergast_client.rb, line 9
def api_get_request
  c = Curl::Easy.new(@endpoint)
  c.connect_timeout = 60
  c.timeout = 300
  c.http_get()
  # TODO: ADD CONNECTION ERROR HANDLING
  return json_parse_response(c.body_str)
end

Private Instance Methods

json_parse_response(response) click to toggle source
# File lib/ergast_f1/ergast_client.rb, line 20
def json_parse_response(response)
  begin
    return JSON.parse(response)
  rescue JSON::ParserError
    return ApiError, "Error: invalid JSON reponse from ErgastF1 server"
  end
end