better-faraday 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6f0c2729ee0008d378633405c1b5b7ce2487d2ff16c78bce61973a4bc524a2f
4
- data.tar.gz: 3e5dc920399d735b9de37efd781430fa1f19ee51a2fc0d11d88cf3b0fe5771c8
3
+ metadata.gz: b4091f67de65133fa096eef795198cf51895c03ada658fb72e84fbfae2c14522
4
+ data.tar.gz: c79c87d6051648a39a58e91259bb78309e78368d9874ca4605d09152388b908f
5
5
  SHA512:
6
- metadata.gz: 72017939d4eaddce9514bb76d329ae2fba24e9bce2ed4d9bbbc51341f7b21adb68d6a5fa81222abff6d47faae49fb56e0ef1bf648cbc66a69a5553e419529782
7
- data.tar.gz: 426bab6ab085ca927e4e7999903286371308b00ce551ef60525555043e8807b2ea0e87f2392a12d8f1b8715474399be40261b490dd84e9eca6574c11f163cdb0
6
+ metadata.gz: 80c822fc52bc8bf778d37b769bbce32e2e7c75e3c94fb9a2098659f8b4d66e37df8c6e02c8c34b9f9bedc9f3fcaa7c64fa30de7c491a5f86f00fda575d1c3d65
7
+ data.tar.gz: bdca3821190b987e8de4f334c712c3380985b4c60f4703a261a821aceba6e4bb8cb7fef5b742153d65230f23d418ca87d77da0c4369957df56e67e002e2422c1
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.1
1
+ 2.7.3
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "better-faraday"
6
- s.version = "1.1.0"
6
+ s.version = "1.2.0"
7
7
  s.author = "Yaroslav Konoplov"
8
8
  s.email = "eahome00@gmail.com"
9
9
  s.summary = "Extends Faraday with useful features."
@@ -13,6 +13,6 @@ Gem::Specification.new do |s|
13
13
  s.files = `git ls-files -z`.split("\x0")
14
14
  s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
15
15
  s.require_paths = ["lib"]
16
- s.add_dependency "faraday", "~> 0.12"
17
- s.add_dependency "activesupport", ">= 4.0", "< 6.0"
16
+ s.add_dependency "faraday", ">= 1.0", "< 2.0"
17
+ s.add_dependency "activesupport", ">= 4.0", "< 7.0"
18
18
  end
@@ -71,10 +71,19 @@ module Faraday
71
71
  end
72
72
 
73
73
  def describe
74
- request_headers = __protect_data(env.request_headers.deep_dup)
75
- request_json = __protect_data(__parse_json(env.request_body))
76
- response_headers = __protect_data(::Hash === env.response_headers ? env.response_headers.deep_dup : {})
77
- response_json = __protect_data(__parse_json(env.body))
74
+ request_headers = __protect_data(env.request_headers.deep_dup)
75
+
76
+ if env.request_headers["Content-Type"].to_s.match?(/\bapplication\/json\b/)
77
+ request_json = __protect_data(__parse_json(env.request_body.dup))
78
+ end
79
+
80
+ if env.response_headers
81
+ response_headers = __protect_data(env.response_headers.deep_dup)
82
+ end
83
+
84
+ if env.response_headers && env.response_headers["Content-Type"].to_s.match?(/\bapplication\/json\b/)
85
+ response_json = __protect_data(__parse_json(env.body.dup))
86
+ end
78
87
 
