Class: RAWG::Client
- Inherits:
-
Object
- Object
- RAWG::Client
- Defined in:
- lib/rawg/client.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #all_games(options = {}) ⇒ Object
- #all_users(options = {}) ⇒ Object
- #game(game) ⇒ Object
- #game_info(game) ⇒ Object
- #game_reviews(game, options = {}) ⇒ Object
- #game_suggest(game, options = {}) ⇒ Object
- #games(options = {}) ⇒ Object
- #get(path, query = {}) ⇒ Object
-
#initialize(user_agent: nil) ⇒ Client
constructor
A new instance of Client.
- #search_games(query, options = {}) ⇒ Object
- #search_users(query, options = {}) ⇒ Object
- #user_games(user, options = {}) ⇒ Object
- #user_info(user) ⇒ Object
- #user_reviews(user, options = {}) ⇒ Object
Constructor Details
#initialize(user_agent: nil) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/rawg/client.rb', line 13 def initialize(user_agent: nil) @user_agent = combine_user_agents(user_agent, DEFAULT_USER_AGENT) @http_client = default_http_client end |
Instance Attribute Details
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
11 12 13 |
# File 'lib/rawg/client.rb', line 11 def user_agent @user_agent end |
Instance Method Details
#all_games(options = {}) ⇒ Object
26 27 28 |
# File 'lib/rawg/client.rb', line 26 def all_games( = {}) get('/api/games', ) end |
#all_users(options = {}) ⇒ Object
30 31 32 |
# File 'lib/rawg/client.rb', line 30 def all_users( = {}) get('/api/users', ) end |
#game(game) ⇒ Object
66 67 68 69 |
# File 'lib/rawg/client.rb', line 66 def game(game) response = game_info(game) RAWG::Game.new(client: self).from_api_response(response) end |
#game_info(game) ⇒ Object
42 43 44 |
# File 'lib/rawg/client.rb', line 42 def game_info(game) get("/api/games/#{game}") end |
#game_reviews(game, options = {}) ⇒ Object
50 51 52 |
# File 'lib/rawg/client.rb', line 50 def game_reviews(game, = {}) get("/api/games/#{game}/reviews", ) end |
#game_suggest(game, options = {}) ⇒ Object
46 47 48 |
# File 'lib/rawg/client.rb', line 46 def game_suggest(game, = {}) get("/api/games/#{game}/suggested", ) end |
#games(options = {}) ⇒ Object
71 72 73 74 |
# File 'lib/rawg/client.rb', line 71 def games( = {}) response = all_games() RAWG::Collection.new(RAWG::Game, client: self).from_api_response(response) end |
#get(path, query = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rawg/client.rb', line 18 def get(path, query = {}) response = @http_client.get(path, format_query(query)).body return nil unless response.is_a?(Hash) return nil if response[:detail] == 'Not found.' response end |
#search_games(query, options = {}) ⇒ Object
34 35 36 |
# File 'lib/rawg/client.rb', line 34 def search_games(query, = {}) all_games(search: query, **) end |
#search_users(query, options = {}) ⇒ Object
38 39 40 |
# File 'lib/rawg/client.rb', line 38 def search_users(query, = {}) all_users(search: query, **) end |
#user_games(user, options = {}) ⇒ Object
58 59 60 |
# File 'lib/rawg/client.rb', line 58 def user_games(user, = {}) get("/api/users/#{user}/games", ) end |
#user_info(user) ⇒ Object
54 55 56 |
# File 'lib/rawg/client.rb', line 54 def user_info(user) get("/api/users/#{user}") end |
#user_reviews(user, options = {}) ⇒ Object
62 63 64 |
# File 'lib/rawg/client.rb', line 62 def user_reviews(user, = {}) get("/api/users/#{user}/reviews", ) end |