blizzard_api_rb_rb 3.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +22 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +7 -0
- data/CHANGELOG.md +269 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +200 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/blizzard_api_rb.gemspec +44 -0
- data/lib/blizzard_api_rb/api_response.rb +27 -0
- data/lib/blizzard_api_rb/api_standards.rb +55 -0
- data/lib/blizzard_api_rb/configuration.rb +93 -0
- data/lib/blizzard_api_rb/diablo/community/act.rb +35 -0
- data/lib/blizzard_api_rb/diablo/community/artisan.rb +38 -0
- data/lib/blizzard_api_rb/diablo/community/character_class.rb +38 -0
- data/lib/blizzard_api_rb/diablo/community/follower.rb +25 -0
- data/lib/blizzard_api_rb/diablo/community/item.rb +25 -0
- data/lib/blizzard_api_rb/diablo/community/item_type.rb +35 -0
- data/lib/blizzard_api_rb/diablo/community/profile.rb +83 -0
- data/lib/blizzard_api_rb/diablo/game_data/era.rb +21 -0
- data/lib/blizzard_api_rb/diablo/game_data/generic_data_endpoint.rb +58 -0
- data/lib/blizzard_api_rb/diablo/game_data/season.rb +21 -0
- data/lib/blizzard_api_rb/diablo/request.rb +15 -0
- data/lib/blizzard_api_rb/diablo.rb +91 -0
- data/lib/blizzard_api_rb/exception.rb +14 -0
- data/lib/blizzard_api_rb/hearthstone/game_data/back.rb +59 -0
- data/lib/blizzard_api_rb/hearthstone/game_data/card.rb +111 -0
- data/lib/blizzard_api_rb/hearthstone/game_data/deck.rb +30 -0
- data/lib/blizzard_api_rb/hearthstone/game_data/generic_data_endpoint.rb +49 -0
- data/lib/blizzard_api_rb/hearthstone/game_data/metadata.rb +22 -0
- data/lib/blizzard_api_rb/hearthstone/request.rb +15 -0
- data/lib/blizzard_api_rb/hearthstone.rb +49 -0
- data/lib/blizzard_api_rb/overwatch_league/community/matches.rb +22 -0
- data/lib/blizzard_api_rb/overwatch_league/community/players.rb +22 -0
- data/lib/blizzard_api_rb/overwatch_league/community/segments.rb +22 -0
- data/lib/blizzard_api_rb/overwatch_league/community/summary.rb +22 -0
- data/lib/blizzard_api_rb/overwatch_league/community/teams.rb +22 -0
- data/lib/blizzard_api_rb/overwatch_league/request.rb +15 -0
- data/lib/blizzard_api_rb/overwatch_league.rb +50 -0
- data/lib/blizzard_api_rb/request.rb +189 -0
- data/lib/blizzard_api_rb/starcraft/community/account.rb +23 -0
- data/lib/blizzard_api_rb/starcraft/community/ladder.rb +34 -0
- data/lib/blizzard_api_rb/starcraft/community/legacy.rb +87 -0
- data/lib/blizzard_api_rb/starcraft/community/profile.rb +76 -0
- data/lib/blizzard_api_rb/starcraft/game_data/league.rb +27 -0
- data/lib/blizzard_api_rb/starcraft/request.rb +36 -0
- data/lib/blizzard_api_rb/starcraft.rb +57 -0
- data/lib/blizzard_api_rb/token_manager.rb +49 -0
- data/lib/blizzard_api_rb/version.rb +6 -0
- data/lib/blizzard_api_rb/wow/game_data/achievement.rb +46 -0
- data/lib/blizzard_api_rb/wow/game_data/auction.rb +50 -0
- data/lib/blizzard_api_rb/wow/game_data/azerite_essence.rb +30 -0
- data/lib/blizzard_api_rb/wow/game_data/connected_realm.rb +18 -0
- data/lib/blizzard_api_rb/wow/game_data/covenant.rb +72 -0
- data/lib/blizzard_api_rb/wow/game_data/creature.rb +102 -0
- data/lib/blizzard_api_rb/wow/game_data/generic_data_endpoint.rb +50 -0
- data/lib/blizzard_api_rb/wow/game_data/guild_crest.rb +48 -0
- data/lib/blizzard_api_rb/wow/game_data/heirloom.rb +16 -0
- data/lib/blizzard_api_rb/wow/game_data/item.rb +102 -0
- data/lib/blizzard_api_rb/wow/game_data/journal.rb +110 -0
- data/lib/blizzard_api_rb/wow/game_data/media.rb +26 -0
- data/lib/blizzard_api_rb/wow/game_data/modified_crafting.rb +60 -0
- data/lib/blizzard_api_rb/wow/game_data/mount.rb +18 -0
- data/lib/blizzard_api_rb/wow/game_data/mythic_keystone.rb +86 -0
- data/lib/blizzard_api_rb/wow/game_data/mythic_keystone_affix.rb +28 -0
- data/lib/blizzard_api_rb/wow/game_data/mythic_keystone_leaderboard.rb +48 -0
- data/lib/blizzard_api_rb/wow/game_data/mythic_raid_leaderboard.rb +28 -0
- data/lib/blizzard_api_rb/wow/game_data/pet.rb +62 -0
- data/lib/blizzard_api_rb/wow/game_data/playable_class.rb +39 -0
- data/lib/blizzard_api_rb/wow/game_data/playable_race.rb +16 -0
- data/lib/blizzard_api_rb/wow/game_data/playable_specialization.rb +65 -0
- data/lib/blizzard_api_rb/wow/game_data/power_type.rb +16 -0
- data/lib/blizzard_api_rb/wow/game_data/profession.rb +65 -0
- data/lib/blizzard_api_rb/wow/game_data/pvp_region.rb +82 -0
- data/lib/blizzard_api_rb/wow/game_data/pvp_season.rb +53 -0
- data/lib/blizzard_api_rb/wow/game_data/pvp_tier.rb +26 -0
- data/lib/blizzard_api_rb/wow/game_data/quest.rb +79 -0
- data/lib/blizzard_api_rb/wow/game_data/realm.rb +18 -0
- data/lib/blizzard_api_rb/wow/game_data/region.rb +16 -0
- data/lib/blizzard_api_rb/wow/game_data/reputation.rb +74 -0
- data/lib/blizzard_api_rb/wow/game_data/spell.rb +38 -0
- data/lib/blizzard_api_rb/wow/game_data/talent.rb +75 -0
- data/lib/blizzard_api_rb/wow/game_data/tech_talent.rb +50 -0
- data/lib/blizzard_api_rb/wow/game_data/title.rb +16 -0
- data/lib/blizzard_api_rb/wow/game_data/toy.rb +16 -0
- data/lib/blizzard_api_rb/wow/game_data/wow_token.rb +20 -0
- data/lib/blizzard_api_rb/wow/profile/account_profile.rb +97 -0
- data/lib/blizzard_api_rb/wow/profile/character_profile.rb +415 -0
- data/lib/blizzard_api_rb/wow/profile/guild.rb +75 -0
- data/lib/blizzard_api_rb/wow/request.rb +16 -0
- data/lib/blizzard_api_rb/wow/search/search_composer.rb +97 -0
- data/lib/blizzard_api_rb/wow/search/search_request.rb +24 -0
- data/lib/blizzard_api_rb/wow/slug.rb +12 -0
- data/lib/blizzard_api_rb/wow.rb +335 -0
- data/lib/blizzard_api_rb.rb +26 -0
- metadata +237 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'blizzard_api_rb/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.required_ruby_version = '>= 2.7.2'
|
9
|
+
spec.name = 'blizzard_api_rb_rb'
|
10
|
+
spec.version = BlizzardApi::VERSION
|
11
|
+
spec.authors = ['Alexchaos']
|
12
|
+
spec.email = ['contact@astpierre.dev']
|
13
|
+
spec.summary = 'Unofficial Ruby client for Blizzard Entertainment API'
|
14
|
+
spec.description = 'This is a simple interface to obtain data from Blizzard API'
|
15
|
+
spec.homepage = 'https://github.com/alexchaoss/blizzard_api_rb'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
|
21
|
+
|
22
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
23
|
+
spec.metadata['source_code_uri'] = 'https://github.com/alexchaoss/blizzard_api_rb'
|
24
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/alexchaoss/blizzard_api_rb/issues'
|
25
|
+
spec.metadata['changelog_uri'] = 'https://github.com/alexchaoss/blizzard_api_rb/blob/master/CHANGELOG.md'
|
26
|
+
spec.metadata['documentation_uri'] = 'https://rubydoc.info/gems/blizzard_api_rb_rb'
|
27
|
+
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
end
|
33
|
+
spec.bindir = 'exe'
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ['lib']
|
36
|
+
|
37
|
+
spec.add_runtime_dependency 'redis', '~> 4.1', '>= 4.1.0'
|
38
|
+
|
39
|
+
spec.add_development_dependency 'dotenv'
|
40
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
41
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
42
|
+
spec.add_development_dependency 'rubocop', '~> 0.61'
|
43
|
+
spec.add_development_dependency 'yard'
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
##
|
5
|
+
# Simple replacement for the http response object for cached data
|
6
|
+
class ApiResponse
|
7
|
+
attr_reader :code, :body
|
8
|
+
|
9
|
+
def initialize(body)
|
10
|
+
@code = 200
|
11
|
+
@body = body
|
12
|
+
end
|
13
|
+
|
14
|
+
def cached?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Net
|
21
|
+
# Workaround for fake response payloads
|
22
|
+
class HTTPResponse
|
23
|
+
def cached?
|
24
|
+
false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
##
|
5
|
+
# Default constants and helper functions for the API format
|
6
|
+
module ApiStandards
|
7
|
+
# Common endpoints
|
8
|
+
BASE_URLS = {
|
9
|
+
game_data: 'https://%s.api.blizzard.com/data/%s',
|
10
|
+
community: 'https://%s.api.blizzard.com/%s',
|
11
|
+
profile: 'https://%s.api.blizzard.com/profile/%s',
|
12
|
+
media: 'https://%s.api.blizzard.com/data/%s/media',
|
13
|
+
user_profile: 'https://%s.api.blizzard.com/profile/user/%s',
|
14
|
+
search: 'https://%s.api.blizzard.com/data/%s/search'
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def base_url(scope)
|
20
|
+
raise ArgumentError, 'Invalid scope' unless BASE_URLS.include? scope
|
21
|
+
|
22
|
+
format BASE_URLS[scope], region, @game
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Returns a valid version namespace
|
27
|
+
#
|
28
|
+
# @param [Hash] options A hash containing a valid namespace key
|
29
|
+
def endpoint_version(options)
|
30
|
+
if options.key? :classic
|
31
|
+
'classic-'
|
32
|
+
elsif options.key? :classic1x
|
33
|
+
'classic1x-'
|
34
|
+
else
|
35
|
+
''
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Returns a valid namespace string for consuming the api endpoints
|
41
|
+
#
|
42
|
+
# @param [Hash] options A hash containing the namespace key
|
43
|
+
def endpoint_namespace(options)
|
44
|
+
version = endpoint_version(options)
|
45
|
+
|
46
|
+
return "dynamic-#{version}#{region}" if options[:namespace].eql? :dynamic
|
47
|
+
|
48
|
+
return "static-#{version}#{region}" if options[:namespace].eql? :static
|
49
|
+
|
50
|
+
return "profile-#{version}#{region}" if options[:namespace].eql? :profile
|
51
|
+
|
52
|
+
raise ArgumentError, 'Invalid namespace scope'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
# Global configurations
|
5
|
+
module Configuration
|
6
|
+
##
|
7
|
+
# @!attribute app_id
|
8
|
+
# Application ID.
|
9
|
+
# @see https://develop.battle.net/access/clients
|
10
|
+
# @return [String] Application ID
|
11
|
+
attr_accessor :app_id
|
12
|
+
|
13
|
+
##
|
14
|
+
# @!attribute app_secret
|
15
|
+
# Application secret.
|
16
|
+
# @see https://develop.battle.net/access/clients
|
17
|
+
# @return [String] Application secret
|
18
|
+
attr_accessor :app_secret
|
19
|
+
|
20
|
+
##
|
21
|
+
# @!attribute region
|
22
|
+
# Default region.
|
23
|
+
# @return [String] Default region
|
24
|
+
attr_accessor :region
|
25
|
+
|
26
|
+
##
|
27
|
+
# @!attribute mode
|
28
|
+
# Api response mode :regular or :extended.
|
29
|
+
# @return [Symbol] Default API response mode
|
30
|
+
attr_accessor :mode
|
31
|
+
|
32
|
+
##
|
33
|
+
# @!attribute use_cache
|
34
|
+
# If true requests will be cached using a Redis server.
|
35
|
+
# @see https://redis.io/
|
36
|
+
# @return [Boolean] Application ID
|
37
|
+
attr_accessor :use_cache
|
38
|
+
|
39
|
+
##
|
40
|
+
# @!attribute redis_host
|
41
|
+
# Redis host.
|
42
|
+
# @see https://redis.io/
|
43
|
+
# @return [String] Redis host
|
44
|
+
attr_accessor :redis_host
|
45
|
+
|
46
|
+
##
|
47
|
+
# @!attribute redis_port
|
48
|
+
# Redis port.
|
49
|
+
# @see https://redis.io/
|
50
|
+
# @return [Integer] Redis port
|
51
|
+
attr_accessor :redis_port
|
52
|
+
|
53
|
+
##
|
54
|
+
# @!attribute redis_database
|
55
|
+
# Redis databse.
|
56
|
+
# @see https://redis.io/
|
57
|
+
# @return [Integer] Redis database
|
58
|
+
attr_accessor :redis_database
|
59
|
+
|
60
|
+
##
|
61
|
+
# @!attribute cache_access_token
|
62
|
+
# If set to true and cache is enabled the current access token will be cached and recovered from Redis
|
63
|
+
# @return [Boolean] Access token.
|
64
|
+
attr_accessor :cache_access_token
|
65
|
+
|
66
|
+
##
|
67
|
+
# This method return the singleton instance of the configuration module. Use this to initialize the default values
|
68
|
+
# and options.
|
69
|
+
#
|
70
|
+
# @yield self
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# BlizzardApi.configure do |config|
|
74
|
+
# config.app_id = ENV['BNET_APPLICATION_ID']
|
75
|
+
# config.app_secret = ENV['BNET_APPLICATION_SECRET']
|
76
|
+
# config.region = 'us'
|
77
|
+
#
|
78
|
+
# config.use_cache = true
|
79
|
+
# config.redis_host = ENV['REDIS_HOST']
|
80
|
+
# config.redis_port = ENV['REDIS_PORT']
|
81
|
+
# end
|
82
|
+
def configure
|
83
|
+
yield self
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Initializes some default values for the main module
|
88
|
+
def self.extended(base)
|
89
|
+
base.redis_port = 1
|
90
|
+
base.mode = :regular
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
##
|
6
|
+
# This class allows access to Diablo III act data
|
7
|
+
#
|
8
|
+
# @see https://develop.battle.net/documentation/api-reference/diablo-3-community-api
|
9
|
+
#
|
10
|
+
# You can get an instance of this class using the default region as follows:
|
11
|
+
# api_instance = BlizzardApi::Diablo.act
|
12
|
+
class Act < BlizzardApi::Diablo::Request
|
13
|
+
##
|
14
|
+
# Return a list with all acts
|
15
|
+
#
|
16
|
+
# @!macro request_options
|
17
|
+
#
|
18
|
+
# @!macro response
|
19
|
+
def index(**options)
|
20
|
+
api_request "#{base_url(:community)}/data/act", **{ ttl: CACHE_TRIMESTER }.merge(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Return complete information about an act
|
25
|
+
#
|
26
|
+
# @param id [Integer] Act id
|
27
|
+
# @!macro request_options
|
28
|
+
#
|
29
|
+
# @!macro response
|
30
|
+
def get(id, **options)
|
31
|
+
api_request "#{base_url(:community)}/data/act/#{id}", **{ ttl: CACHE_TRIMESTER }.merge(options)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
##
|
6
|
+
# This class allows access to Diablo III artisan data
|
7
|
+
#
|
8
|
+
# @see https://develop.battle.net/documentation/api-reference/diablo-3-community-api
|
9
|
+
#
|
10
|
+
# You can get an instance of this class using the default region as follows:
|
11
|
+
# api_instance = BlizzardApi::Diablo.artisan
|
12
|
+
class Artisan < BlizzardApi::Diablo::Request
|
13
|
+
##
|
14
|
+
# Return data about an artisan by its slug
|
15
|
+
#
|
16
|
+
# @param artisan_slug [String] Artisan slug
|
17
|
+
# @!macro request_options
|
18
|
+
#
|
19
|
+
# @!macro response
|
20
|
+
def get(artisan_slug, **options)
|
21
|
+
api_request "#{base_url(:community)}/data/artisan/#{artisan_slug}", **{ ttl: CACHE_TRIMESTER }.merge(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Return data about an artisan recipe
|
26
|
+
#
|
27
|
+
# @param artisan_slug [String] Artisan slug
|
28
|
+
# @param recipe_slug [String] Recipe slug
|
29
|
+
# @!macro request_options
|
30
|
+
#
|
31
|
+
# @!macro response
|
32
|
+
def recipe(artisan_slug, recipe_slug, **options)
|
33
|
+
opts = { ttl: CACHE_TRIMESTER }.merge(options)
|
34
|
+
api_request "#{base_url(:community)}/data/artisan/#{artisan_slug}/recipe/#{recipe_slug}", **opts
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
##
|
6
|
+
# This class allows access to Diablo III character data
|
7
|
+
#
|
8
|
+
# @see https://develop.battle.net/documentation/api-reference/diablo-3-community-api
|
9
|
+
#
|
10
|
+
# You can get an instance of this class using the default region as follows:
|
11
|
+
# api_instance = BlizzardApi::Diablo.character
|
12
|
+
class CharacterClass < BlizzardApi::Diablo::Request
|
13
|
+
##
|
14
|
+
# Return information about a class
|
15
|
+
#
|
16
|
+
# @param class_slug [String] Class slug
|
17
|
+
# @!macro request_options
|
18
|
+
#
|
19
|
+
# @!macro response
|
20
|
+
def get(class_slug, **options)
|
21
|
+
api_request "#{base_url(:community)}/data/hero/#{class_slug}", **{ ttl: CACHE_TRIMESTER }.merge(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Return information about a class' skill
|
26
|
+
#
|
27
|
+
# @param class_slug [String] Class slug
|
28
|
+
# @param skill_slug [String] Skill slug
|
29
|
+
# @!macro request_options
|
30
|
+
#
|
31
|
+
# @!macro response
|
32
|
+
def skill(class_slug, skill_slug, **options)
|
33
|
+
opts = { ttl: CACHE_TRIMESTER }.merge(options)
|
34
|
+
api_request "#{base_url(:community)}/data/hero/#{class_slug}/skill/#{skill_slug}", **opts
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
##
|
6
|
+
# This class allows access to Diablo III follower data
|
7
|
+
#
|
8
|
+
# @see https://develop.battle.net/documentation/api-reference/diablo-3-community-api
|
9
|
+
#
|
10
|
+
# You can get an instance of this class using the default region as follows:
|
11
|
+
# api_instance = BlizzardApi::Diablo.follower
|
12
|
+
class Follower < BlizzardApi::Diablo::Request
|
13
|
+
##
|
14
|
+
# Return information about a follower
|
15
|
+
#
|
16
|
+
# @param follower_slug [String] Follower slug
|
17
|
+
# @!macro request_options
|
18
|
+
#
|
19
|
+
# @!macro response
|
20
|
+
def get(follower_slug, **options)
|
21
|
+
api_request "#{base_url(:community)}/data/follower/#{follower_slug}", **{ ttl: CACHE_TRIMESTER }.merge(options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
##
|
6
|
+
# This class allows access to Diablo III item data
|
7
|
+
#
|
8
|
+
# @see https://develop.battle.net/documentation/api-reference/diablo-3-community-api
|
9
|
+
#
|
10
|
+
# You can get an instance of this class using the default region as follows:
|
11
|
+
# api_instance = BlizzardApi::Diablo.item
|
12
|
+
class Item < BlizzardApi::Diablo::Request
|
13
|
+
##
|
14
|
+
# Return information about an item
|
15
|
+
#
|
16
|
+
# @param item_slug_and_id [String] Item slug
|
17
|
+
# @!macro request_options
|
18
|
+
#
|
19
|
+
# @!macro response
|
20
|
+
def get(item_slug_and_id, **options)
|
21
|
+
api_request "#{base_url(:community)}/data/item/#{item_slug_and_id}", **{ ttl: CACHE_TRIMESTER }.merge(options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
##
|
6
|
+
# This class allows access to Diablo III item type data
|
7
|
+
#
|
8
|
+
# @see https://develop.battle.net/documentation/api-reference/diablo-3-community-api
|
9
|
+
#
|
10
|
+
# You can get an instance of this class using the default region as follows:
|
11
|
+
# api_instance = BlizzardApi::Diablo.item_type
|
12
|
+
class ItemType < BlizzardApi::Diablo::Request
|
13
|
+
##
|
14
|
+
# Return a list of item types
|
15
|
+
#
|
16
|
+
# @!macro request_options
|
17
|
+
#
|
18
|
+
# @!macro response
|
19
|
+
def index(**options)
|
20
|
+
api_request "#{base_url(:community)}/data/item-type", **{ ttl: CACHE_TRIMESTER }.merge(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Return more information about an item type
|
25
|
+
#
|
26
|
+
# @param item_type_slug [String] Item type slug
|
27
|
+
# @!macro request_options
|
28
|
+
#
|
29
|
+
# @!macro response
|
30
|
+
def get(item_type_slug, **options)
|
31
|
+
api_request "#{base_url(:community)}/data/item-type/#{item_type_slug}", **{ ttl: CACHE_TRIMESTER }.merge(options)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
##
|
6
|
+
# This class allows access to Diablo III profile data
|
7
|
+
#
|
8
|
+
# @see https://develop.battle.net/documentation/api-reference/diablo-3-community-api
|
9
|
+
#
|
10
|
+
# You can get an instance of this class using the default region as follows:
|
11
|
+
# api_instance = BlizzardApi::Diablo.profile
|
12
|
+
class Profile < BlizzardApi::Diablo::Request
|
13
|
+
##
|
14
|
+
# Return an user's profile data with a list of heroes
|
15
|
+
#
|
16
|
+
# @param battletag [String] User's battletag
|
17
|
+
# @param oauth_token [String] A token generated by the OAuth authorization flow. See the link below for more info.
|
18
|
+
# @!macro request_options
|
19
|
+
#
|
20
|
+
# @!macro response
|
21
|
+
#
|
22
|
+
# @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
|
23
|
+
def index(battletag, oauth_token, **options)
|
24
|
+
opts = { access_token: oauth_token, ttl: CACHE_TRIMESTER }.merge(options)
|
25
|
+
api_request "#{base_url(:community)}/profile/#{parse_battle_tag(battletag)}/", **opts
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Return more data about a hero
|
30
|
+
#
|
31
|
+
# @param battletag [String] User's battletag
|
32
|
+
# @param oauth_token [String] A token generated by the OAuth authorization flow. See the link below for more info.
|
33
|
+
# @param hero_id [Integer] Hero id
|
34
|
+
# @!macro request_options
|
35
|
+
#
|
36
|
+
# @!macro response
|
37
|
+
#
|
38
|
+
# @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
|
39
|
+
def hero(battletag, oauth_token, hero_id, **options)
|
40
|
+
opts = { access_token: oauth_token, ttl: CACHE_TRIMESTER }.merge(options)
|
41
|
+
api_request "#{base_url(:community)}/profile/#{parse_battle_tag(battletag)}/hero/#{hero_id}", **opts
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Return more data about a hero's items
|
46
|
+
#
|
47
|
+
# @param battletag [String] User's battletag
|
48
|
+
# @param oauth_token [String] A token generated by the OAuth authorization flow. See the link below for more info.
|
49
|
+
# @param hero_id [Integer] Hero id
|
50
|
+
# @!macro request_options
|
51
|
+
#
|
52
|
+
# @!macro response
|
53
|
+
#
|
54
|
+
# @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
|
55
|
+
def hero_items(battletag, oauth_token, hero_id, **options)
|
56
|
+
opts = { access_token: oauth_token, ttl: CACHE_TRIMESTER }.merge(options)
|
57
|
+
api_request "#{base_url(:community)}/profile/#{parse_battle_tag(battletag)}/hero/#{hero_id}/items", **opts
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Return more data about a hero's followers
|
62
|
+
#
|
63
|
+
# @param battletag [String] User's battletag
|
64
|
+
# @param oauth_token [String] A token generated by the OAuth authorization flow. See the link below for more info.
|
65
|
+
# @param hero_id [Integer] Hero id
|
66
|
+
# @!macro request_options
|
67
|
+
#
|
68
|
+
# @!macro response
|
69
|
+
#
|
70
|
+
# @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
|
71
|
+
def hero_follower_items(battletag, oauth_token, hero_id, **options)
|
72
|
+
opts = { access_token: oauth_token, ttl: CACHE_TRIMESTER }.merge(options)
|
73
|
+
api_request "#{base_url(:community)}/profile/#{parse_battle_tag(battletag)}/hero/#{hero_id}/follower-items", **opts
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def parse_battle_tag(battletag)
|
79
|
+
battletag.sub('#', '-')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
##
|
6
|
+
# This class allows access to Diablo III era data
|
7
|
+
#
|
8
|
+
# @see https://develop.battle.net/documentation/api-reference/diablo-3-game-data-api
|
9
|
+
#
|
10
|
+
# You can get an instance of this class using the default region as follows:
|
11
|
+
# api_instance = BlizzardApi::Diablo.era
|
12
|
+
class Era < Diablo::GenericDataEndpoint
|
13
|
+
protected
|
14
|
+
|
15
|
+
def endpoint_setup
|
16
|
+
@endpoint = 'era'
|
17
|
+
@ttl = CACHE_TRIMESTER
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
# Generic endpoint to support most data requests with minor configurations
|
6
|
+
class GenericDataEndpoint < Diablo::Request
|
7
|
+
def initialize(**options)
|
8
|
+
super(**options)
|
9
|
+
endpoint_setup
|
10
|
+
@ttl ||= CACHE_DAY
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Get information about the resource
|
15
|
+
#
|
16
|
+
# @!macro request_options
|
17
|
+
#
|
18
|
+
# @!macro response
|
19
|
+
def index(**options)
|
20
|
+
api_request "#{base_url(:game_data)}/#{@endpoint}/", **default_options.merge(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Fetch all possible data for one of items listed by the {#index} using its *id*
|
25
|
+
#
|
26
|
+
# @param [Integer] id One of the IDs returned by the {#index}
|
27
|
+
# @!macro request_options
|
28
|
+
#
|
29
|
+
# @!macro response
|
30
|
+
def get(id, **options)
|
31
|
+
api_request "#{base_url(:game_data)}/#{@endpoint}/#{id}", **default_options.merge(options)
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Fetch leaderboard data for the current endpoint
|
36
|
+
#
|
37
|
+
# @param [Integer] id One of the IDs returned by the {index}
|
38
|
+
# @param [String] leaderboard_id Leaderboard id
|
39
|
+
# @!macro request_options
|
40
|
+
#
|
41
|
+
# @!macro response
|
42
|
+
def leaderboard(id, leaderboard_id, **options)
|
43
|
+
opts = default_options.merge(options)
|
44
|
+
api_request "#{base_url(:game_data)}/#{@endpoint}/#{id}/leaderboard/#{leaderboard_id}", **opts
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def endpoint_setup
|
50
|
+
raise NotImplementedError
|
51
|
+
end
|
52
|
+
|
53
|
+
def default_options
|
54
|
+
{ ttl: @ttl }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
##
|
6
|
+
# This class allows access to Diablo III season data
|
7
|
+
#
|
8
|
+
# @see https://develop.battle.net/documentation/api-reference/diablo-3-game-data-api
|
9
|
+
#
|
10
|
+
# You can get an instance of this class using the default region as follows:
|
11
|
+
# api_instance = BlizzardApi::Diablo.season
|
12
|
+
class Season < Diablo::GenericDataEndpoint
|
13
|
+
protected
|
14
|
+
|
15
|
+
def endpoint_setup
|
16
|
+
@endpoint = 'season'
|
17
|
+
@ttl = CACHE_TRIMESTER
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlizzardApi
|
4
|
+
module Diablo
|
5
|
+
# Diablo III requests
|
6
|
+
class Request < BlizzardApi::Request
|
7
|
+
##
|
8
|
+
# @!macro init_options
|
9
|
+
def initialize(**options)
|
10
|
+
super(**options)
|
11
|
+
@game = 'd3'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|