79
88
  lines = [
80
89
  "",
@@ -89,17 +98,43 @@ module Faraday
89
98
  "-- Request headers --",
90
99
  ::JSON.generate(request_headers).yield_self { |t| t.truncate(2048, omission: "... (truncated, full length: #{t.length})") },
91
100
  "",
101
+
92
102
  "-- Request body --",
93
- (request_json ? ::JSON.generate(request_json) : env.request_body.to_s).yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
103
+ if request_json
104
+ ::JSON.generate(request_json)
105
+ else
106
+ body = env.request_body.to_s.dup
107
+ if body.encoding.name == "ASCII-8BIT"
108
+ "Binary (#{body.size} bytes)"
109
+ else
110
+ body
111
+ end
112
+ end.yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
94
113
  "",
114
+
95
115
  "-- Request sent at --",
96
116
  env.request_sent_at.strftime("%Y-%m-%d %H:%M:%S.%2N") + " UTC",
97
117
  "",
118
+
98
119
  "-- Response headers --",
99
- (response_headers ? ::JSON.generate(response_headers) : env.response_headers.to_s).yield_self { |t| t.truncate(2048, omission: "... (truncated, full length: #{t.length})") },
120
+ if response_headers
121
+ ::JSON.generate(response_headers)
122
+ else
123
+ env.response_headers.to_s
124
+ end.yield_self { |t| t.truncate(2048, omission: "... (truncated, full length: #{t.length})") },
100
125
  "",
126
+
101
127
  "-- Response body --",
102
- (response_json ? ::JSON.generate(response_json) : env.body.to_s).yield_self { |t| t.truncate(2048, omission: "... (truncated, full length: #{t.length})") }
128
+ if response_json
129
+ ::JSON.generate(response_json)
130
+ else
131
+ body = env.body.to_s.dup
132
+ if body.encoding.name == "ASCII-8BIT"
133
+ "Binary (#{body.size} bytes)"
134
+ else
135
+ body
136
+ end
137
+ end.yield_self { |t| t.truncate(2048, omission: "... (truncated, full length: #{t.length})") }
103
138
  ]
104
139
 
105
140
  if env.response_received_at
@@ -113,9 +148,11 @@ module Faraday
113
148
  ]
114
149
  end
115
150
 
116
- lines.join("\n")
151
+ lines.join("\n") + "\n"
117
152
  end
118
153
 
154
+ alias inspect describe
155
+
119
156
  private
120
157
 
121
158
  def __parse_json(json)
@@ -130,7 +167,7 @@ module Faraday
130
167
  return data.map(&method(:__protect_data)) if ::Array === data
131
168
  return data unless ::Hash === data
132
169
  data.each_with_object({}) do |(key, value), memo|
133
- memo[key] = if key.respond_to?(:=~) && Faraday.secrets.any? { |s| key =~ s }
170
+ memo[key] = if key.to_s.underscore.tr("_", " ").yield_self { |k| Faraday::Inspection.secrets.any? { |s| k.match?(s) } }
134
171
  "SECRET"
135
172
  else
136
173
  __protect_data(value)
@@ -147,9 +184,21 @@ module Faraday
147
184
  class HTTP422 < HTTP4xx; end
148
185
  class HTTP429 < HTTP4xx; end
149
186
 
150
- class << self
151
- attr_accessor :secrets
187
+ module Inspection
188
+ class << self
189
+ attr_accessor :secrets
190
+ end
191
+
192
+ self.secrets = [/\bpass(?:word|phrase)\b/i, /\bauthorization\b/i, /\bsecret\b/i, /\b(:?access)?token\b/i]
152
193
  end
153
194
 
154
- self.secrets = [/\bpass(?:word|phrase)\b/i, /\bauthorization\b/i, /\bsecret\b/i, /\b(:?access?)token\b/i]
195
+ class << self
196
+ def secrets
197
+ Inspection.secrets
198
+ end
199
+
200
+ def secrets=(value)
201
+ Inspection.secrets = value
202
+ end
203
+ end
155
204
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better-faraday
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
  - Yaroslav Konoplov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-20 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '0.12'
22
+ version: '2.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '0.12'
32
+ version: '2.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: activesupport
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -33,7 +39,7 @@ dependencies:
33
39
  version: '4.0'
34
40
  - - "<"
35
41
  - !ruby/object:Gem::Version
36
- version: '6.0'
42
+ version: '7.0'
37
43
  type: :runtime
38
44
  prerelease: false
39
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +49,7 @@ dependencies:
43
49
  version: '4.0'
44
50
  - - "<"
45
51
  - !ruby/object:Gem::Version
46
- version: '6.0'
52
+ version: '7.0'
47
53
  description: A gem extending Faraday (popular Ruby HTTP client) with useful features
48
54
  without breaking anything.
49
55
  email: eahome00@gmail.com
@@ -76,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
82
  - !ruby/object:Gem::Version
77
83
  version: '0'
78
84
  requirements: []
79
- rubygems_version: 3.0.3
85
+ rubygems_version: 3.1.6
80
86
  signing_key:
81
87
  specification_version: 4
82
88
  summary: Extends Faraday with useful features.