blizzard_api 0.6.3 → 3.0.0

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/Gemfile.lock +12 -14
  4. data/blizzard_api.gemspec +0 -1
  5. data/lib/blizzard_api/api_response.rb +24 -0
  6. data/lib/blizzard_api/api_standards.rb +55 -0
  7. data/lib/blizzard_api/configuration.rb +20 -17
  8. data/lib/blizzard_api/diablo/game_data/generic_data_endpoint.rb +2 -2
  9. data/lib/blizzard_api/diablo/request.rb +3 -3
  10. data/lib/blizzard_api/diablo.rb +33 -27
  11. data/lib/blizzard_api/hearthstone/game_data/generic_data_endpoint.rb +2 -2
  12. data/lib/blizzard_api/hearthstone/request.rb +3 -3
  13. data/lib/blizzard_api/hearthstone.rb +18 -12
  14. data/lib/blizzard_api/request.rb +45 -83
  15. data/lib/blizzard_api/starcraft/community/legacy.rb +6 -6
  16. data/lib/blizzard_api/starcraft/request.rb +3 -3
  17. data/lib/blizzard_api/starcraft.rb +20 -14
  18. data/lib/blizzard_api/token_manager.rb +49 -0
  19. data/lib/blizzard_api/version.rb +1 -1
  20. data/lib/blizzard_api/wow/game_data/achievement.rb +1 -16
  21. data/lib/blizzard_api/wow/game_data/azerite_essence.rb +2 -9
  22. data/lib/blizzard_api/wow/game_data/connected_realm.rb +1 -8
  23. data/lib/blizzard_api/wow/game_data/covenant.rb +2 -9
  24. data/lib/blizzard_api/wow/game_data/creature.rb +2 -13
  25. data/lib/blizzard_api/wow/game_data/generic_data_endpoint.rb +10 -37
  26. data/lib/blizzard_api/wow/game_data/guild_crest.rb +4 -10
  27. data/lib/blizzard_api/wow/game_data/item.rb +3 -18
  28. data/lib/blizzard_api/wow/game_data/journal.rb +2 -17
  29. data/lib/blizzard_api/wow/game_data/media.rb +2 -13
  30. data/lib/blizzard_api/wow/game_data/modified_crafting.rb +1 -12
  31. data/lib/blizzard_api/wow/game_data/mount.rb +1 -8
  32. data/lib/blizzard_api/wow/game_data/mythic_keystone.rb +2 -13
  33. data/lib/blizzard_api/wow/game_data/mythic_keystone_affix.rb +2 -9
  34. data/lib/blizzard_api/wow/game_data/pet.rb +2 -9
  35. data/lib/blizzard_api/wow/game_data/playable_class.rb +2 -48
  36. data/lib/blizzard_api/wow/game_data/playable_race.rb +1 -8
  37. data/lib/blizzard_api/wow/game_data/playable_specialization.rb +1 -18
  38. data/lib/blizzard_api/wow/game_data/power_type.rb +1 -8
  39. data/lib/blizzard_api/wow/game_data/profession.rb +2 -9
  40. data/lib/blizzard_api/wow/game_data/pvp_region.rb +82 -0
  41. data/lib/blizzard_api/wow/game_data/pvp_season.rb +7 -9
  42. data/lib/blizzard_api/wow/game_data/pvp_tier.rb +3 -10
  43. data/lib/blizzard_api/wow/game_data/quest.rb +2 -9
  44. data/lib/blizzard_api/wow/game_data/realm.rb +1 -8
  45. data/lib/blizzard_api/wow/game_data/region.rb +1 -8
  46. data/lib/blizzard_api/wow/game_data/reputation.rb +2 -9
  47. data/lib/blizzard_api/wow/game_data/spell.rb +2 -17
  48. data/lib/blizzard_api/wow/game_data/talent.rb +2 -9
  49. data/lib/blizzard_api/wow/game_data/tech_talent.rb +2 -9
  50. data/lib/blizzard_api/wow/game_data/title.rb +1 -16
  51. data/lib/blizzard_api/wow/profile/profile.rb +2 -2
  52. data/lib/blizzard_api/wow/request.rb +3 -3
  53. data/lib/blizzard_api/wow.rb +122 -108
  54. data/lib/blizzard_api.rb +10 -0
  55. metadata +6 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daa79d3a8860c6cfd5b600090627933b7b2710ade24d4c76099198741accff97
