faraday_middleware 1.1.0 → 1.2.1
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/README.md +15 -2
- data/lib/faraday_middleware/response/caching.rb +16 -7
- data/lib/faraday_middleware/version.rb +1 -1
- data/lib/faraday_middleware.rb +7 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b8d5f2f821f7c0f8ed6326ad5e93dbc2865a84544cf2974b707b63afe9b13bd
|
4
|
+
data.tar.gz: a0ca51cea4bab75193f38f8bcaa1cd62058137b4bdb9002b97fb6a9271bd25a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 774928e8114a49d941e8b8863ba874395a8c3d1d57b17f7b813e0f5cbccb7133197d11013338780712c9b49868a9fe8e476fee8ade2f0065d9d188e1ae0f1ab9
|
7
|
+
data.tar.gz: 33ff16c6a46beeb4fd2580729559f0558802c909191faf800a79a89cb0fdf9893a424489aeffc2dd8089cbf91328a8f57a4ecbf0ef300b067663d74a7e733815
|
data/README.md
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
Faraday Middleware
|
2
2
|
==================
|
3
|
-
|
4
|
-
](https://github.com/lostisland/faraday_middleware/actions/workflows/ci.yml)
|
5
5
|
|
6
6
|
A collection of useful [Faraday][] middleware. [See the documentation][docs].
|
7
7
|
|
8
8
|
gem install faraday_middleware
|
9
9
|
|
10
|
+
## ⚠️ DEPRECATION WARNING ⚠️
|
11
|
+
|
12
|
+
As highlighted in Faraday's [UPGRADING](https://github.com/lostisland/faraday/blob/main/UPGRADING.md) guide, `faraday_middleware` is DEPRECATED, and will not be updated to support Faraday 2.0.
|
13
|
+
If you rely on `faraday_middleware` in your project and would like to support Faraday 2.0:
|
14
|
+
* The `json` middleware (request and response) are now both bundled with Faraday 🙌
|
15
|
+
* The `instrumentation` middleware is bundled with Faraday
|
16
|
+
* All other middlewares, they'll be re-released as independent gems compatible with both Faraday v1 and v2, look for [`awesome-faraday`](https://github.com/lostisland/awesome-faraday)
|
17
|
+
|
18
|
+
Most of the middlewares are up for adoption, contributors that would like to maintain them.
|
19
|
+
If you'd like to maintain any middleware, have any question or need any help, we're here!
|
20
|
+
Please reach out opening an issue or a discussion.
|
21
|
+
|
22
|
+
|
10
23
|
Dependencies
|
11
24
|
------------
|
12
25
|
|
@@ -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
|
-
#
|
31
|
-
#
|
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
|
-
#
|
34
|
-
#
|
35
|
-
#
|
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
|
-
#
|
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
|
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])
|
data/lib/faraday_middleware.rb
CHANGED
@@ -27,13 +27,11 @@ module FaradayMiddleware
|
|
27
27
|
Faraday::Request.register_middleware \
|
28
28
|
oauth: -> { OAuth },
|
29
29
|
oauth2: -> { OAuth2 },
|
30
|
-
json: -> { EncodeJson },
|
31
30
|
method_override: -> { MethodOverride }
|
32
31
|
|
33
32
|
Faraday::Response.register_middleware \
|
34
33
|
mashify: -> { Mashify },
|
35
34
|
rashify: -> { Rashify },
|
36
|
-
json: -> { ParseJson },
|
37
35
|
json_fix: -> { ParseJson::MimeTypeFix },
|
38
36
|
xml: -> { ParseXml },
|
39
37
|
marshal: -> { ParseMarshal },
|
@@ -46,6 +44,13 @@ module FaradayMiddleware
|
|
46
44
|
Faraday::Middleware.register_middleware \
|
47
45
|
instrumentation: -> { Instrumentation },
|
48
46
|
gzip: -> { Gzip }
|
47
|
+
|
48
|
+
# The request/reponse JSON middleware is included in Faraday since
|
49
|
+
# version 1.10.0, so we only register the middleware if it's not already.
|
50
|
+
if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('1.10.0')
|
51
|
+
Faraday::Request.register_middleware(json: -> { EncodeJson })
|
52
|
+
Faraday::Response.register_middleware(json: -> { ParseJson })
|
53
|
+
end
|
49
54
|
end
|
50
55
|
end
|
51
56
|
|
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
|
4
|
+
version: 1.2.1
|
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:
|
12
|
+
date: 2024-09-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.1.6
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Various middleware for Faraday
|