Module: XIVAPI::HTTP
Overview
Makes HTTP request to XIVAPI
Constant Summary collapse
- API_BASE =
Base URL for XIVAPI
'https://xivapi.com'.freeze
- STAGING_API_BASE =
Base URL for the staging environment of XIVAPI
'https://staging.xivapi.com'.freeze
Instance Method Summary collapse
-
#request(client, endpoint, params = {}, payload = nil) ⇒ Object
Makes a request to XIVAPI.
Instance Method Details
#request(client, endpoint, params = {}, payload = nil) ⇒ Object
Makes a request to XIVAPI
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/xivapi/http.rb', line 16 def request(client, endpoint, params = {}, payload = nil) url = request_url(client, endpoint) query_params = params.merge(client.default_params) .reject { |_, v| v.nil? || v.size == 0 } begin if payload response = RestClient::Request.execute(method: :get, url: url, headers: { params: query_params }, payload: payload.to_json) else response = RestClient.get(url, params: query_params) end body = JSON.parse(response.body) objectify(body) rescue RestClient::ExceptionWithResponse => e if e.http_code == 429 raise XIVAPI::RateLimitError.new else raise XIVAPI::RequestError.new(e.response) end rescue RestClient::Exception => e raise e end end |