From c44473a380bebb637d220ed1f42953249bc3fcfe Mon Sep 17 00:00:00 2001 From: Fernando Briano Date: Sat, 7 Sep 2019 20:21:31 +0100 Subject: [PATCH] Add extra fields to Platforms request --- lib/thegamesdb.rb | 10 ++++------ test/platform_test.rb | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/thegamesdb.rb b/lib/thegamesdb.rb index 773a5c3..afc319f 100644 --- a/lib/thegamesdb.rb +++ b/lib/thegamesdb.rb @@ -33,14 +33,12 @@ def self.games_by_platform_id(platform_id, page = 1) # def self.platforms url = 'Platforms' - data = json_response(url) - platforms = [] + params = { fields: 'icon,console,controller,developer,manufacturer,media,cpu,memory,graphics,sound,maxcontrollers,display,overview,youtube' } + data = json_response(url, params) - data['data']['platforms'].each do |p| - platform = p.last - platforms << { name: platform['name'], id: platform['id'].to_i, slug: platform['alias'] } + data['data']['platforms'].map do |p| + symbolize_keys(p.last) end - platforms end # This API feature returns a set of metadata and artwork data for a diff --git a/test/platform_test.rb b/test/platform_test.rb index 8ef5070..0643068 100644 --- a/test/platform_test.rb +++ b/test/platform_test.rb @@ -8,6 +8,7 @@ it 'should get gaming platforms' do @platforms.count.wont_be :<, 0 + @platforms.count.must_equal 109 end it 'should have a valid name' do @@ -18,8 +19,23 @@ @platforms[0][:id].must_be_kind_of Integer end - it 'should have a valid slug' do - @platforms[0][:slug].must_be_kind_of String + it 'should have a valid alias' do + @platforms[0][:alias].must_be_kind_of String + end + + it 'should have valid fields for other stuff' do + nes = @platforms.select { |p| p[:id] == 7 }.first + nes[:icon].must_be_kind_of String + nes[:console].must_be_kind_of String + nes[:controller].must_be_kind_of String + nes[:developer].must_be_kind_of String + nes[:manufacturer].must_be_kind_of String + nes[:maxcontrollers].must_be_kind_of String + nes[:cpu].must_be_kind_of String + nes[:memory].must_be_kind_of String + nes[:sound].must_be_kind_of String + nes[:display].must_be_kind_of String + nes[:overview].must_be_kind_of String end end