4
- data.tar.gz: f98d1226d19bfb605aa65c5380f7d3891b0b3fa733b7f85f3e21ba0d92ba9ee9
3
+ metadata.gz: 4c8fd5029d2b85e30104b35b0a1f4d7f6b2ea7d758b6388f2822408f94d3181c
4
+ data.tar.gz: 2f74b10c6312c1c85479f99dc498f1eceb65f8afacad3f40a9a94e23d8da2bce
5
5
  SHA512:
6
- metadata.gz: 97da96397847d2d55c09a1bf7fa8aa81fe828780b58dd4830635c06fcb4070799df4e271ffa92c2dd64e40caa5fe0ab78609a0cb3940abee8d91a73a09e3f156
7
- data.tar.gz: 95cd4500e97f933fdd29ac2005524a3b1cb8b5283b82a61dd737a9f04bfaf6206dbc32869c95ff9ca95c72efebb8e3fb6d702126fad41a6f058cd81d88b4f173
6
+ metadata.gz: 25a95b728c6d08054858b1c3203bc8b5e5d3f7737ee8e5074e3f5253f1378c94b0e5970b740f9f29b152c67ec289857bb213842aeaaea519f91d7c9a89549328
7
+ data.tar.gz: c99f65f0f4e15e9076d64dc825d30a55ae5ef7484d14b690065d85a8167329d704d6350594b0576251958b8e938362de589b8afa167ee2e2144c2805e09d017c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  Please view this file on the master branch, otherwise it may be outdated
2
2
 
3
+ **Version 3.0.0**
4
+
5
+ Changed the way `:extended` mode is handled regarding caching. Now the extended mode will use cache and return a fake
6
+ response object if the content is cached (Cache is still ignored when using the `:since` option).
7
+ A cached response can be identified by the presence of a `cached?` method on the response object.
8
+
9
+ Some automated tests for SC2 endpoints are now ignoring `503` errors. The state of the API is somehow unknown since it
10
+ is down most of the time.
11
+
12
+ **Version 2.0.0**
13
+
14
+ Removed the `icon` field from PlayableClass, it was meant to mimic the old communit API behavior during the transition
15
+ to the new game_data version.
16
+
17
+ **Version 1.0.0**
18
+
19
+ Removed the `complete` method from WoW game data endpoints.
20
+ Removed the `concurrency` request and configuration option as it is not necessary anymore.
21
+ Removed the `thwait` dependency.
22
+
23
+ Added the `redis_database` option to support selecting the redis database for caching data.
24
+ The gem will now share a single Redis connection across all calls.
25
+ The gem now creates a new token on demand if the previous one has expired.
26
+ It is now possible to cache the token in Redis to avoid needlessly creating a new token.
27
+ It is now possible to set the default mode for API calls
28
+
29
+ **Version 0.6.4**
30
+
31
+ Fixed argument propagation in SC2 legacy profile methods.
32
+
3
33
  **Version 0.6.3**
4
34
 
5
35
  Fixed argument propagation in some profile methods.
data/Gemfile.lock CHANGED
@@ -1,24 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blizzard_api (0.6.3)
4
+ blizzard_api (3.0.0)
5
5
  redis (~> 4.1, >= 4.1.0)
6
- thwait (~> 0.2.0)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
10
  ast (2.4.2)
12
11
  dotenv (2.7.6)
13
- e2mmap (0.1.0)
14
- minitest (5.14.4)
15
- parallel (1.20.1)
16
- parser (3.0.1.1)
12
+ minitest (5.15.0)
13
+ parallel (1.21.0)
14
+ parser (3.0.3.2)
17
15
  ast (~> 2.4.1)
18
16
  rainbow (3.0.0)
19
- rake (13.0.3)
20
- redis (4.2.5)
21
- regexp_parser (2.1.1)
17
+ rake (13.0.6)
18
+ redis (4.5.1)
19
+ regexp_parser (2.2.0)
22
20
  rexml (3.2.5)
23
21
  rubocop (0.93.1)
24
22
  parallel (~> 1.10)
@@ -29,13 +27,13 @@ GEM
29
27
  rubocop-ast (>= 0.6.0)
30
28
  ruby-progressbar (~> 1.7)
31
29
  unicode-display_width (>= 1.4.0, < 2.0)
32
- rubocop-ast (1.5.0)
30
+ rubocop-ast (1.15.1)
33
31
  parser (>= 3.0.1.1)
34
32
  ruby-progressbar (1.11.0)
35
- thwait (0.2.0)
36
- e2mmap
37
- unicode-display_width (1.7.0)
38
- yard (0.9.26)
33
+ unicode-display_width (1.8.0)
34
+ webrick (1.7.0)
35
+ yard (0.9.27)
36
+ webrick (~> 1.7.0)
39
37
 
40
38
  PLATFORMS
41
39
  ruby
data/blizzard_api.gemspec CHANGED
@@ -35,7 +35,6 @@ Gem::Specification.new do |spec|
35
35
  spec.require_paths = ['lib']
36
36
 
37
37
  spec.add_runtime_dependency 'redis', '~> 4.1', '>= 4.1.0'
38
- spec.add_runtime_dependency 'thwait', '~> 0.2.0'
39
38
 
40
39
  spec.add_development_dependency 'dotenv'
41
40
  spec.add_development_dependency 'minitest', '~> 5.0'
@@ -0,0 +1,24 @@
1
+ module BlizzardApi
2
+ ##
3
+ # Simple replacement for the http response object for cached data
4
+ class ApiResponse
5
+ attr_reader :code, :body
6
+
7
+ def initialize(body)
8
+ @code = 200
9
+ @body = body
10
+ end
11
+
12
+ def cached?
13
+ true
14
+ end
15
+ end
16
+ end
17
+
18
+ module Net
19
+ class HTTPResponse
20
+ def cached?
21
+ false
22
+ end
23
+ end
24
+ 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-#{region}" if options[:namespace].eql? :profile
51
+
52
+ raise ArgumentError, 'Invalid namespace scope'
53
+ end
54
+ end
55
+ end
@@ -23,6 +23,12 @@ module BlizzardApi
23
23
  # @return [String] Default region
24
24
  attr_accessor :region
25
25
 
26
+ ##
27
+ # @!attribute mode
28
+ # Api response mode :regular or :extended.
29
+ # @return [Symbol] Default API response mode
30
+ attr_accessor :mode
31
+
26
32
  ##
27
33
  # @!attribute use_cache
28
34
  # If true requests will be cached using a Redis server.
@@ -45,18 +51,17 @@ module BlizzardApi
45
51
  attr_accessor :redis_port
46
52
 
47
53
  ##
48
- #
49
- # @!attribute concurrency
50
- # How many threads to use for WoW game data `complete` payloads. Defaults to 4.
51
- # Should be set to the amount of available cores on the system.
52
- # @return [Integer] Concurrency
53
- attr_writer :concurrency
54
+ # @!attribute redis_database
55
+ # Redis databse.
56
+ # @see https://redis.io/
57
+ # @return [Integer] Redis database
58
+ attr_accessor :redis_database
54
59
 
55
60
  ##
56
- # @!attribute access_token
57
- # Access token. Optional. If you don't provide one it will be generate using your client credentials.
58
- # @return [String] Access token.
59
- attr_accessor :access_token
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
60
65
 
61
66
  ##
62
67
  # This method return the singleton instance of the configuration module. Use this to initialize the default values
@@ -73,18 +78,16 @@ module BlizzardApi
73
78
  # config.use_cache = true
74
79
  # config.redis_host = ENV['REDIS_HOST']
75
80
  # config.redis_port = ENV['REDIS_PORT']
76
- # config.format = :json
77
- #
78
- # config.icons_directory = './wow/icons'
79
- # config.guild_crest_directory = './wow/guild_crest'
80
- # config.wow_character_profile_directory = './wow/profile'
81
81
  # end
