blizzard_api 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c8fd5029d2b85e30104b35b0a1f4d7f6b2ea7d758b6388f2822408f94d3181c
4
- data.tar.gz: 2f74b10c6312c1c85479f99dc498f1eceb65f8afacad3f40a9a94e23d8da2bce
3
+ metadata.gz: 680ed6a0b92283da14b06fd82d2b68d907f54ae43286dcdadce49c59d5d2f006
4
+ data.tar.gz: 55533dafd67060eaa7c5100da709d9477941cbc3e1d110d01feb7384857bb791
5
5
  SHA512:
6
- metadata.gz: 25a95b728c6d08054858b1c3203bc8b5e5d3f7737ee8e5074e3f5253f1378c94b0e5970b740f9f29b152c67ec289857bb213842aeaaea519f91d7c9a89549328
7
- data.tar.gz: c99f65f0f4e15e9076d64dc825d30a55ae5ef7484d14b690065d85a8167329d704d6350594b0576251958b8e938362de589b8afa167ee2e2144c2805e09d017c
6
+ metadata.gz: 9f389ae7148b0e0527cbae0f00153e9db2d400496223c4c69a86149720115d39959e69365004914128a53072dc838bcec5161d9a436e880a7e96bd8ac39d5669
7
+ data.tar.gz: cbcfceaeab33b4a85e6c0fe6d408c2762e4cd0ba14fadb471eec2ff00e246e0982bcc7e3820d56c87788e0a011d2055e0b27fb0e4effbb795c0435b93bd0f1d1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  Please view this file on the master branch, otherwise it may be outdated
2
2
 
3
+ **Version 3.1.0**
4
+
5
+ Fixed the latest build to exclude non 200 responses from caching.
6
+
3
7
  **Version 3.0.0**
4
8
 
5
9
  Changed the way `:extended` mode is handled regarding caching. Now the extended mode will use cache and return a fake
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blizzard_api (3.0.0)
4
+ blizzard_api (3.1.0)
5
5
  redis (~> 4.1, >= 4.1.0)
6
6
 
7
7
  GEM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BlizzardApi
2
4
  ##
3
5
  # Simple replacement for the http response object for cached data
@@ -16,6 +18,7 @@ module BlizzardApi
16
18
  end
17
19
 
18
20
  module Net
21
+ # Workaround for fake response payloads
19
22
  class HTTPResponse
20
23
  def cached?
21
24
  false
@@ -9,7 +9,7 @@ module BlizzardApi
9
9
  #
10
10
  # You can get an instance of this class using the default region as follows:
11
11
  # api_instance = BlizzardApi::Diablo.character
12
- class Character < BlizzardApi::Diablo::Request
12
+ class CharacterClass < BlizzardApi::Diablo::Request
13
13
  ##
14
14
  # Return information about a class
15
15
  #
@@ -35,7 +35,7 @@ module BlizzardApi
35
35
  # Fetch leaderboard data for the current endpoint
36
36
  #
37
37
  # @param [Integer] id One of the IDs returned by the {index}
38
- # @param [Integer] leaderboard_id Leaderboard id
38
+ # @param [String] leaderboard_id Leaderboard id
39
39
  # @!macro request_options
40
40
  #
41
41
  # @!macro response
@@ -34,7 +34,7 @@ module BlizzardApi
34
34
  require_relative 'diablo/community/act'
35
35
  require_relative 'diablo/community/artisan'
36
36
  require_relative 'diablo/community/follower'
37
- require_relative 'diablo/community/character'
37
+ require_relative 'diablo/community/character_class'
38
38
  require_relative 'diablo/community/item_type'
39
39
  require_relative 'diablo/community/item'
40
40
  require_relative 'diablo/community/profile'
@@ -64,7 +64,7 @@ module BlizzardApi
64
64
  # @!macro init_options
65
65
  # @return {Character}
66
66
  def self.character(**options)
67
- BlizzardApi::Diablo::Character.new(**options)
67
+ BlizzardApi::Diablo::CharacterClass.new(**options)
68
68
  end
69
69
 
70
70
  ##
@@ -20,7 +20,7 @@ module BlizzardApi
20
20
  # @!macro request_options
21
21
  #
22
22
  # @!macro response
23
- def index(**options)
23
+ def search(**options)
24
24
  api_request "#{base_url(:community)}/#{@endpoint}/", **default_options.merge(options)
25
25
  end
26
26
 
@@ -82,7 +82,6 @@ module BlizzardApi
82
82
  def request(url, **options)
83
83
  # Creates the whole url for request
84
84
  parsed_url = URI.parse(url)
85
-
86
85
  data = using_cache?(options) ? find_in_cache(parsed_url.to_s) : nil
