Class: Agent
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#game(id) ⇒ Object
get a game based on its unique GiantBomb id.
-
#initialize(key) ⇒ Agent
constructor
pass in your API key generated from the GiantBomb sign up.
-
#platform(id) ⇒ Object
Search for info about a platform, based on its name.
-
#platform_games(platform_id) ⇒ Object
get the 20 most popular games from the platform of choice.
-
#platform_id_hash ⇒ Object
Create a relationship between platform name and its unique GiantBomb id.
- #platform_id_hash2 ⇒ Object
-
#platforms ⇒ Object
get a list of platforms.
- #second_platforms ⇒ Object
Constructor Details
#initialize(key) ⇒ Agent
pass in your API key generated from the GiantBomb sign up
11 12 13 14 |
# File 'lib/giant-bomber.rb', line 11 def initialize(key) @key = key @accept = "application/json" end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
7 8 9 |
# File 'lib/giant-bomber.rb', line 7 def key @key end |
Instance Method Details
#game(id) ⇒ Object
get a game based on its unique GiantBomb id
17 18 19 |
# File 'lib/giant-bomber.rb', line 17 def game(id) self.class.get("/game/#{id}/?api_key=#{@key}&format=json&field_list=name,deck,description,genres,image")["results"] end |
#platform(id) ⇒ Object
Search for info about a platform, based on its name
31 32 33 |
# File 'lib/giant-bomber.rb', line 31 def platform(id) self.class.get("/platform/#{id}/?api_key=#{@key}&format=json&field_list=name,description,deck,release_date,image")["results"] end |
#platform_games(platform_id) ⇒ Object
get the 20 most popular games from the platform of choice
57 58 59 |
# File 'lib/giant-bomber.rb', line 57 def platform_games(platform_id) self.class.get("/games/?api_key=#{@key}&format=json&platforms=#{platform_id.to_i}&field_list=name,deck,image,id,original_release_date&sort=number_of_user_reviews:desc&limit=21")["results"] end |
#platform_id_hash ⇒ Object
Create a relationship between platform name and its unique GiantBomb id
36 37 38 39 40 41 42 43 44 |
# File 'lib/giant-bomber.rb', line 36 def platform_id_hash list = platforms platform_hash = Hash.new list.each do |platform| platform_hash[platform["name"]] = platform["id"] end platform_hash end |
#platform_id_hash2 ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/giant-bomber.rb', line 46 def platform_id_hash2 list = second_platforms platform_hash = Hash.new list.each do |platform| platform_hash[platform["name"]] = platform["id"] end platform_hash end |
#platforms ⇒ Object
get a list of platforms
22 23 24 |
# File 'lib/giant-bomber.rb', line 22 def platforms self.class.get("/platforms/?api_key=#{@key}&format=json&field_list=name,id")["results"] end |
#second_platforms ⇒ Object
26 27 28 |
# File 'lib/giant-bomber.rb', line 26 def second_platforms self.class.get("/platforms/?api_key=#{@key}&format=json&field_list=name,id&offset=100")["results"] end |