82
82
  def configure
83
83
  yield self
84
84
  end
85
85
 
86
- def concurrency
87
- @concurrency ||= 4
86
+ ##
87
+ # Initializes some default values for the main module
88
+ def self.extended(base)
89
+ base.redis_port = 1
90
+ base.mode = :regular
88
91
  end
89
92
  end
90
93
  end
@@ -4,8 +4,8 @@ module BlizzardApi
4
4
  module Diablo
5
5
  # Generic endpoint to support most data requests with minor configurations
6
6
  class GenericDataEndpoint < Diablo::Request
7
- def initialize(region = nil, mode = :regular)
8
- super region, mode
7
+ def initialize(**options)
8
+ super(**options)
9
9
  endpoint_setup
10
10
  @ttl ||= CACHE_DAY
11
11
  end
@@ -5,9 +5,9 @@ module BlizzardApi
5
5
  # Diablo III requests
6
6
  class Request < BlizzardApi::Request
7
7
  ##
8
- # @!macro regions
9
- def initialize(region = nil, mode = :regular)
10
- super region, mode
8
+ # @!macro init_options
9
+ def initialize(**options)
10
+ super(**options)
11
11
  @game = 'd3'
12
12
  end
13
13
  end
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ ##
4
+ # @!macro [new] init_options
5
+ # @param options [Hash] Initialization options
6
+ # @option options [String] :region API region
7
+ # @option options [Symbol] :model API mode (:regular, :extended)
8
+
3
9
  module BlizzardApi
4
10
  # Diablo III related classes
5
11
  module Diablo
@@ -11,17 +17,17 @@ module BlizzardApi
11
17
  require_relative 'diablo/game_data/era'
12
18
 
13
19
  ##
14
- # @param region [String] API Region
20
+ # @!macro init_options
15
21
  # @return {Season}
16
- def self.season(region = BlizzardApi.region)
17
- BlizzardApi::Diablo::Season.new(region)
22
+ def self.season(**options)
23
+ BlizzardApi::Diablo::Season.new(**options)
18
24
  end
19
25
 
20
26
  ##
21
- # @param region [String] API Region
27
+ # @!macro init_options
22
28
  # @return {Era}
23
- def self.era(region = BlizzardApi.region)
24
- BlizzardApi::Diablo::Era.new(region)
29
+ def self.era(**options)
30
+ BlizzardApi::Diablo::Era.new(**options)
25
31
  end
26
32
 
27
33
  # Diablo community api
@@ -34,52 +40,52 @@ module BlizzardApi
34
40
  require_relative 'diablo/community/profile'
35
41
 
36
42
  ##
37
- # @param region [String] API Region
43
+ # @!macro init_options
38
44
  # @return {Act}
39
- def self.act(region = BlizzardApi.region)
40
- BlizzardApi::Diablo::Act.new(region)
45
+ def self.act(**options)
46
+ BlizzardApi::Diablo::Act.new(**options)
41
47
  end
42
48
 
43
49
  ##
44
- # @param region [String] API Region
50
+ # @!macro init_options
45
51
  # @return {Artisan}
46
- def self.artisan(region = BlizzardApi.region)
47
- BlizzardApi::Diablo::Artisan.new(region)
52
+ def self.artisan(**options)
53
+ BlizzardApi::Diablo::Artisan.new(**options)
48
54
  end
49
55
 
50
56
  ##
51
- # @param region [String] API Region
57
+ # @!macro init_options
52
58
  # @return {Follower}
53
- def self.follower(region = BlizzardApi.region)
54
- BlizzardApi::Diablo::Follower.new(region)
59
+ def self.follower(**options)
60
+ BlizzardApi::Diablo::Follower.new(**options)
55
61
  end
56
62
 
57
63
  ##
58
- # @param region [String] API Region
64
+ # @!macro init_options
59
65
  # @return {Character}
60
- def self.character(region = BlizzardApi.region)
61
- BlizzardApi::Diablo::Character.new(region)
66
+ def self.character(**options)
67
+ BlizzardApi::Diablo::Character.new(**options)
62
68
  end
