Skip to content

Commit

Permalink
Add extra fields to Platforms request
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Sep 7, 2019
1 parent 0a57398 commit c44473a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 4 additions & 6 deletions lib/thegamesdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions test/platform_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit c44473a

Please sign in to comment.