Module: Gamesdb::Platforms

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

Overview

Platforms related API Endpoints

Instance Method Summary collapse

Instance Method Details

#platform_api_response(data) ⇒ Object

Auxiliary method to return either one hash when there’s only one result or an Array of Hashes for several results



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

def platform_api_response(data)
  return [] if data['data']['count'].zero?

  platforms = data['data']['platforms']

  response = case platforms
             when Hash
               platforms.map { |_k, platform| Gamesdb::Utils.symbolize_keys(platform) }
             when Array
               platforms.map { |platform| Gamesdb::Utils.symbolize_keys(platform) }
             end

  return response.first if response.count == 1

  response
end

#platform_images(platforms_id, args = {}) ⇒ Object

Fetch platform(s) images by platform(s) id

database or a String with comma delimited list of Ids. (Required) comma delimited list)

Parameters:

  • platforms_id (Integer|String)

    The numeric ID of the platform in the GamesDB

  • filter (String)

    options: ‘fanart’, ‘banner’, ‘boxart’ (supports

  • page (Integer)

Returns:

  • Array of Hashes

See Also:



79
80
81
82
83
84
85
# File 'lib/thegamesdb/platforms.rb', line 79

def platform_images(platforms_id, args = {})
  url = 'Platforms/Images'
  args['filter[type]'] = args.delete(:type) if args[:type]
  args = args.merge({ platforms_id: platforms_id })
  data = perform_request(url, args)
  data['data']['images'].values.flatten
end

#platformsArray

Method for listing platforms

Returns:

  • (Array)

    Array of Hashes with platforms info

See Also:



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/thegamesdb/platforms.rb', line 12

def platforms
  url = 'Platforms'
  params = { fields:
    'icon,console,controller,developer,manufacturer,media,cpu,memory,graphics,sound,maxcontrollers,'\
      'display,overview,youtube' }
  data = perform_request(url, params)

  data['data']['platforms'].map do |p|
    Gamesdb::Utils.symbolize_keys(p.last)
  end
end

#platforms_by_id(id) ⇒ Hash|Array

This API feature returns a set of metadata and artwork data for a specified Platform ID.

database or a String with comma delimited list of Ids.

Hashes when there’s more than one

Parameters:

  • id (Integer|String)

    The numeric ID of the platform in the GamesDB

Returns:

  • (Hash|Array)

    Returns a Hash when there’s one result or an Array of

See Also:



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/thegamesdb/platforms.rb', line 34

def platforms_by_id(id)
  url = 'Platforms/ByPlatformID'
  params = {
    id: id,
    fields:
    'icon,console,controller,developer,manufacturer,media,cpu,memory,graphics,sound,maxcontrollers,' \
    'display,overview,youtube'
  }
  data = perform_request(url, params)

  platform_api_response(data)
end

#platforms_by_name(name) ⇒ Hash|Array

Fetches platforms by name

Hashes when there’s more than one

Parameters:

  • name (String)

    Platform name (Required)

Returns:

  • (Hash|Array)

    Returns a Hash when there’s one result or an Array of

See Also:



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/thegamesdb/platforms.rb', line 55

def platforms_by_name(name)
  url = 'Platforms/ByPlatformName'
  params = {
    name: name,
    fields:
    'icon,console,controller,developer,manufacturer,media,cpu,memory,graphics,sound,maxcontrollers,display,' \
    'overview,youtube'
  }
  data = perform_request(url, params)

  platform_api_response(data)
end