63
69
 
64
70
  ##
65
- # @param region [String] API Region
71
+ # @!macro init_options
66
72
  # @return {ItemType}
67
- def self.item_type(region = BlizzardApi.region)
68
- BlizzardApi::Diablo::ItemType.new(region)
73
+ def self.item_type(**options)
74
+ BlizzardApi::Diablo::ItemType.new(**options)
69
75
  end
70
76
 
71
77
  ##
72
- # @param region [String] API Region
78
+ # @!macro init_options
73
79
  # @return {Type}
74
- def self.item(region = BlizzardApi.region)
75
- BlizzardApi::Diablo::Item.new(region)
80
+ def self.item(**options)
81
+ BlizzardApi::Diablo::Item.new(**options)
76
82
  end
77
83
 
78
84
  ##
79
- # @param region [String] API Region
85
+ # @!macro init_options
80
86
  # @return {Profile}
81
- def self.profile(region = BlizzardApi.region)
82
- BlizzardApi::Diablo::Profile.new(region)
87
+ def self.profile(**options)
88
+ BlizzardApi::Diablo::Profile.new(**options)
83
89
  end
84
90
  end
85
91
  end
@@ -4,8 +4,8 @@ module BlizzardApi
4
4
  module Hearthstone
5
5
  # Generic endpoint to support most data requests with minor configurations
6
6
  class GenericDataEndpoint < Hearthstone::Request
7
- def initialize(region = nil, mode = :regular)
8
- super region, mode
7
+ def initialize(**options)
8
+ super(**options)
9
9
  endpoint_setup
10
10
  @ttl ||= CACHE_DAY
11
11
  end
@@ -5,9 +5,9 @@ module BlizzardApi
5
5
  # Hearthstone requests
6
6
  class Request < BlizzardApi::Request
7
7
  ##
8
- # @!macro regions
9
- def initialize(region = nil, mode = :regular)
10
- super region, mode
8
+ # @!macro init_options
9
+ def initialize(**options)
10
+ super(**options)
11
11
  @game = 'hearthstone'
12
12
  end
13
13
  end
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ ##
4
+ # @!macro [new] init_options
5
+ # @param options [Hash] Initialization options
6
+ # @option options [String] :region API region
7
+ # @option options [Symbol] :model API mode (:regular, :extended)
8
+
3
9
  module BlizzardApi
4
10
  # Hearthstone related classes
5
11
  module Hearthstone
@@ -13,31 +19,31 @@ module BlizzardApi
13
19
  require_relative 'hearthstone/game_data/metadata'
14
20
 
15
21
  ##
16
- # @param region [String] API Region
22
+ # @!macro init_options
17
23
  # @return {Card}
18
- def self.card(region = BlizzardApi.region)
19
- BlizzardApi::Hearthstone::Card.new(region)
24
+ def self.card(**options)
25
+ BlizzardApi::Hearthstone::Card.new(**options)
20
26
  end
21
27
 
22
28
  ##
23
- # @param region [String] API Region
29
+ # @!macro init_options
24
30
  # @return {Back}
25
- def self.back(region = BlizzardApi.region)
26
- BlizzardApi::Hearthstone::Back.new(region)
31
+ def self.back(**options)
32
+ BlizzardApi::Hearthstone::Back.new(**options)
27
33
  end
28
34
 
29
35
  ##
30
- # @param region [String] API Region
36
+ # @!macro init_options
31
37
  # @return {Deck}
32
- def self.deck(region = BlizzardApi.region)
33
- BlizzardApi::Hearthstone::Deck.new(region)
38
+ def self.deck(**options)
39
+ BlizzardApi::Hearthstone::Deck.new(**options)
34
40
  end
35
41
 
36
42
  ##
37
- # @param region [String] API Region
43
+ # @!macro init_options
38
44
  # @return {Metadata}
39
- def self.metadata(region = BlizzardApi.region)
40
- BlizzardApi::Hearthstone::Metadata.new(region)
45
+ def self.metadata(**options)
46
+ BlizzardApi::Hearthstone::Metadata.new(**options)
41
47
  end
42
48
  end
43
49
  end