faraday_middleware 1.0.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 +4 -4
- data/README.md +6 -7
- data/lib/faraday_middleware/rack_compatible.rb +1 -3
- data/lib/faraday_middleware/request/encode_json.rb +1 -1
- data/lib/faraday_middleware/request/oauth.rb +1 -3
- data/lib/faraday_middleware/request/oauth2.rb +1 -3
- data/lib/faraday_middleware/response/caching.rb +17 -7
- data/lib/faraday_middleware/response/follow_redirects.rb +1 -1
- data/lib/faraday_middleware/response_middleware.rb +2 -4
- data/lib/faraday_middleware/version.rb +1 -1
- 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: b9533a5d53e299a95e8b2aa19d277ac32ed800930c0abd4d92c67f025c98101d
|
4
|
+
data.tar.gz: 7261d4f25c4e0edeaaba0718947af74439d2fef8a114278a74f8de63f0f6c575
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ae2e4ea996bb4a2ad2762a7c0812c8734879205adb05eb88aed062f0be24b26fa18de82e6cc33c7c86dfc8f7c4fa8694522732c457643c8a4d3991e50ac095a
|
7
|
+
data.tar.gz: 512f5e9888e8adf5ac0d93c501470028079b463e407697353d55ef603b3a2590f46b9a6530a0a688a54e391fe9033302551f133b6d216281bf01c451e1a73f85
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@ Faraday Middleware
|
|
2
2
|
==================
|
3
3
|
[](https://rubygems.org/gems/faraday_middleware)
|
4
4
|

|
5
|
-
[](https://codeclimate.com/github/lostisland/faraday_middleware/maintainability)
|
6
5
|
|
7
6
|
A collection of useful [Faraday][] middleware. [See the documentation][docs].
|
8
7
|
|
@@ -19,12 +18,12 @@ Some dependent libraries are needed only when using specific middleware:
|
|
19
18
|
|
20
19
|
| Middleware | Library | Notes |
|
21
20
|
| --------------------------- | -------------- | ----- |
|
22
|
-
| [FaradayMiddleware::Instrumentation](https://github.com/lostisland/faraday_middleware/blob/
|
23
|
-
| [FaradayMiddleware::OAuth](https://github.com/lostisland/faraday_middleware/blob/
|
24
|
-
| [FaradayMiddleware::ParseXml](https://github.com/lostisland/faraday_middleware/blob/
|
25
|
-
| [FaradayMiddleware::ParseYaml](https://github.com/lostisland/faraday_middleware/blob/
|
26
|
-
| [FaradayMiddleware::Mashify](https://github.com/lostisland/faraday_middleware/blob/
|
27
|
-
| [FaradayMiddleware::Rashify](https://github.com/lostisland/faraday_middleware/blob/
|
21
|
+
| [FaradayMiddleware::Instrumentation](https://github.com/lostisland/faraday_middleware/blob/main/lib/faraday_middleware/instrumentation.rb) | [`activesupport`](https://rubygems.org/gems/activesupport) | |
|
22
|
+
| [FaradayMiddleware::OAuth](https://github.com/lostisland/faraday_middleware/blob/main/lib/faraday_middleware/request/oauth.rb) | [`simple_oauth`](https://rubygems.org/gems/simple_oauth) | |
|
23
|
+
| [FaradayMiddleware::ParseXml](https://github.com/lostisland/faraday_middleware/blob/main/lib/faraday_middleware/response/parse_xml.rb) | [`multi_xml`](https://rubygems.org/gems/multi_xml) | |
|
24
|
+
| [FaradayMiddleware::ParseYaml](https://github.com/lostisland/faraday_middleware/blob/main/lib/faraday_middleware/response/parse_yaml.rb) | [`safe_yaml`](https://rubygems.org/gems/safe_yaml) | Not backwards compatible with versions of this middleware prior to `faraday_middleware` v0.12. See code comments for alternatives. |
|
25
|
+
| [FaradayMiddleware::Mashify](https://github.com/lostisland/faraday_middleware/blob/main/lib/faraday_middleware/response/mashify.rb) | [`hashie`](https://rubygems.org/gems/hashie) | |
|
26
|
+
| [FaradayMiddleware::Rashify](https://github.com/lostisland/faraday_middleware/blob/main/lib/faraday_middleware/response/rashify.rb) | [`rash_alt`](https://rubygems.org/gems/rash_alt) | Make sure to uninstall original `rash` gem to avoid conflict. |
|
28
27
|
|
29
28
|
Examples
|
30
29
|
--------
|
@@ -80,9 +80,7 @@ module FaradayMiddleware
|
|
80
80
|
def finalize_response(env, rack_response)
|
81
81
|
status, headers, body = rack_response
|
82
82
|
body = body.inject { |str, part| str << part }
|
83
|
-
unless headers.is_a?(Faraday::Utils::Headers)
|
84
|
-
headers = Faraday::Utils::Headers.new(headers)
|
85
|
-
end
|
83
|
+
headers = Faraday::Utils::Headers.new(headers) unless headers.is_a?(Faraday::Utils::Headers)
|
86
84
|
|
87
85
|
env.update status: status.to_i,
|
88
86
|
body: body,
|
@@ -38,9 +38,7 @@ module FaradayMiddleware
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def call(env)
|
41
|
-
if sign_request?(env)
|
42
|
-
env[:request_headers][AUTH_HEADER] ||= oauth_header(env).to_s
|
43
|
-
end
|
41
|
+
env[:request_headers][AUTH_HEADER] ||= oauth_header(env).to_s if sign_request?(env)
|
44
42
|
@app.call(env)
|
45
43
|
end
|
46
44
|
|
@@ -63,9 +63,7 @@ module FaradayMiddleware
|
|
63
63
|
@param_name = options.fetch(:param_name, PARAM_NAME).to_s
|
64
64
|
@token_type = options.fetch(:token_type, TOKEN_TYPE).to_s
|
65
65
|
|
66
|
-
if @token_type == 'param' && @param_name.empty?
|
67
|
-
raise ArgumentError, ":param_name can't be blank"
|
68
|
-
end
|
66
|
+
raise ArgumentError, ":param_name can't be blank" if @token_type == 'param' && @param_name.empty?
|
69
67
|
|
70
68
|
return unless options[:token_type].nil?
|
71
69
|
|
@@ -8,6 +8,7 @@ module FaradayMiddleware
|
|
8
8
|
# Public: Caches GET responses and pulls subsequent ones from the cache.
|
9
9
|
class Caching < Faraday::Middleware
|
10
10
|
attr_reader :cache
|
11
|
+
|
11
12
|
# Internal: List of status codes that can be cached:
|
12
13
|
# * 200 - 'OK'
|
13
14
|
# * 203 - 'Non-Authoritative Information'
|
@@ -26,14 +27,16 @@ module FaradayMiddleware
|
|
26
27
|
# cache - An object that responds to read and write (default: nil).
|
27
28
|
# options - An options Hash (default: {}):
|
28
29
|
# :ignore_params - String name or Array names of query
|
29
|
-
#
|
30
|
-
#
|
30
|
+
# params that should be ignored when forming
|
31
|
+
# the cache key (default: []).
|
31
32
|
# :write_options - Hash of settings that should be passed as the
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
33
|
+
# third options parameter to the cache's #write
|
34
|
+
# method. If not specified, no options parameter
|
35
|
+
# will be passed.
|
35
36
|
# :full_key - Boolean - use full URL as cache key:
|
36
|
-
#
|
37
|
+
# (url.host + url.request_uri)
|
38
|
+
# :status_codes - Array of http status code to be cache
|
39
|
+
# (default: CACHEABLE_STATUS_CODE)
|
37
40
|
#
|
38
41
|
# Yields if no cache is given. The block should return a cache object.
|
39
42
|
def initialize(app, cache = nil, options = {})
|
@@ -85,6 +88,13 @@ module FaradayMiddleware
|
|
85
88
|
@full_key ||= @options[:full_key]
|
86
89
|
end
|
87
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
|
+
|
88
98
|
def cache_on_complete(env)
|
89
99
|
key = cache_key(env)
|
90
100
|
if (cached_response = cache.read(key))
|
@@ -100,7 +110,7 @@ module FaradayMiddleware
|
|
100
110
|
end
|
101
111
|
|
102
112
|
def store_response_in_cache(key, response)
|
103
|
-
return unless
|
113
|
+
return unless custom_status_codes.include?(response.status)
|
104
114
|
|
105
115
|
if @options[:write_options]
|
106
116
|
cache.write(key, response, @options[:write_options])
|
@@ -133,7 +133,7 @@ module FaradayMiddleware
|
|
133
133
|
def safe_escape(uri)
|
134
134
|
uri = uri.split('#')[0] # we want to remove the fragment if present
|
135
135
|
uri.to_s.gsub(URI_UNSAFE) do |match|
|
136
|
-
|
136
|
+
"%#{match.unpack('H2' * match.bytesize).join('%').upcase}"
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
@@ -34,9 +34,7 @@ module FaradayMiddleware
|
|
34
34
|
|
35
35
|
def call(environment)
|
36
36
|
@app.call(environment).on_complete do |env|
|
37
|
-
if process_response_type?(response_type(env)) && parse_response?(env)
|
38
|
-
process_response(env)
|
39
|
-
end
|
37
|
+
process_response(env) if process_response_type?(response_type(env)) && parse_response?(env)
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
@@ -44,7 +42,7 @@ module FaradayMiddleware
|
|
44
42
|
env[:raw_body] = env[:body] if preserve_raw?(env)
|
45
43
|
env[:body] = parse(env[:body])
|
46
44
|
rescue Faraday::ParsingError => e
|
47
|
-
raise Faraday::ParsingError.new(e, env[:response])
|
45
|
+
raise Faraday::ParsingError.new(e.wrapped_exception, env[:response])
|
48
46
|
end
|
49
47
|
|
50
48
|
# Parse the response body.
|
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.
|
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:
|
12
|
+
date: 2021-10-14 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.0.3
|
79
|
+
rubygems_version: 3.0.3.1
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Various middleware for Faraday
|