faraday_middleware 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b061911e8925a657ce571d5d3a096e6a9b43e8abcca0bec121fc81edb3b65c7
4
- data.tar.gz: 4722349158a61b9ee4789fc1046596ac80a44a7dd76eba178cb32330a5583a9b
3
+ metadata.gz: b9533a5d53e299a95e8b2aa19d277ac32ed800930c0abd4d92c67f025c98101d
4
+ data.tar.gz: 7261d4f25c4e0edeaaba0718947af74439d2fef8a114278a74f8de63f0f6c575
5
5
  SHA512:
6
- metadata.gz: 3d331ca5a71fda7702da83967033355c6ad896ea6026af78e248bf21c027a7f4287ab117ae81cb9dad0c0dc2d50eaaba1ab1a02f6a54a15436970e9c4232306f
7
- data.tar.gz: 49b8a45c1aa7e06764bc5433b83f469544c509c7c372bc986dadd497dd987054d5e02160d5019679b23acd068b32bd7c86c09498f2e29b9ccdca6376b316f634
6
+ metadata.gz: 9ae2e4ea996bb4a2ad2762a7c0812c8734879205adb05eb88aed062f0be24b26fa18de82e6cc33c7c86dfc8f7c4fa8694522732c457643c8a4d3991e50ac095a
7
+ data.tar.gz: 512f5e9888e8adf5ac0d93c501470028079b463e407697353d55ef603b3a2590f46b9a6530a0a688a54e391fe9033302551f133b6d216281bf01c451e1a73f85
@@ -27,14 +27,16 @@ module FaradayMiddleware
27
27
  # cache - An object that responds to read and write (default: nil).
28
28
  # options - An options Hash (default: {}):
29
29
  # :ignore_params - String name or Array names of query
30
- # params that should be ignored when forming
31
- # the cache key (default: []).
30
+ # params that should be ignored when forming
31
+ # the cache key (default: []).
32
32
  # :write_options - Hash of settings that should be passed as the
33
- # third options parameter to the cache's #write
34
- # method. If not specified, no options parameter
35
- # will be passed.
33
+ # third options parameter to the cache's #write
34
+ # method. If not specified, no options parameter
35
+ # will be passed.
36
36
  # :full_key - Boolean - use full URL as cache key:
37
- # (url.host + url.request_uri)
37
+ # (url.host + url.request_uri)
38
+ # :status_codes - Array of http status code to be cache
39
+ # (default: CACHEABLE_STATUS_CODE)
38
40
  #
39
41
  # Yields if no cache is given. The block should return a cache object.
40
42
  def initialize(app, cache = nil, options = {})
@@ -86,6 +88,13 @@ module FaradayMiddleware
86
88
  @full_key ||= @options[:full_key]
87
89
  end
88
90
 
91
+ def custom_status_codes
92
+ @custom_status_codes ||= begin
93
+ codes = CACHEABLE_STATUS_CODES & Array(@options[:status_codes]).map(&:to_i)
94
+ codes.any? ? codes : CACHEABLE_STATUS_CODES
95
+ end
96
+ end
97
+
89
98
  def cache_on_complete(env)
90
99
  key = cache_key(env)
91
100
  if (cached_response = cache.read(key))
@@ -101,7 +110,7 @@ module FaradayMiddleware
101
110
  end
102
111
 
103
112
  def store_response_in_cache(key, response)
104
- return unless CACHEABLE_STATUS_CODES.include?(response.status)
113
+ return unless custom_status_codes.include?(response.status)
105
114
 
106
115
  if @options[:write_options]
107
116
  cache.write(key, response, @options[:write_options])
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Main FaradayMiddleware module.
4
4
  module FaradayMiddleware
5
- VERSION = '1.1.0' unless defined?(FaradayMiddleware::VERSION)
5
+ VERSION = '1.2.0' unless defined?(FaradayMiddleware::VERSION)
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday_middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Michaels-Ober
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-07-31 00:00:00.000000000 Z
12
+ date: 2021-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday