Class: Gamesdb::Client
- Inherits:
-
Object
- Object
- Gamesdb::Client
- Includes:
- Developers, Games, Genres, Platforms, Publishers
- Defined in:
- lib/thegamesdb.rb
Overview
Client for TheGamesDB API (thegamesdb.net)
Constant Summary collapse
- BASE_URL =
'https://api.thegamesdb.net/v1/'
- IMAGES_BASE_URL =
'https://legacy.thegamesdb.net/banners/'
Instance Attribute Summary collapse
-
#allowance_refresh_timer ⇒ Object
readonly
Returns the value of attribute allowance_refresh_timer.
-
#extra_allowance ⇒ Object
readonly
Returns the value of attribute extra_allowance.
-
#remaining_monthly_allowance ⇒ Object
readonly
Returns the value of attribute remaining_monthly_allowance.
Instance Method Summary collapse
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
-
#perform_request(url, params = {}) ⇒ Hash
Perform request.
Methods included from Publishers
Methods included from Platforms
#platform_api_response, #platform_images, #platforms, #platforms_by_id, #platforms_by_name
Methods included from Genres
Methods included from Games
#games_by_id, #games_by_name, #games_by_platform_id, #games_images, #games_update
Methods included from Developers
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
28 29 30 |
# File 'lib/thegamesdb.rb', line 28 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#allowance_refresh_timer ⇒ Object (readonly)
Returns the value of attribute allowance_refresh_timer.
26 27 28 |
# File 'lib/thegamesdb.rb', line 26 def allowance_refresh_timer @allowance_refresh_timer end |
#extra_allowance ⇒ Object (readonly)
Returns the value of attribute extra_allowance.
26 27 28 |
# File 'lib/thegamesdb.rb', line 26 def extra_allowance @extra_allowance end |
#remaining_monthly_allowance ⇒ Object (readonly)
Returns the value of attribute remaining_monthly_allowance.
26 27 28 |
# File 'lib/thegamesdb.rb', line 26 def remaining_monthly_allowance @remaining_monthly_allowance end |
Instance Method Details
#perform_request(url, params = {}) ⇒ Hash
Perform request
Used by every API endpoint, but can also be used manually.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/thegamesdb.rb', line 40 def perform_request(url, params = {}) raise ArgumentError, 'You need to set the API KEY to use the GamesDB API' unless @api_key uri = prepare_uri(params, url) response = Net::HTTP.get_response(uri) check_http_errors(response) json_response = JSON.parse(response.body) refresh_allowances(json_response) json_response rescue StandardError => e raise e end |