Skip to content

Commit

Permalink
Adds page parameter to games_by_name
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Sep 11, 2019
1 parent 5635428 commit cce2c2a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/thegamesdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions test/games_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions test/platform_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -56,7 +56,6 @@
@second_page.count.must_equal 20
(@first_page & @second_page).must_equal []
end

end

describe 'platform' do
Expand Down

0 comments on commit cce2c2a

Please sign in to comment.