better-faraday 1.0.8 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/better-faraday.gemspec +3 -3
- data/lib/better-faraday.rb +79 -19
- metadata +15 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30c3a63862a5faff00055d0f7fa905b8a67bcb85b3197929a0dcc1b7cce84d5c
|
4
|
+
data.tar.gz: 1d21b6f8fc0ce3efa6dcfec7fcec79e490a27a7c8b48b8a5d97e6d27d196ef26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 181d98b5697219d6bc095d275c0335438b148dd0ddf3e0d08d97855c5f4457731d541d83e19d3c8b3b187023171621baffe13d03417a00d4be50a414809a3d0e
|
7
|
+
data.tar.gz: fcaa327eb416c1ec95e8df522e580a92809ff927f043402f9c998a2797e19eda91b666261280edf89ccf08bfb8c58822399211ba6b8d899d9647b8cf28273001
|
data/better-faraday.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "better-faraday"
|
6
|
-
s.version = "1.
|
6
|
+
s.version = "1.1.4"
|
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", "
|
17
|
-
s.add_dependency "activesupport", ">= 4.0", "<
|
16
|
+
s.add_dependency "faraday", ">= 0.17", "< 2.0"
|
17
|
+
s.add_dependency "activesupport", ">= 4.0", "< 7.0"
|
18
18
|
end
|
data/lib/better-faraday.rb
CHANGED
@@ -11,14 +11,21 @@ require "active_support/core_ext/string/filters"
|
|
11
11
|
require "active_support/core_ext/string/inflections"
|
12
12
|
|
13
13
|
Module.new do
|
14
|
-
def
|
15
|
-
|
14
|
+
def call(env)
|
15
|
+
env.instance_variable_set(:@request_sent_at, Time.now.utc)
|
16
|
+
super
|
16
17
|
end
|
17
|
-
|
18
|
+
|
19
|
+
def save_response(env, status, body, headers = nil, reason_phrase = nil)
|
20
|
+
env.instance_variable_set(:@response_received_at, Time.now.utc)
|
21
|
+
env.instance_variable_set(:@request_body, env.body.respond_to?(:read) ? env.body.read : env.body)
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end.tap { |m| Faraday::Adapter.send(:prepend, m) }
|
18
25
|
|
19
26
|
module Faraday
|
20
27
|
class Env
|
21
|
-
attr_reader :request_body
|
28
|
+
attr_reader :request_body, :request_sent_at, :response_received_at
|
22
29
|
end
|
23
30
|
|
24
31
|
class Error
|
@@ -39,7 +46,7 @@ module Faraday
|
|
39
46
|
Faraday::Error
|
40
47
|
end
|
41
48
|
|
42
|
-
error = klass.new(describe)
|
49
|
+
error = klass.new("\n#{describe}")
|
43
50
|
error.instance_variable_set(:@response, self)
|
44
51
|
raise error
|
45
52
|
end
|
@@ -64,13 +71,23 @@ module Faraday
|
|
64
71
|
end
|
65
72
|
|
66
73
|
def describe
|
67
|
-
request_headers
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
71
87
|
|
72
|
-
[
|
73
|
-
"
|
88
|
+
lines = [
|
89
|
+
"",
|
90
|
+
"-- #{status} #{reason_phrase} --".upcase,
|
74
91
|
"",
|
75
92
|
"-- Request URL --",
|
76
93
|
env.url.to_s,
|
@@ -79,20 +96,63 @@ module Faraday
|
|
79
96
|
env.method.to_s.upcase,
|
80
97
|
"",
|
81
98
|
"-- Request headers --",
|
82
|
-
::JSON.generate(request_headers).yield_self { |t| t.truncate(
|
99
|
+
::JSON.generate(request_headers).yield_self { |t| t.truncate(2048, omission: "... (truncated, full length: #{t.length})") },
|
83
100
|
"",
|
101
|
+
|
84
102
|
"-- Request body --",
|
85
|
-
|
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})") },
|
113
|
+
"",
|
114
|
+
|
115
|
+
"-- Request sent at --",
|
116
|
+
env.request_sent_at.strftime("%Y-%m-%d %H:%M:%S.%2N") + " UTC",
|
86
117
|
"",
|
118
|
+
|
87
119
|
"-- Response headers --",
|
88
|
-
|
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})") },
|
89
125
|
"",
|
126
|
+
|
90
127
|
"-- Response body --",
|
91
|
-
|
92
|
-
|
93
|
-
|
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})") }
|
138
|
+
]
|
139
|
+
|
140
|
+
if env.response_received_at
|
141
|
+
lines.concat [
|
142
|
+
"",
|
143
|
+
"-- Response received at --",
|
144
|
+
env.response_received_at.strftime("%Y-%m-%d %H:%M:%S.%2N") + " UTC",
|
145
|
+
"",
|
146
|
+
"-- Response received in --",
|
147
|
+
"#{((env.response_received_at.to_f - env.request_sent_at.to_f) * 1000.0).round(2)}ms"
|
148
|
+
]
|
149
|
+
end
|
150
|
+
|
151
|
+
lines.join("\n") + "\n"
|
94
152
|
end
|
95
153
|
|
154
|
+
alias inspect describe
|
155
|
+
|
96
156
|
private
|
97
157
|
|
98
158
|
def __parse_json(json)
|
@@ -107,7 +167,7 @@ module Faraday
|
|
107
167
|
return data.map(&method(:__protect_data)) if ::Array === data
|
108
168
|
return data unless ::Hash === data
|
109
169
|
data.each_with_object({}) do |(key, value), memo|
|
110
|
-
memo[key] = if key.
|
170
|
+
memo[key] = if key.to_s.underscore.tr("_", " ").yield_self { |k| Faraday.secrets.any? { |s| k.match?(s) } }
|
111
171
|
"SECRET"
|
112
172
|
else
|
113
173
|
__protect_data(value)
|
@@ -128,5 +188,5 @@ module Faraday
|
|
128
188
|
attr_accessor :secrets
|
129
189
|
end
|
130
190
|
|
131
|
-
self.secrets = [/\bpass(?:word|phrase)\b/i, /\bauthorization\b/i, /\bsecret\b/i, /\b(:?access?
|
191
|
+
self.secrets = [/\bpass(?:word|phrase)\b/i, /\bauthorization\b/i, /\bsecret\b/i, /\b(:?access)?token\b/i]
|
132
192
|
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.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Konoplov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-26 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: '0.17'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
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: '0.17'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
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: '
|
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: '
|
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.
|
85
|
+
rubygems_version: 3.1.2
|
80
86
|
signing_key:
|
81
87
|
specification_version: 4
|
82
88
|
summary: Extends Faraday with useful features.
|