Class: BlizzardApi::Diablo::GenericDataEndpoint

Inherits:
Request show all
Defined in:
lib/blizzard_api/diablo/game_data/generic_data_endpoint.rb

Overview

Generic endpoint to support most data requests with minor configurations

Direct Known Subclasses

Era, Season

Constant Summary

Constants inherited from Request

Request::CACHE_DAY, Request::CACHE_HOUR, Request::CACHE_TRIMESTER

Constants included from ApiStandards

ApiStandards::BASE_URLS

Instance Attribute Summary

Attributes inherited from Request

#mode, #region

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ GenericDataEndpoint

Returns a new instance of GenericDataEndpoint.



7
8
9
10
11
# File 'lib/blizzard_api/diablo/game_data/generic_data_endpoint.rb', line 7

def initialize(**options)
  super(**options)
  endpoint_setup
  @ttl ||= CACHE_DAY
end

Instance Method Details

#get(id, **options) ⇒ Hash

Fetch all possible data for one of items listed by the #index using its id

in the configuration module

Parameters:

  • id (Integer)

    One of the IDs returned by the #index

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :completed (Boolean)

    Should return completed quests

Returns:

  • (Hash)

    API Response. The actual type of the returned object depends on the format option



30
31
32
# File 'lib/blizzard_api/diablo/game_data/generic_data_endpoint.rb', line 30

def get(id, **options)
  api_request "#{base_url(:game_data)}/#{@endpoint}/#{id}", **default_options.merge(options)
end

#index(**options) ⇒ Hash

Get information about the resource

in the configuration module

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :completed (Boolean)

    Should return completed quests

Returns:

  • (Hash)

    API Response. The actual type of the returned object depends on the format option



19
20
21
# File 'lib/blizzard_api/diablo/game_data/generic_data_endpoint.rb', line 19

def index(**options)
  api_request "#{base_url(:game_data)}/#{@endpoint}/", **default_options.merge(options)
end

#leaderboard(id, leaderboard_id, **options) ⇒ Hash

Fetch leaderboard data for the current endpoint

in the configuration module

Parameters:

  • id (Integer)

    One of the IDs returned by the #index

  • leaderboard_id (String)

    Leaderboard id

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :completed (Boolean)

    Should return completed quests

Returns:

  • (Hash)

    API Response. The actual type of the returned object depends on the format option



42
43
44
45
# File 'lib/blizzard_api/diablo/game_data/generic_data_endpoint.rb', line 42

def leaderboard(id, leaderboard_id, **options)
  opts = default_options.merge(options)
  api_request "#{base_url(:game_data)}/#{@endpoint}/#{id}/leaderboard/#{leaderboard_id}", **opts
end