Class: GiantBomb::Search

Inherits:
Object show all
Includes:
HTTParty
Defined in:
lib/giant_bomb/search.rb

Instance Method Summary collapse

Constructor Details

#initialize(the_api_key) ⇒ Search

Returns a new instance of Search.



8
9
10
# File 'lib/giant_bomb/search.rb', line 8

def initialize(the_api_key)
  @api_key = the_api_key
end

Instance Method Details

#default_query_optionsObject



12
13
14
# File 'lib/giant_bomb/search.rb', line 12

def default_query_options
  {"api_key" => @api_key, "format" => 'json'}
end

#find_game(keywords) ⇒ Object



18
19
20
21
22
23
# File 'lib/giant_bomb/search.rb', line 18

def find_game(keywords)
  options = {"query" => keywords, "resources" => "game"}
  options.merge!(default_query_options)
  response = self.class.get("/search", :query => options)
  response["results"].collect{|r| Game.new(r, self)}
end

#get_game(game_id) ⇒ Object



33
34
35
36
37
38
# File 'lib/giant_bomb/search.rb', line 33

def get_game(game_id)
  response = self.class.get("/game/#{game_id}/", :query => default_query_options)
  game = Game.new(response["results"], self)
  game.loaded = true
  game
end

#get_game_info(game_id) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/giant_bomb/search.rb', line 25

def get_game_info(game_id)
  field_list = %w{developers genres images publishers}
  options = {"field_list" => field_list.join(',')}
  options.merge!(default_query_options)
  response = self.class.get("/game/#{game_id}/", :query => options)
  Game.new(response["results"], self)
end