thegamesdb 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/thegamesdb.rb +25 -37
- data/lib/thegamesdb/version.rb +1 -1
- data/test/platform_test.rb +30 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09c223ffcdbfefc714627f7673aac31836b8d20f76f4aa51f5cdb583ed4aaef6'
|
4
|
+
data.tar.gz: 692abf6425da4f35d557fb3dba738b14584680822baf0d21dcf0ccd777045e44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a64df3a9904963cac3782dd221eca0e77ece3af43a08fc84e098dd21eb24abc1211dda4b49fec7fe50422117b102c8329df8ed4f8646c7da5bd3292e7ca6bfc3
|
7
|
+
data.tar.gz: a141723f13ae4fc5fcfc597fd27def6f2a79eaf9a32e0ad6ecab8c9705af14deea7960857443dae3c084e9bafaba27ad2212a8770292febf4cddc0e010f254c6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.1.0
|
4
|
+
* Adds `page` parameter to `games_by_platform_id` and includes `boxart`.
|
5
|
+
* Adds all available fields from Platforms in `platforms`, updates tests. Changes `:slug` to `:alias` in platforms response, to map to same response from API.
|
6
|
+
* Refactored `json_response` to use `includes` and extra data from the API response.
|
7
|
+
|
8
|
+
|
3
9
|
## 1.0.0
|
4
10
|
|
5
11
|
* Updated to new API endpoint, API key is now required to use the gem. Request an API Key here: https://forums.thegamesdb.net/viewforum.php?f=10
|
data/lib/thegamesdb.rb
CHANGED
@@ -11,14 +11,15 @@ module Gamesdb
|
|
11
11
|
# Method for listing platform's games
|
12
12
|
# https://api.thegamesdb.net/#/operations/Games/GamesByPlatformID
|
13
13
|
#
|
14
|
-
# Parameters: platform id (int)
|
14
|
+
# Parameters: platform id (int), page (int)
|
15
15
|
#
|
16
16
|
# == Returns:
|
17
17
|
# Array of Hashes with games info
|
18
18
|
#
|
19
|
-
def self.games_by_platform_id(platform_id)
|
19
|
+
def self.games_by_platform_id(platform_id, page = 1)
|
20
20
|
url = 'Games/ByPlatformID'
|
21
|
-
|
21
|
+
params = {id: platform_id, page: page, include: 'boxart'}
|
22
|
+
data = json_response(url, params)
|
22
23
|
process_platform_games(data)
|
23
24
|
end
|
24
25
|
|
@@ -32,14 +33,12 @@ module Gamesdb
|
|
32
33
|
#
|
33
34
|
def self.platforms
|
34
35
|
url = 'Platforms'
|
35
|
-
|
36
|
-
|
36
|
+
params = { fields: 'icon,console,controller,developer,manufacturer,media,cpu,memory,graphics,sound,maxcontrollers,display,overview,youtube' }
|
37
|
+
data = json_response(url, params)
|
37
38
|
|
38
|
-
data['platforms'].
|
39
|
-
|
40
|
-
platforms << { name: platform['name'], id: platform['id'].to_i, slug: platform['alias'] }
|
39
|
+
data['data']['platforms'].map do |p|
|
40
|
+
symbolize_keys(p.last)
|
41
41
|
end
|
42
|
-
platforms
|
43
42
|
end
|
44
43
|
|
45
44
|
# This API feature returns a set of metadata and artwork data for a
|
@@ -60,7 +59,7 @@ module Gamesdb
|
|
60
59
|
}
|
61
60
|
data = json_response(url, params)
|
62
61
|
|
63
|
-
response = data['platforms'].values.first
|
62
|
+
response = data['data']['platforms'].values.first
|
64
63
|
symbolize_keys(response)
|
65
64
|
end
|
66
65
|
|
@@ -82,8 +81,8 @@ module Gamesdb
|
|
82
81
|
include: 'boxart,platform'
|
83
82
|
}
|
84
83
|
data = json_response(url, params)
|
85
|
-
return [] if data[
|
86
|
-
symbolize_keys(data['games'].first)
|
84
|
+
return [] if data['data']['count'] == 0
|
85
|
+
symbolize_keys(data['data']['games'].first)
|
87
86
|
end
|
88
87
|
|
89
88
|
# The GetGamesList API search returns a listing of games matched up
|
@@ -100,7 +99,7 @@ module Gamesdb
|
|
100
99
|
def self.games_by_name(name)
|
101
100
|
url = 'Games/ByGameName'
|
102
101
|
data = json_response(url, name: name)
|
103
|
-
data['games'].map { |game| symbolize_keys(game) }
|
102
|
+
data['data']['games'].map { |game| symbolize_keys(game) }
|
104
103
|
end
|
105
104
|
|
106
105
|
# This API feature returns a list of available artwork types and
|
@@ -120,14 +119,14 @@ module Gamesdb
|
|
120
119
|
def self.game_images(id)
|
121
120
|
url = 'Games/Images'
|
122
121
|
data = json_response(url, games_id: id)
|
123
|
-
return [] if data['count'] == 0
|
122
|
+
return [] if data['data']['count'] == 0
|
124
123
|
|
125
124
|
response = {}
|
126
|
-
response[:base_url] = data['base_url']['original']
|
127
|
-
response[:logo] = process_logo(data, id)
|
128
|
-
response[:boxart] = process_covers(data, id)
|
129
|
-
response[:screenshot] = process_screenshots(data, id)
|
130
|
-
response[:fanart] = process_fanart(data, id)
|
125
|
+
response[:base_url] = data['data']['base_url']['original']
|
126
|
+
response[:logo] = process_logo(data['data'], id)
|
127
|
+
response[:boxart] = process_covers(data['data'], id)
|
128
|
+
response[:screenshot] = process_screenshots(data['data'], id)
|
129
|
+
response[:fanart] = process_fanart(data['data'], id)
|
131
130
|
response
|
132
131
|
end
|
133
132
|
|
@@ -192,19 +191,23 @@ module Gamesdb
|
|
192
191
|
uri.query = URI.encode_www_form(params)
|
193
192
|
request = Net::HTTP.get_response(uri)
|
194
193
|
response = JSON.parse(request.body)
|
195
|
-
response
|
194
|
+
response
|
196
195
|
end
|
197
196
|
|
198
197
|
# Process games for platform_games
|
199
198
|
def self.process_platform_games(data)
|
200
199
|
games = []
|
201
200
|
|
202
|
-
data['games'].each do |elem|
|
201
|
+
data['data']['games'].each do |elem|
|
203
202
|
name = elem['game_title']
|
204
203
|
id = elem['id']
|
205
204
|
date = elem['release_date']
|
206
205
|
developers = elem['developers']
|
207
|
-
|
206
|
+
if boxart = data.dig('include', 'boxart', 'data', id.to_s)
|
207
|
+
image = data['include']['boxart']['base_url']['original'] +
|
208
|
+
boxart.select { |a| a['side'] == 'front' }.first['filename'] || ''
|
209
|
+
end
|
210
|
+
games << { name: name, id: id, release_date: date, developers: developers, image: image }
|
208
211
|
end
|
209
212
|
games
|
210
213
|
end
|
@@ -217,21 +220,6 @@ module Gamesdb
|
|
217
220
|
game
|
218
221
|
end
|
219
222
|
|
220
|
-
# Method for processing the fan art and screenshots into a uniform
|
221
|
-
# collection with url, width, height and thumb url
|
222
|
-
def self.images_from_nodes(data)
|
223
|
-
images = []
|
224
|
-
data.each do |art|
|
225
|
-
images << {
|
226
|
-
url: art.original.nodes[0],
|
227
|
-
width: art.nodes.first.attributes[:width],
|
228
|
-
height: art.nodes.first.attributes[:height],
|
229
|
-
thumb: art.thumb.text
|
230
|
-
}
|
231
|
-
end
|
232
|
-
images
|
233
|
-
end
|
234
|
-
|
235
223
|
def self.symbolize_keys(hash)
|
236
224
|
hash.keys.each do |key|
|
237
225
|
hash[key.to_sym] = hash.delete(key)
|
data/lib/thegamesdb/version.rb
CHANGED
data/test/platform_test.rb
CHANGED
@@ -8,6 +8,7 @@ describe 'GamesDB - platforms', :vcr do
|
|
8
8
|
|
9
9
|
it 'should get gaming platforms' do
|
10
10
|
@platforms.count.wont_be :<, 0
|
11
|
+
@platforms.count.must_equal 109
|
11
12
|
end
|
12
13
|
|
13
14
|
it 'should have a valid name' do
|
@@ -18,26 +19,50 @@ describe 'GamesDB - platforms', :vcr do
|
|
18
19
|
@platforms[0][:id].must_be_kind_of Integer
|
19
20
|
end
|
20
21
|
|
21
|
-
it 'should have a valid
|
22
|
-
@platforms[0][:
|
22
|
+
it 'should have a valid alias' do
|
23
|
+
@platforms[0][:alias].must_be_kind_of String
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should have valid fields for other stuff' do
|
27
|
+
nes = @platforms.select { |p| p[:id] == 7 }.first
|
28
|
+
nes[:icon].must_be_kind_of String
|
29
|
+
nes[:console].must_be_kind_of String
|
30
|
+
nes[:controller].must_be_kind_of String
|
31
|
+
nes[:developer].must_be_kind_of String
|
32
|
+
nes[:manufacturer].must_be_kind_of String
|
33
|
+
nes[:maxcontrollers].must_be_kind_of String
|
34
|
+
nes[:cpu].must_be_kind_of String
|
35
|
+
nes[:memory].must_be_kind_of String
|
36
|
+
nes[:sound].must_be_kind_of String
|
37
|
+
nes[:display].must_be_kind_of String
|
38
|
+
nes[:overview].must_be_kind_of String
|
23
39
|
end
|
24
40
|
end
|
25
41
|
|
26
42
|
describe 'platform_games' do
|
27
43
|
before do
|
28
44
|
platforms = Gamesdb.platforms
|
29
|
-
@
|
45
|
+
@first_page = Gamesdb.games_by_platform_id(platforms[0][:id])
|
46
|
+
@second_page = Gamesdb.games_by_platform_id(platforms[0][:id], 2)
|
30
47
|
end
|
31
48
|
|
32
49
|
it 'should return games in platform by id' do
|
33
|
-
@
|
50
|
+
@first_page.count.wont_be :<, 0
|
51
|
+
@first_page.count.must_equal 20
|
34
52
|
end
|
53
|
+
|
54
|
+
it 'should return games in the platform for the second page' do
|
55
|
+
@second_page.count.wont_be :<, 0
|
56
|
+
@second_page.count.must_equal 20
|
57
|
+
(@first_page & @second_page).must_equal []
|
58
|
+
end
|
59
|
+
|
35
60
|
end
|
36
61
|
|
37
62
|
describe 'platform' do
|
38
63
|
describe 'assigning basic info' do
|
39
64
|
before do
|
40
|
-
@platform = Gamesdb.platform_by_id
|
65
|
+
@platform = Gamesdb.platform_by_id(6)
|
41
66
|
end
|
42
67
|
|
43
68
|
it 'should return valid platform info' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thegamesdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Briano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
|
-
rubygems_version: 3.0.
|
165
|
+
rubygems_version: 3.0.6
|
166
166
|
signing_key:
|
167
167
|
specification_version: 4
|
168
168
|
summary: Client for TheGamesDB API (thegamesdb.net).
|