better-faraday 1.0.6 → 1.0.7
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/better-faraday.gemspec +1 -1
- data/lib/better-faraday.rb +34 -14
- 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: 566a4665f7f21fbc42e2ab20190caf5d87d3d49d775ac376135c273728132334
|
4
|
+
data.tar.gz: 4ab4177eb90929e0c3f1f89aa8418c74af97120770c68595cf6ba630e9d8894c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c459e43aed401c92e6e57957c057bfef94a4194dfb77bb789e3d5466cd99153f17a43b883a9a5896c3c0c5a074ab42f39ddda0ae749bc33744c40aebeb34054
|
7
|
+
data.tar.gz: ceddc5b83c55fc7546b0dd2c6edb88a9711f8308c7c9363f1868b32b67e419b9b44ad41b0a6a3c8a114c34b2497a6db11b79d924a45a64c0ec128c56340f95db
|
data/better-faraday.gemspec
CHANGED
data/lib/better-faraday.rb
CHANGED
@@ -31,9 +31,9 @@ module Faraday
|
|
31
31
|
|
32
32
|
class Response
|
33
33
|
def assert_2xx!
|
34
|
-
return self if
|
34
|
+
return self if status_2xx?
|
35
35
|
|
36
|
-
klass = if
|
36
|
+
klass = if status_4xx?
|
37
37
|
"Faraday::HTTP#{status}".safe_constantize || Faraday::HTTP4xx
|
38
38
|
else
|
39
39
|
Faraday::Error
|
@@ -47,12 +47,27 @@ module Faraday
|
|
47
47
|
alias ok! assert_2xx! # Short name.
|
48
48
|
alias assert_success! assert_2xx! # Compatibility.
|
49
49
|
|
50
|
+
def status_2xx?
|
51
|
+
status >= 200 && status <= 299
|
52
|
+
end
|
53
|
+
|
54
|
+
def status_3xx?
|
55
|
+
status >= 300 && status <= 399
|
56
|
+
end
|
57
|
+
|
58
|
+
def status_4xx?
|
59
|
+
status >= 400 && status <= 499
|
60
|
+
end
|
61
|
+
|
62
|
+
def status_5xx?
|
63
|
+
status >= 500 && status <= 599
|
64
|
+
end
|
65
|
+
|
50
66
|
def describe
|
51
|
-
request_headers = env.request_headers.deep_dup
|
52
|
-
request_json = parse_json(env.request_body)
|
53
|
-
response_headers = ::Hash === env.response_headers ? env.response_headers.deep_dup : {}
|
54
|
-
response_json =
|
55
|
-
[request_headers, request_json, response_headers, response_json].compact.each(&method(:protect!))
|
67
|
+
request_headers = __protect_data(env.request_headers.deep_dup)
|
68
|
+
request_json = __protect_data(parse_json(env.request_body))
|
69
|
+
response_headers = __protect_data(::Hash === env.response_headers ? env.response_headers.deep_dup : {})
|
70
|
+
response_json = __protect_data(__parse_json(env.body))
|
56
71
|
|
57
72
|
[ "",
|
58
73
|
"-- #{status} #{reason_phrase} --",
|
@@ -80,18 +95,23 @@ module Faraday
|
|
80
95
|
|
81
96
|
private
|
82
97
|
|
83
|
-
def
|
84
|
-
|
98
|
+
def __parse_json(json)
|
99
|
+
return nil unless ::String === json
|
100
|
+
data = ::JSON.parse(json)
|
85
101
|
data if ::Hash === data || ::Array === data
|
86
102
|
rescue ::JSON::ParserError
|
87
103
|
nil
|
88
104
|
end
|
89
105
|
|
90
|
-
def
|
91
|
-
return
|
92
|
-
|
93
|
-
|
94
|
-
|
106
|
+
def __protect_data(data)
|
107
|
+
return data.map(&method(:__protect_data)) if ::Array === data
|
108
|
+
return data unless ::Hash === data
|
109
|
+
data.each_with_object({}) do |(key, value), memo|
|
110
|
+
memo[key] = if key.respond_to?(:=~) && Faraday.secrets.any? { |s| key =~ s }
|
111
|
+
"SECRET"
|
112
|
+
else
|
113
|
+
__protect_data(value)
|
114
|
+
end
|
95
115
|
end
|
96
116
|
end
|
97
117
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better-faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Konoplov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
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.
|
79
|
+
rubygems_version: 3.0.3
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Extends Faraday with useful features.
|