blizzard_api 2.0.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/lib/blizzard_api/api_response.rb +24 -0
- data/lib/blizzard_api/request.rb +18 -7
- data/lib/blizzard_api/version.rb +1 -1
- data/lib/blizzard_api.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c8fd5029d2b85e30104b35b0a1f4d7f6b2ea7d758b6388f2822408f94d3181c
|
4
|
+
data.tar.gz: 2f74b10c6312c1c85479f99dc498f1eceb65f8afacad3f40a9a94e23d8da2bce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25a95b728c6d08054858b1c3203bc8b5e5d3f7737ee8e5074e3f5253f1378c94b0e5970b740f9f29b152c67ec289857bb213842aeaaea519f91d7c9a89549328
|
7
|
+
data.tar.gz: c99f65f0f4e15e9076d64dc825d30a55ae5ef7484d14b690065d85a8167329d704d6350594b0576251958b8e938362de589b8afa167ee2e2144c2805e09d017c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
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
|
+
|
3
12
|
**Version 2.0.0**
|
4
13
|
|
5
14
|
Removed the `icon` field from PlayableClass, it was meant to mimic the old communit API behavior during the transition
|
data/Gemfile.lock
CHANGED
@@ -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
|
data/lib/blizzard_api/request.rb
CHANGED
@@ -86,16 +86,14 @@ module BlizzardApi
|
|
86
86
|
data = using_cache?(options) ? find_in_cache(parsed_url.to_s) : nil
|
87
87
|
|
88
88
|
# If data was found that means cache is enabled and valid
|
89
|
-
return
|
89
|
+
return prepare_response data if data
|
90
90
|
|
91
91
|
response = consume_api parsed_url, **options
|
92
92
|
|
93
|
+
response_data = response.code.to_i.eql?(304) ? nil : response.body
|
93
94
|
save_in_cache parsed_url.to_s, response.body, options[:ttl] || CACHE_DAY if using_cache? options
|
94
95
|
|
95
|
-
response_data
|
96
|
-
return [response, response_data] if mode.eql? :extended
|
97
|
-
|
98
|
-
response_data
|
96
|
+
prepare_response response_data, response
|
99
97
|
end
|
100
98
|
|
101
99
|
def api_request(uri, **query_string)
|
@@ -110,7 +108,7 @@ module BlizzardApi
|
|
110
108
|
|
111
109
|
# In case uri already have query string parameters joins them with &
|
112
110
|
if query_string.size.positive?
|
113
|
-
query_string = URI.encode_www_form(query_string
|
111
|
+
query_string = URI.encode_www_form(query_string)
|
114
112
|
uri = uri.include?('?') ? "#{uri}&#{query_string}" : "#{uri}?#{query_string}"
|
115
113
|
end
|
116
114
|
|
@@ -119,10 +117,22 @@ module BlizzardApi
|
|
119
117
|
|
120
118
|
private
|
121
119
|
|
120
|
+
##
|
121
|
+
# Resolves the response based on the mode
|
122
|
+
def prepare_response(data, response = false)
|
123
|
+
parsed_data = data.nil? ? data : JSON.parse(data, symbolize_names: true)
|
124
|
+
|
125
|
+
return parsed_data unless mode.eql? :extended
|
126
|
+
|
127
|
+
response = ApiResponse.new(data) unless response
|
128
|
+
|
129
|
+
[response, parsed_data]
|
130
|
+
end
|
131
|
+
|
122
132
|
##
|
123
133
|
# @param options [Hash] Request options
|
124
134
|
def using_cache?(options)
|
125
|
-
return false if
|
135
|
+
return false if options.key?(:since)
|
126
136
|
|
127
137
|
!options.fetch(:ignore_cache, false)
|
128
138
|
end
|
@@ -130,6 +140,7 @@ module BlizzardApi
|
|
130
140
|
def http_connection(url)
|
131
141
|
Net::HTTP.new(url.host, url.port).tap do |http|
|
132
142
|
http.use_ssl = true
|
143
|
+
http.keep_alive_timeout = 30
|
133
144
|
end
|
134
145
|
end
|
135
146
|
|
data/lib/blizzard_api/version.rb
CHANGED
data/lib/blizzard_api.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'blizzard_api/configuration'
|
4
4
|
require_relative 'blizzard_api/token_manager'
|
5
5
|
require_relative 'blizzard_api/api_standards'
|
6
|
+
require_relative 'blizzard_api/api_response'
|
6
7
|
require_relative 'blizzard_api/request'
|
7
8
|
require_relative 'blizzard_api/exception'
|
8
9
|
require_relative 'blizzard_api/version'
|
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:
|
4
|
+
version: 3.0.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-
|
11
|
+
date: 2022-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- bin/setup
|
122
122
|
- blizzard_api.gemspec
|
123
123
|
- lib/blizzard_api.rb
|
124
|
+
- lib/blizzard_api/api_response.rb
|
124
125
|
- lib/blizzard_api/api_standards.rb
|
125
126
|
- lib/blizzard_api/configuration.rb
|
126
127
|
- lib/blizzard_api/diablo.rb
|