diff --git a/lib/thegamesdb.rb b/lib/thegamesdb.rb index 7037121..5ffb6b7 100644 --- a/lib/thegamesdb.rb +++ b/lib/thegamesdb.rb @@ -9,6 +9,7 @@ module Gamesdb IMAGES_BASE_URL = 'https://legacy.thegamesdb.net/banners/'.freeze # Method for listing platform's games + # TODO: check (and test) that we support ',' delimited list # https://api.thegamesdb.net/#/operations/Games/GamesByPlatformID # # Parameters: platform id (int), page (int) @@ -64,7 +65,7 @@ def self.platform_by_id(id) end # Method for getting game info - # TODO: name and platform parameters (for search) + # TODO: check (and test) that we support ',' delimited list # https://api.thegamesdb.net/#/operations/Games/GamesByGameID # # Parameters: @@ -92,17 +93,19 @@ def self.game_by_id(id) # Parameters: # - name (required) # - platform (optional - platform id) + # - page (optional) # # == Returns: # Hash with game info: id, name (not-unique), release_date, # platform, etc. # - def self.games_by_name(name, platform: nil) + def self.games_by_name(name, platform: nil, page: 1) url = 'Games/ByGameName' params = { fields: 'players,publishers,genres,overview,last_updated,rating,platform,coop,youtube,os,processor,ram,hdd,video,sound,alternates', include: 'boxart', - name: name + name: name, + page: page } unless platform.nil? params.merge!("filter[platform]" => platform) diff --git a/test/games_test.rb b/test/games_test.rb index fe5fe2c..cd82982 100644 --- a/test/games_test.rb +++ b/test/games_test.rb @@ -41,6 +41,24 @@ end end + describe 'games by name pages' do + before do + @first_page = Gamesdb.games_by_name('mario', page: 1) + @second_page = Gamesdb.games_by_name('mario', page: 2) + end + + it 'should return games in platform by id' do + @first_page.count.wont_be :<, 0 + @first_page.count.must_equal 20 + end + + it 'should return games in the platform for the second page' do + @second_page.count.wont_be :<, 0 + @second_page.count.must_equal 20 + (@first_page & @second_page).must_equal [] + end + end + describe 'games by name and platform' do before do @games_list = Gamesdb.games_by_name('mario', platform: 7) diff --git a/test/platform_test.rb b/test/platform_test.rb index 39b8b53..9e26236 100644 --- a/test/platform_test.rb +++ b/test/platform_test.rb @@ -39,7 +39,7 @@ end end - describe 'platform_games' do + describe 'platform_games pages' do before do platforms = Gamesdb.platforms @first_page = Gamesdb.games_by_platform_id(platforms[0][:id]) @@ -56,7 +56,6 @@ @second_page.count.must_equal 20 (@first_page & @second_page).must_equal [] end - end describe 'platform' do