Module: TriviaCrack::API::Common

Included in:
Game, Login, Profile, Question, User
Defined in:
lib/triviacrack/api/common.rb

Instance Method Summary collapse

Instance Method Details

#get(url, parameters: nil) ⇒ Object

Internal: Makes a GET request to the Trivia Crack API using the set of default headers.

url - The URL of the TriviaCrack API resource. parameters - The parameters to send with the request.

Returns a Faraday Response object with the server’s response. Raises TriviaCrack:Errors::RequestError if the request fails.



19
20
21
22
23
# File 'lib/triviacrack/api/common.rb', line 19

def get(url, parameters: nil)
  response = Faraday.get "#{API_HOST}#{url}", parameters, default_headers

  check_response url, response
end

#post(url, parameters: nil) ⇒ Object

Internal: Makes a POST request to the Trivia Crack API using the set of default headers.

url - The URL of the TriviaCrack API resource. parameters - The parameters to send with the request.

Returns a Faraday Response object with the server’s response. Raises TriviaCrack:Errors::RequestError if the request fails.



33
34
35
36
37
# File 'lib/triviacrack/api/common.rb', line 33

def post(url, parameters: nil)
  response = Faraday.post "#{API_HOST}#{url}", parameters, default_headers

  check_response url, response
end