87
86
 
88
87
  # If data was found that means cache is enabled and valid
@@ -90,9 +89,20 @@ module BlizzardApi
90
89
 
91
90
  response = consume_api parsed_url, **options
92
91
 
93
- response_data = response.code.to_i.eql?(304) ? nil : response.body
94
- save_in_cache parsed_url.to_s, response.body, options[:ttl] || CACHE_DAY if using_cache? options
92
+ handle_cache_on_response parsed_url, response, **options
93
+ end
95
94
 
95
+ def handle_cache_on_response(parsed_url, response, **options)
96
+ case response.code.to_i
97
+ when 304
98
+ response_data = nil
99
+ when 200
100
+ response_data = response.body
101
+ else
102
+ return nil, response
103
+ end
104
+
105
+ save_in_cache parsed_url.to_s, response.body, options[:ttl] || CACHE_DAY if using_cache? options
96
106
  prepare_response response_data, response
97
107
  end
98
108
 
@@ -119,12 +129,12 @@ module BlizzardApi
119
129
 
120
130
  ##
121
131
  # Resolves the response based on the mode
122
- def prepare_response(data, response = false)
132
+ def prepare_response(data, response = nil)
123
133
  parsed_data = data.nil? ? data : JSON.parse(data, symbolize_names: true)
124
134
 
125
135
  return parsed_data unless mode.eql? :extended
126
136
 
127
- response = ApiResponse.new(data) unless response
137
+ response ||= ApiResponse.new(data)
128
138
 
129
139
  [response, parsed_data]
130
140
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module BlizzardApi
4
4
  # Gem version
5
- VERSION = '3.0.0'
5
+ VERSION = '3.1.0'
6
6
  end
@@ -13,7 +13,7 @@ module BlizzardApi
13
13
  setup 'guild-crest', :static, CACHE_TRIMESTER
14
14
 
15
15
  def get
16
- raise BlizzardApi::ApiException, 'This endpoint doens\'t have a get method'
16
+ raise BlizzardApi::ApiException, 'This endpoint does not have a get method'
17
17
  end
18
18
 
19
19
  ##
@@ -17,7 +17,7 @@ module BlizzardApi
17
17
  #
18
18
  # @!macro response
19
19
  def index
20
- raise BlizzardApi::ApiException, 'This endpoint does not have a index method'
20
+ raise BlizzardApi::ApiException, 'This endpoint does not have an index method'
21
21
  end
22
22
 
23
23
  ##
@@ -19,7 +19,7 @@ module BlizzardApi
19
19
  #
20
20
  # @!macro response
21
21
  def index
22
- raise BlizzardApi::ApiException, 'This endpoint does not have a index method'
22
+ raise BlizzardApi::ApiException, 'This endpoint does not have an index method'
23
23
  end
24
24
 
25
25
  ##
@@ -9,16 +9,11 @@ module BlizzardApi
9
9
  #
10
10
  # You can get an instance of this class using the default region as follows:
11
11
  # api_instance = BlizzardApi::Wow.wow_token
12
- class WowToken < Wow::Request
13
- ##
14
- # Returns wow token data
15
- #
16
- # @!macro request_options
17
- #
18
- # @!macro response
19
- def get(**options)
20
- opts = { namespace: :dynamic, ttl: CACHE_HOUR }.merge(options)
21
- api_request "#{base_url(:game_data)}/token/index", **opts
12
+ class WowToken < GenericDataEndpoint
13
+ setup 'token', :dynamic, CACHE_HOUR
14
+
15
+ def get
16
+ raise BlizzardApi::ApiException, 'This endpoint does not have a index method'
22
17
  end
23
18
  end
24
19
  end
@@ -13,7 +13,7 @@ module BlizzardApi
13
13
  include BlizzardApi::Wow::Slug
14
14
 
15
15
  ##
16
- # Return character achievements
16
+ # Return character basic data
17
17
  #
18
18
  # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
19
19
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blizzard_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Schiavo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-08 00:00:00.000000000 Z
11
+ date: 2022-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -127,7 +127,7 @@ files:
127
127
  - lib/blizzard_api/diablo.rb
128
128
  - lib/blizzard_api/diablo/community/act.rb
129
129
  - lib/blizzard_api/diablo/community/artisan.rb
130
- - lib/blizzard_api/diablo/community/character.rb
130
+ - lib/blizzard_api/diablo/community/character_class.rb
131
131
  - lib/blizzard_api/diablo/community/follower.rb
132
132
  - lib/blizzard_api/diablo/community/item.rb
133
133
  - lib/blizzard_api/diablo/community/item_type.rb