thegamesdb 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ff4b1c3cbe0040265ddcab2536c1bfc342ced4c
4
+ data.tar.gz: 82272c0cc89471e58d58281ed46226094279cf48
5
+ SHA512:
6
+ metadata.gz: 64027ae70c35fd6f80a5954e71c61be96b07626207535f52f87558bb14f09759cf076dbc95ede14eafd3f0b2f97a344eaefaf6cceda512c46bba0531b71d3da9
7
+ data.tar.gz: 7cf6f23330b516df6d88f89a84033067f2ef1117d69cd77b21bae0439048aa137f4634355dc1d720345233338febda170f45a0de37185b0b9698f045bbf2381c
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ test/fixtures/vcr_cassettes/*
19
+ .byebug_history
20
+ test/reports
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gamesdb.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Fernando Briano
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,221 @@
1
+ # Gamesdb
2
+
3
+ A Ruby gem to interact with [TheGamesDB](http://thegamesdb.net) [API](http://wiki.thegamesdb.net/index.php?title=API_Introduction).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'thegamesdb'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install thegamesdb
18
+
19
+ ## Usage
20
+
21
+ This is still a work in progress, but for now you can use:
22
+
23
+ * [Get Platforms](#get-platforms)
24
+ * [Get Platform Games || Platform Games](#get-platform-games)
25
+ * [Get Platform](#get-platform)
26
+ * [Get Game](#get-game)
27
+ * [Get Games List](#get-game-list)
28
+ * [Get Art](#get-art)
29
+
30
+ ### Get Platforms
31
+ http://wiki.thegamesdb.net/index.php?title=GetPlatformsList
32
+ >The GetGamesList API search returns a listing of a listing of all platforms available on the site, sorted by alphabetical order of name.
33
+
34
+ **Usage**
35
+
36
+ * Parameters: none
37
+ * Returns: Array with platforms info in Hashes with `:id`, `:name` and `:slug`.
38
+
39
+ ```ruby
40
+ $ irb
41
+ 2.1.2 :001 > require 'gamesdb'
42
+ => true
43
+ 2.1.2 :002 > Gamesdb.platforms
44
+ => [{:name=>"3DO", :id=>25, :slug=>nil},
45
+ {:name=>"Amiga", :id=>4911, :slug=>nil},
46
+ {:name=>"Amstrad CPC", :id=>4914, :slug=>nil},
47
+ {:name=>"Android", :id=>4916, :slug=>nil},
48
+ {:name=>"Arcade", :id=>23, :slug=>nil},
49
+ {:name=>"Atari 2600", :id=>22, :slug=>nil},
50
+ {:name=>"Atari 5200", :id=>26, :slug=>nil},
51
+ ...
52
+ ```
53
+
54
+ ### Get Platform Games OR Platform Games
55
+ The same method implements `GetPlatformGames` and `PlatformGames`. The first receives the platform id as a parameter, the second one receives the slug. You can find the slug with the GetPlatform method. The return is the same for both methods.
56
+
57
+ http://wiki.thegamesdb.net/index.php?title=GetPlatformGames
58
+ >The GetPlatformGames API method returns a listing of all games available on the site for the given platform.
59
+
60
+ http://wiki.thegamesdb.net/index.php/PlatformGames
61
+ >The PlatformGames API call lists all games under a certain platform.
62
+
63
+ * Parameters:
64
+ * id - the integer id of the required platform, as retrived from GetPlatformsList
65
+ * platform (string) : the platform slug to list games for (for more information on how to attain a valid platform slug see GetPlatformsList)
66
+
67
+ * Returns: Array with games info in Hashes with `:id`, `:name` and `:release_date`.
68
+
69
+ With id:
70
+
71
+ ```ruby
72
+ 2.1.2 :003 > Gamesdb.platform_games(6)
73
+ => [{:name=>"Super Mario Kart", :id=>"41", :release_date=>"09/01/1992"},
74
+ {:name=>"Final Fantasy VI", :id=>"83", :release_date=>"04/02/1994"},
75
+ {:name=>"Contra III: The Alien Wars", :id=>"122", :release_date=>"04/06/1992"},
76
+ {:name=>"Donkey Kong Country", :id=>"131", :release_date=>"11/21/1994"},
77
+ {:name=>"Super Mario World", :id=>"136", :release_date=>"11/21/1990"},
78
+ {:name=>"Super Mario World 2: Yoshi's Island", :id=>"137", :release_date=>"10/04/1995"},
79
+ {:name=>"Mega Man X", :id=>"143", :release_date=>"01/01/1994"},
80
+ {:name=>"Teenage Mutant Ninja Turtles IV: Turtles In Time", :id=>"188", :release_date=>"08/01/1992"},
81
+ ...
82
+ ```
83
+
84
+ With slug:
85
+
86
+ ```ruby
87
+ 2.3.1 :001 > Gamesdb.platform_games("3do")
88
+ => [
89
+ {:name=>"Mad Dog McCree", :id=>"6429", :release_date=>"01/01/1994"},
90
+ {:name=>"AD&D: Slayer", :id=>"3143", :release_date=>"01/01/1994"},
91
+ {:name=>"Blade Force", :id=>"4826", :release_date=>"04/05/1995"},
92
+ {:name=>"Battle Chess", :id=>"4829", :release_date=>"01/01/1993"},
93
+ {:name=>"Brain Dead 13", :id=>"4830", :release_date=>"01/01/1996"},
94
+ ...
95
+ ```
96
+
97
+ ### Get Platform
98
+ http://wiki.thegamesdb.net/index.php/GetPlatform
99
+ >This API feature returns a set of metadata and artwork data for a specified Platform ID.
100
+
101
+ **Usage**
102
+
103
+ * Parameters: id - The numeric ID of the platform in the GamesDB database
104
+ * Returns: Hash with platform info
105
+
106
+ ```ruby
107
+ 2.3.1 :001 > Gamesdb.platform(6)
108
+ => {:name=>"Super Nintendo (SNES)",
109
+ :id=>"6",
110
+ :Platform=>"Super Nintendo (SNES)",
111
+ :console=>"http://www.youtube.com/watch?v=6.png",
112
+ :controller=>"http://www.youtube.com/watch?v=6.png",
113
+ :overview=>"The Super Nintendo Entertainment System (also known as the Super NES, SNES or Super Nintendo) is a 16-bit video game console that was released by Nintendo...",
114
+ :developer=>"Nintendo",
115
+ :manufacturer=>"Nintendo",
116
+ :cpu=>"16-bit 65c816 Ricoh 5A22 3.58 MHz",
117
+ :memory=>"128kb",
118
+ :sound=>"8-bit Sony SPC700",
119
+ :display=>"512 × 239",
120
+ :media=>"Cartridge",
121
+ :maxcontrollers=>"2",
122
+ :Youtube=>"http://www.youtube.com/watch?v=9fSAnVpJ42w",
123
+ :Rating=>"7.5909",
124
+ :Images=>{
125
+ :boxart=>{
126
+ :url=>"platform/boxart/6-2.jpg",
127
+ :width=>"500",
128
+ :height=>"750"
129
+ },
130
+ :console_art=>"platform/consoleart/6.png",
131
+ :controller_image=>"platform/controllerart/6.png"
132
+ }
133
+ }
134
+ ```
135
+
136
+ ### Get Game
137
+ http://wiki.thegamesdb.net/index.php?title=GetGame
138
+ >The GetGameApi title search returns game data in an XML document or if an id is given it just returns the data for that specific game.
139
+
140
+ **Usage**
141
+
142
+ * Parameters: id (int): ID representing a specific game
143
+ * Returns: Array with games info in Hashes `:id`, `:title`, `:release_date`, `:platform`, `:overview`, `:publisher`, `:developer`, `:genres` (comma separated string), `:images {:front, :back}`
144
+
145
+ ```ruby
146
+ 2.1.2 :006 > Gamesdb.game(109)
147
+ => {:id=>109,
148
+ :title=>"The Legend of Zelda: Twilight Princess",
149
+ :release_date=>"11/19/2006",
150
+ :platform=>"Nintendo Wii",
151
+ :overview=>"In the next chapter in the Legend of Zelda series, Link can transform into a wolf to scour the darkened land of Hyrule. With the help of Midna, a mysterious being, you must guide Link through hordes of foul creatures and challenging bosses using new moves and a new horseback combat system. Many puzzles stand between Link and the fulfillment of his quest, so you must sharpen your wits as you hunt for weapons and items.",
152
+ :publisher=>"Nintendo",
153
+ :developer=>"Nintendo",
154
+ :genres=>"Action, Adventure",
155
+ :images=>{:back=>"boxart/original/back/109-1.jpg",
156
+ :front=>"boxart/original/front/109-1.jpg"}}
157
+ ```
158
+
159
+ ### Get Games List
160
+ http://wiki.thegamesdb.net/index.php/GetGamesList
161
+ >The GetGamesList API search returns a listing of games matched up with loose search terms. *Note: We have implemented special character stripping and loose word order searching in an attempt to provide better matching and a return a greater number of relevant hits.*
162
+
163
+ **Usage**
164
+
165
+ * Parameters: name (String): search string.
166
+ * Returns: Hash with game info: `:id`, `:name` (not-unique), `:release_date`, `platform`
167
+
168
+ ```ruby
169
+ 2.2.4 :001 > Gamesdb.games_list "Asterix"
170
+ => [{:id=>"2981", :name=>"Asterix", :release_date=>"01/01/1991", :platform=>"Sega Master System"},
171
+ {:id=>"3160", :name=>"Asterix", :release_date=>"01/01/1993", :platform=>"Super Nintendo (SNES)"},
172
+ {:id=>"9243", :name=>"Asterix", :release_date=>"01/01/1983", :platform=>"Atari 2600"},
173
+ {:id=>"21170", :name=>"Asterix", :release_date=>"01/01/1993", :platform=>"Nintendo Game Boy"},
174
+ {:id=>"330", :name=>"Asterix", :release_date=>"03/23/2015", :platform=>"Nintendo Entertainment System (NES)"},
175
+ ...
176
+ ```
177
+
178
+ ### Get Art
179
+ http://wiki.thegamesdb.net/index.php/GetArt
180
+ >This API feature returns a list of available artwork types and locations specific to the requested game id in the database. It also lists the resolution of any images available.
181
+
182
+ **Usage**
183
+
184
+ * Parameters: id (integer): The numeric ID of the game in Gamesdb
185
+ * Returns: Hash with images: `logo`, `boxart` (Hash - front, back), `screenshots`, `fanart`
186
+
187
+ ```ruby
188
+ 2.2.4 :001 > Gamesdb.art(2208)
189
+ => {
190
+ :logo=>"clearlogo/2208.png",
191
+ :boxart=>
192
+ {
193
+ :front=>{
194
+ :url=>"boxart/original/front/2208-1.jpg", :width=>"2099",
195
+ :height=>"1513",
196
+ :thumb=>"boxart/thumb/original/front/2208-1.jpg"
197
+ },
198
+ :back=>{
199
+ :url=>"boxart/original/front/2208-1.jpg",
200
+ :width=>"2099",
201
+ :height=>"1513",
202
+ :thumb=>"boxart/thumb/original/front/2208-1.jpg"
203
+ }
204
+ },
205
+ :screenshots=>[
206
+ {:url=>"screenshots/2208-1.jpg", :width=>"768", :height=>"672", :thumb=>"screenshots/thumb/2208-1.jpg"},
207
+ {:url=>"screenshots/2208-2.jpg", :width=>"768", :height=>"672", :thumb=>"screenshots/thumb/2208-2.jpg"},
208
+ {:url=>"screenshots/2208-3.jpg", :width=>"768", :height=>"672", :thumb=>"screenshots/thumb/2208-3.jpg"}
209
+ ],
210
+ :fanart=>[]
211
+ }
212
+ ```
213
+
214
+ ## Contributing
215
+
216
+ 1. Fork it ( http://github.com/picandocodogio/gamesdb/fork )
217
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
218
+ 3. Write your tests and run `rake test` (make sure they pass)
219
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
220
+ 5. Push to the branch (`git push origin my-new-feature`)
221
+ 6. Create new Pull Request
@@ -0,0 +1,16 @@
1
+ require 'rake/testtask'
2
+ require 'bundler/gem_tasks'
3
+
4
+ Rake::TestTask.new('test') do |t|
5
+ t.pattern = 'test/**/*_test.rb'
6
+ end
7
+
8
+ task :console do
9
+ require 'irb'
10
+ require 'irb/completion'
11
+ require 'thegamesdb'
12
+ ARGV.clear
13
+ IRB.start
14
+ end
15
+
16
+ task default: 'test'
@@ -0,0 +1,242 @@
1
+ require 'thegamesdb/version'
2
+ require 'ox'
3
+ require 'net/http'
4
+
5
+ # Client for TheGamesDB API (thegamesdb.net)
6
+ module Gamesdb
7
+ BASE_URL = 'http://thegamesdb.net/api/'
8
+ IMAGES_BASE_URL = 'http://thegamesdb.net/banners/'
9
+
10
+ # Method for listing platform's games
11
+ # http://wiki.thegamesdb.net/index.php?title=GetPlatformGames
12
+ #
13
+ # Parameters: platform id (int) || platform slug (string)
14
+ # For information on how to attain a valid platform slug see `platform`
15
+ #
16
+ # == Returns:
17
+ # Array of Hashes with games info
18
+ def self.platform_games(platform)
19
+ url = (platform.is_a? Numeric) ? 'GetPlatformGames.php' : 'PlatformGames.php'
20
+ data = xml_response(url, platform: platform)
21
+ process_platform_games(data)
22
+ end
23
+
24
+ # Method for listing platforms
25
+ # http://wiki.thegamesdb.net/index.php?title=GetPlatformsList
26
+ #
27
+ # Parameters: none
28
+ #
29
+ # == Returns:
30
+ # Array of Hashes with platforms info
31
+ #
32
+ def self.platforms
33
+ url = 'GetPlatformsList.php'
34
+ data = xml_response(url)
35
+ platforms = []
36
+
37
+ data.nodes[0].Platforms.nodes.each do |platform|
38
+ id = platform.id.text
39
+ name = platform.nodes[1].text
40
+ slug = platform.respond_to?(:alias) ? platform.alias.text : ''
41
+ platforms << { name: name, id: id.to_i, slug: slug }
42
+ end
43
+ platforms
44
+ end
45
+
46
+ # This API feature returns a set of metadata and artwork data for a
47
+ # specified Platform ID.
48
+ # http://wiki.thegamesdb.net/index.php/GetPlatform
49
+ #
50
+ # Parameters:
51
+ # - id - (int) The numeric ID of the platform in the GamesDB database
52
+ #
53
+ # == Returns:
54
+ # Hash with platform info
55
+ #
56
+ def self.platform(id)
57
+ url = 'GetPlatform.php'
58
+ data = xml_response(url, id: id).Data.Platform
59
+ platform = { name: data.Platform.text }
60
+ data.nodes.each do |node|
61
+ platform[node.value.to_sym] = node.text
62
+ end
63
+ if data.Images
64
+ platform[:Images] = {
65
+ boxart: {
66
+ url: data.Images.boxart.text,
67
+ width: data.Images.boxart.attributes[:width],
68
+ height: data.Images.boxart.attributes[:height]
69
+ },
70
+ console_art: data.Images.consoleart.text,
71
+ controller_image: data.Images.controllerart.text
72
+ }
73
+ end
74
+ platform
75
+ end
76
+
77
+ # Method for getting game info
78
+ # TODO: name and platform parameters (for search)
79
+ # http://wiki.thegamesdb.net/index.php?title=GetGame
80
+ #
81
+ # Parameters:
82
+ # - id - (int) Game id
83
+ #
84
+ # == Returns:
85
+ # Hash with game info
86
+ #
87
+ def self.game(id)
88
+ url = 'GetGame.php'
89
+ data = xml_response(url, id: id)
90
+ game = data.nodes[0].Game
91
+ process_game(game)
92
+ end
93
+
94
+ # The GetGamesList API search returns a listing of games matched up
95
+ # with loose search terms.
96
+ # http://wiki.thegamesdb.net/index.php/GetGamesList
97
+ #
98
+ # Parameters:
99
+ # - name (required)
100
+ # - TODO: platform (optional): filters results by platform (not implemented)
101
+ # - TODO: genre (optional): filters results by genre (not
102
+ # implemented)
103
+ #
104
+ # == Returns:
105
+ # Hash with game info: id, name (not-unique), release_date,
106
+ # platform
107
+ #
108
+ def self.games_list(name)
109
+ url = 'GetGamesList.php'
110
+ data = xml_response(url, name: name)
111
+ build_games_list(data)
112
+ end
113
+
114
+ # This API feature returns a list of available artwork types and
115
+ # locations specific to the requested game id in the database. It
116
+ # also lists the resolution of any images available. Scrapers can be
117
+ # set to use a minimum or maximum resolution for specific images
118
+ # http://wiki.thegamesdb.net/index.php/GetArt
119
+ #
120
+ # Parameters
121
+ # - id - (integer) The numeric ID of the game in Gamesdb that you
122
+ # like to fetch artwork details for
123
+ #
124
+ # == Returns:
125
+ # Hash with game art info: fanart (array), boxart (Hash, :front,
126
+ # :back), screenshots (array), fanart (array)
127
+ #
128
+ def self.art(id)
129
+ url = 'GetArt.php'
130
+ data = xml_response(url, id: id)
131
+ build_images(data.Data.Images)
132
+ end
133
+
134
+ private
135
+
136
+ # Api call and xml parsing
137
+ def self.xml_response(url, params = {})
138
+ uri = URI(BASE_URL + url)
139
+ uri.query = URI.encode_www_form(params)
140
+ request = Net::HTTP.get_response(uri)
141
+ Ox.parse(request.body)
142
+ end
143
+
144
+ # Process games for platform_games
145
+ def self.process_platform_games(data)
146
+ games = []
147
+
148
+ data.nodes[0].nodes.each do |elem|
149
+ name = elem.GameTitle.text
150
+ id = elem.id.text
151
+ date = nil
152
+ # TODO: Fix this:
153
+ begin
154
+ date = elem.ReleaseDate.text
155
+ rescue NoMethodError
156
+ # No release date, nothing to do
157
+ end
158
+ games << { name: name, id: id, release_date: date }
159
+ end
160
+ games
161
+ end
162
+
163
+ def self.process_game(game)
164
+ images = {}
165
+ require 'byebug'; byebug
166
+ game.locate('Images/boxart').each do |a|
167
+ key = a.attributes[:side].to_sym
168
+ images[key] = a.text
169
+ end
170
+ {
171
+ id: game.id.text.to_i, title: game.GameTitle.text,
172
+ release_date: game.ReleaseDate.text, platform: game.Platform.text,
173
+ overview: game.Overview.text, publisher: game.Publisher.text,
174
+ developer: game.Developer.text,
175
+ genres: game.Genres.nodes.map(&:text).join(', '),
176
+ # esrb: game.ESRB.text, rating: game.Rating.text,
177
+ images: images
178
+ }
179
+ end
180
+
181
+ def self.build_games_list(data)
182
+ games = []
183
+ data.Data.nodes.each do |node|
184
+ games << {
185
+ id: node.nodes[0].nodes.first,
186
+ name: node.nodes[1].nodes.first,
187
+ release_date: node.nodes[2].nodes.first,
188
+ platform: node.nodes[3].nodes.first
189
+ }
190
+ end
191
+ games
192
+ end
193
+
194
+ # Process the XML into a hash with screenshots, box art and fan art
195
+ # The URL's stored are the ones coming from the GamesDB, to access
196
+ # the images append Gamesdb::IMAGES_BASE_URL to the urls.
197
+ def self.build_images(data)
198
+ boxart = data.nodes.select { |a| a.value == "boxart" }
199
+ fanart = data.nodes.select { |a| a.value == "fanart" }
200
+ screenshots = data.nodes.select{ |s| s.value == "screenshot"}
201
+ images = {
202
+ logo: data.clearlogo.text,
203
+ boxart: build_boxart(boxart),
204
+ screenshots: images_from_nodes(screenshots),
205
+ fanart: images_from_nodes(fanart)
206
+ }
207
+ images
208
+ end
209
+
210
+ # Get the front and back box art into a Hash
211
+ def self.build_boxart(boxart)
212
+ front = boxart.select { |b| b.attributes[:side] == 'front' }[0]
213
+ back = boxart.pop
214
+ art = {}
215
+ ['front', 'back'].each do |face|
216
+ name = eval(face)
217
+ art[face.to_sym] = {
218
+ url: name.text,
219
+ width: name.attributes[:width],
220
+ height: name.attributes[:height],
221
+ thumb: name.attributes[:thumb]
222
+ }
223
+ end
224
+ art
225
+ end
226
+
227
+ # Method for processing the fan art and screenshots into a uniform
228
+ # collection with url, width, height and thumb url
229
+ def self.images_from_nodes(data)
230
+ images = Array.new
231
+ data.each do |art|
232
+ images << {
233
+ url: art.original.nodes[0],
234
+ width: art.nodes.first.attributes[:width],
235
+ height: art.nodes.first.attributes[:height],
236
+ thumb: art.thumb.text
237
+ }
238
+ end
239
+ images
240
+ end
241
+
242
+ end
@@ -0,0 +1,4 @@
1
+ # Gem version
2
+ module Gamesdb
3
+ VERSION = '0.1.1'
4
+ end
@@ -0,0 +1,162 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ require 'vcr'
4
+ require 'minitest/spec'
5
+ require 'minitest/autorun'
6
+ require "minitest/reporters"
7
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
8
+ require 'thegamesdb'
9
+
10
+ VCR.configure do |c|
11
+ c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
12
+ c.hook_into :webmock
13
+ end
14
+
15
+ describe Gamesdb do
16
+
17
+ describe 'platforms' do
18
+ before do
19
+ VCR.insert_cassette('platforms')
20
+ @platforms = Gamesdb.platforms
21
+ end
22
+
23
+ after do
24
+ VCR.eject_cassette
25
+ end
26
+
27
+ it 'should get gaming platforms' do
28
+ @platforms.count.wont_be :<, 0
29
+ end
30
+
31
+ it 'should have a valid name' do
32
+ @platforms[0][:name].must_be_kind_of String
33
+ end
34
+
35
+ it 'should have a valid id' do
36
+ @platforms[0][:id].must_be_kind_of Integer
37
+ end
38
+
39
+ it 'should have a valid slug' do
40
+ @platforms[0][:slug].must_be_kind_of String
41
+ end
42
+ end
43
+
44
+ describe 'platform_games' do
45
+ before do
46
+ VCR.insert_cassette('platform_games')
47
+ platforms = Gamesdb.platforms
48
+ @games_by_id = Gamesdb.platform_games(platforms[0][:id])
49
+ @games_by_slug = Gamesdb.platform_games(platforms[0][:slug])
50
+ end
51
+
52
+ after do
53
+ VCR.eject_cassette
54
+ end
55
+
56
+ it 'should return games in platform by id' do
57
+ @games_by_id.count.wont_be :<, 0
58
+ end
59
+
60
+ it 'should return games in platform' do
61
+ @games_by_slug.count.wont_be :<, 0
62
+ end
63
+ end
64
+
65
+ describe 'platform' do
66
+ before do
67
+ VCR.insert_cassette('platform')
68
+ @platform = Gamesdb.platform 6
69
+ end
70
+
71
+ after do
72
+ VCR.eject_cassette
73
+ end
74
+
75
+ it 'should return valid platform info' do
76
+ @platform[:name].must_equal 'Super Nintendo (SNES)'
77
+ @platform[:overview].must_be_kind_of String
78
+ @platform[:developer].must_be_kind_of String
79
+ @platform[:manufacturer].must_equal 'Nintendo'
80
+ @platform[:cpu].must_be_kind_of String
81
+ @platform[:memory].must_be_kind_of String
82
+ @platform[:sound].must_be_kind_of String
83
+ @platform[:display].must_be_kind_of String
84
+ end
85
+ end
86
+
87
+ describe 'game' do
88
+ before do
89
+ VCR.insert_cassette('game')
90
+ @game = Gamesdb.game(109)
91
+ end
92
+
93
+ after do
94
+ VCR.eject_cassette
95
+ end
96
+
97
+ it 'should have a valid id' do
98
+ @game[:id].must_be_kind_of Integer
99
+ @game[:id].must_equal 109
100
+ end
101
+
102
+ it 'should have valid fields' do
103
+ @game[:title].must_be_kind_of String
104
+ @game[:title].length.wont_be :<, 0
105
+ end
106
+ end
107
+
108
+ describe 'games_list' do
109
+ before do
110
+ VCR.insert_cassette('games_list')
111
+ @games_list = Gamesdb.games_list('asterix')
112
+ end
113
+
114
+ after do
115
+ VCR.eject_cassette
116
+ end
117
+
118
+ it 'should return a list' do
119
+ @games_list.count.wont_be :<, 0
120
+ game = @games_list.first
121
+ game[:id].must_be_kind_of String
122
+ game[:name].must_be_kind_of String
123
+ game[:platform].must_be_kind_of String
124
+ end
125
+ end
126
+
127
+ describe 'games art' do
128
+ before do
129
+ VCR.insert_cassette('game_art')
130
+ @images = Gamesdb.art("216")
131
+ end
132
+
133
+ after do
134
+ VCR.eject_cassette
135
+ end
136
+
137
+ it 'should return logo and boxart' do
138
+ @images[:boxart].count.wont_be :<, 0
139
+ @images[:logo].must_be_kind_of String
140
+ @images[:boxart][:front][:url].must_be_kind_of String
141
+ @images[:boxart][:front][:width].must_be_kind_of String
142
+ @images[:boxart][:front][:height].must_be_kind_of String
143
+ @images[:boxart][:front][:thumb].must_be_kind_of String
144
+ end
145
+
146
+ it 'should return screenshots' do
147
+ @images[:screenshots].count.wont_be :<, 0
148
+ @images[:screenshots].first[:url].must_be_kind_of String
149
+ @images[:screenshots].first[:width].must_be_kind_of String
150
+ @images[:screenshots].first[:height].must_be_kind_of String
151
+ @images[:screenshots].first[:thumb].must_be_kind_of String
152
+ end
153
+
154
+ it 'should return fanart' do
155
+ @images[:fanart].count.wont_be :<, 0
156
+ @images[:fanart].first[:url].must_be_kind_of String
157
+ @images[:fanart].first[:width].must_be_kind_of String
158
+ @images[:fanart].first[:height].must_be_kind_of String
159
+ @images[:fanart].first[:thumb].must_be_kind_of String
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'thegamesdb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'thegamesdb'
8
+ spec.version = Gamesdb::VERSION
9
+ spec.authors = ['Fernando Briano']
10
+ spec.email = ['fernando@picandocodigo.net']
11
+ spec.summary = 'Client for TheGamesDB API (thegamesdb.net).'
12
+ spec.description = 'Ruby Client for TheGamesDB API (thegamesdb.net). See README.md for usage'
13
+ spec.homepage = 'http://github.com/picandocodigo/gamesdb'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+ spec.add_runtime_dependency 'ox', '~> 2.1'
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'vcr', '~> 2.9'
24
+ spec.add_development_dependency 'minitest'
25
+ spec.add_development_dependency 'minitest-reporters'
26
+ spec.add_development_dependency 'webmock'
27
+ spec.add_development_dependency 'byebug'
28
+ spec.add_development_dependency 'simplecov'
29
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thegamesdb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Fernando Briano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ox
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-reporters
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Ruby Client for TheGamesDB API (thegamesdb.net). See README.md for usage
140
+ email:
141
+ - fernando@picandocodigo.net
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - Gemfile
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - lib/thegamesdb.rb
152
+ - lib/thegamesdb/version.rb
153
+ - test/gamesdb_test.rb
154
+ - thegamesdb.gemspec
155
+ homepage: http://github.com/picandocodigo/gamesdb
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.5.1
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Client for TheGamesDB API (thegamesdb.net).
179
+ test_files:
180
+ - test/gamesdb_test.rb