Module: Gamesdb::Games

Included in:
Client
Defined in:
lib/thegamesdb/games.rb

Overview

Games related API Endpoints

Instance Method Summary collapse

Instance Method Details

#games_by_id(id) ⇒ Array|Hash

Method for getting game info

rubocop:disable Metrics/MethodLength

Parameters:

  • id (Integer|String)

    Game id or string of ‘,’ delimited list

Returns:

  • (Array|Hash)

    Hash with game info

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/thegamesdb/games.rb', line 31

def games_by_id(id)
  url = 'Games/ByGameID'
  params = {
    id: id,
    fields:
    'players,publishers,genres,overview,last_updated,rating,platform,coop,youtube,os,processor,ram,hdd,'\
    'video,sound,alternates',
    include: 'boxart,platform'
  }
  data = perform_request(url, params)
  return [] if (data['data']['count']).zero?

  games = data['data']['games']
  return Gamesdb::Utils.symbolize_keys(games.first) if games.count == 1

  games.map { |game| Gamesdb::Utils.symbolize_keys(game) }
end

#games_by_name(name, platform: nil, page: 1) ⇒ Hash

The GetGamesList API search returns a listing of games matched up with loose search terms.

rubocop:disable Metrics/MethodLength

Parameters:

  • name (String)

    game name (required)

  • platform (Integer) (defaults to: nil)

    (optional - platform id)

  • page (Integer) (defaults to: 1)

    (optional)

Returns:

  • (Hash)

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

See Also:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/thegamesdb/games.rb', line 61

def games_by_name(name, platform: nil, page: 1)
  url = 'Games/ByGameName'
  params = {
    fields:
    'players,publishers,genres,overview,last_updated,rating,platform,coop,youtube,os,processor,ram,hdd'\
      ',video,sound,alternates',
    include: 'boxart',
    name: name,
    page: page
  }
  params.merge!('filter[platform]' => platform) unless platform.nil?

  data = perform_request(url, params)
  process_platform_games(data)
end

#games_by_platform_id(platform_id, page = 1) ⇒ Array

Method for listing platform’s games

Parameters:

  • id (Integer)
  • page (Integer) (defaults to: 1)

Returns:

  • (Array)

    Array of Hashes with games info

See Also:



15
16
17
18
19
20
# File 'lib/thegamesdb/games.rb', line 15

def games_by_platform_id(platform_id, page = 1)
  url = 'Games/ByPlatformID'
  params = { id: platform_id, page: page, include: 'boxart' }
  data = perform_request(url, params)
  process_platform_games(data)
end

#games_images(id) ⇒ Hash

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

rubocop:disable Metrics/AbcSize

Parameters:

  • id (Integer)

    The numeric ID of the game in Gamesdb that you like to fetch artwork details for

Returns:

  • (Hash)

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

See Also:



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/thegamesdb/games.rb', line 91

def games_images(id)
  url = 'Games/Images'
  data = perform_request(url, games_id: id)
  return [] if data.dig('data', 'count') == (0 || nil)

  response = {}
  response[:base_url] = data['data']['base_url']['original']
  response[:logo] = Gamesdb::Utils.(data['data'], id)
  response[:boxart] = Gamesdb::Utils.process_covers(data['data'], id)
  response[:screenshot] = Gamesdb::Utils.process_screenshots(data['data'], id)
  response[:fanart] = Gamesdb::Utils.process_fanart(data['data'], id)
  response
end

#games_update(last_edit_id, arguments = {}) ⇒ Object

Fetch games update

rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity

Parameters:

  • last_edit_id (Integer)

    Required

  • time (Integer)

    (optional)

  • page (Integer)

    results page offset to return (optional)

See Also:



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/thegamesdb/games.rb', line 114

def games_update(last_edit_id, arguments = {})
  url = 'Games/Updates'
  params = arguments.merge({ last_edit_id: last_edit_id })
  data = perform_request(url, params)

  regexp = /page=([0-9]+)/
  response = {}
  response[:updates] = data['data']['updates']
  response[:previous_page] = data.dig('pages', 'previous')&.match(regexp)&.captures&.first&.to_i
  response[:next_page] = data.dig('pages', 'next')&.match(regexp)&.captures&.first&.to_i
  response
end