Module: Gamesdb

Defined in:
lib/thegamesdb.rb,
lib/thegamesdb/version.rb

Overview

Gem version

Constant Summary collapse

BASE_URL =
'http://legacy.thegamesdb.net/api/'
IMAGES_BASE_URL =
'http://legacy.thegamesdb.net/banners/'
VERSION =
'0.2.0'.freeze

Class Method Summary collapse

Class Method Details

.art(id) ⇒ Object

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. Scrapers can be set to use a minimum or maximum resolution for specific images wiki.thegamesdb.net/index.php/GetArt

Parameters

  • id - (integer) The numeric ID of the game in Gamesdb that you

like to fetch artwork details for

Returns:

Hash with game art info: fanart (array), boxart (Hash, :front, :back), screenshots (array), fanart (array)



111
112
113
114
115
116
117
# File 'lib/thegamesdb.rb', line 111

def self.art(id)
  url = 'GetArt.php'
  data = xml_response(url, id: id)[:Images]
  data[:logo] = data[:clearlogo].last
  data[:boxart] = process_covers(data[:boxart])
  data
end

.game(id) ⇒ Object

Method for getting game info TODO: name and platform parameters (for search) wiki.thegamesdb.net/index.php?title=GetGame

Parameters:

- id - (int) Game id

Returns:

Hash with game info



70
71
72
73
74
75
# File 'lib/thegamesdb.rb', line 70

def self.game(id)
  url = 'GetGame.php'
  data = xml_response(url, id: id)
  game = process_game(data[:Game])
  game
end

.games_list(name) ⇒ Object

The GetGamesList API search returns a listing of games matched up with loose search terms. wiki.thegamesdb.net/index.php/GetGamesList

Parameters:

  • name (required)

  • TODO: platform (optional): filters results by platform (not implemented)

  • TODO: genre (optional): filters results by genre (not

implemented)

Returns:

Hash with game info: id, name (not-unique), release_date, platform



91
92
93
94
95
# File 'lib/thegamesdb.rb', line 91

def self.games_list(name)
  url = 'GetGamesList.php'
  data = xml_response(url, name: name)
  data[:Game].map { |game| process_game(game) }
end

.platform(id) ⇒ Object

This API feature returns a set of metadata and artwork data for a specified Platform ID. wiki.thegamesdb.net/index.php/GetPlatform

Parameters:

- id - (int) The numeric ID of the platform in the GamesDB database

Returns:

Hash with platform info



53
54
55
56
57
58
# File 'lib/thegamesdb.rb', line 53

def self.platform(id)
  url = 'GetPlatform.php'
  data = xml_response(url, id: id)[:Platform]
  data[:name] = data.delete(:Platform)
  data
end

.platform_games(platform) ⇒ Object

Method for listing platform’s games wiki.thegamesdb.net/index.php?title=GetPlatformGames

Parameters: platform id (int) || platform slug (string) For information on how to attain a valid platform slug see ‘platform`

Returns:

Array of Hashes with games info



18
19
20
21
22
# File 'lib/thegamesdb.rb', line 18

def self.platform_games(platform)
  url = platform.is_a?(Numeric) ? 'GetPlatformGames.php' : 'PlatformGames.php'
  data = xml_response(url, platform: platform)
  process_platform_games(data)
end

.platformsObject

Method for listing platforms wiki.thegamesdb.net/index.php?title=GetPlatformsList

Parameters: none

Returns:

Array of Hashes with platforms info



32
33
34
35
36
37
38
39
40
41
# File 'lib/thegamesdb.rb', line 32

def self.platforms
  url = 'GetPlatformsList.php'
  data = xml_response(url)
  platforms = []

  data[:Platforms].first.last.each do |platform|
    platforms << { name: platform[:name], id: platform[:id].to_i, slug: platform[:alias] }
  end
  platforms
end

.process_covers(boxart) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/thegamesdb.rb', line 119

def self.process_covers(boxart)
  boxart = boxart.flatten

  covers = {}
  boxart.each do |art|
    next unless art.is_a?(Hash)
    covers[art[:side].to_sym] = {
      url: art[:thumb].gsub('thumb/',''),
      width: art[:width],
      height: art[:height],
      thumb: art[:thumb]
    }
  end
  covers
end