better-faraday 1.0.8 → 1.1.0
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 +1 -1
- data/lib/better-faraday.rb +35 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6f0c2729ee0008d378633405c1b5b7ce2487d2ff16c78bce61973a4bc524a2f
|
4
|
+
data.tar.gz: 3e5dc920399d735b9de37efd781430fa1f19ee51a2fc0d11d88cf3b0fe5771c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72017939d4eaddce9514bb76d329ae2fba24e9bce2ed4d9bbbc51341f7b21adb68d6a5fa81222abff6d47faae49fb56e0ef1bf648cbc66a69a5553e419529782
|
7
|
+
data.tar.gz: 426bab6ab085ca927e4e7999903286371308b00ce551ef60525555043e8807b2ea0e87f2392a12d8f1b8715474399be40261b490dd84e9eca6574c11f163cdb0
|
data/better-faraday.gemspec
CHANGED
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
|
@@ -69,8 +76,9 @@ module Faraday
|
|
69
76
|
response_headers = __protect_data(::Hash === env.response_headers ? env.response_headers.deep_dup : {})
|
70
77
|
response_json = __protect_data(__parse_json(env.body))
|
71
78
|
|
72
|
-
[
|
73
|
-
"
|
79
|
+
lines = [
|
80
|
+
"",
|
81
|
+
"-- #{status} #{reason_phrase} --".upcase,
|
74
82
|
"",
|
75
83
|
"-- Request URL --",
|
76
84
|
env.url.to_s,
|
@@ -79,18 +87,33 @@ module Faraday
|
|
79
87
|
env.method.to_s.upcase,
|
80
88
|
"",
|
81
89
|
"-- Request headers --",
|
82
|
-
::JSON.generate(request_headers).yield_self { |t| t.truncate(
|
90
|
+
::JSON.generate(request_headers).yield_self { |t| t.truncate(2048, omission: "... (truncated, full length: #{t.length})") },
|
83
91
|
"",
|
84
92
|
"-- Request body --",
|
85
93
|
(request_json ? ::JSON.generate(request_json) : env.request_body.to_s).yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
|
86
94
|
"",
|
95
|
+
"-- Request sent at --",
|
96
|
+
env.request_sent_at.strftime("%Y-%m-%d %H:%M:%S.%2N") + " UTC",
|
97
|
+
"",
|
87
98
|
"-- Response headers --",
|
88
|
-
(response_headers ? ::JSON.generate(response_headers) : env.response_headers.to_s).yield_self { |t| t.truncate(
|
99
|
+
(response_headers ? ::JSON.generate(response_headers) : env.response_headers.to_s).yield_self { |t| t.truncate(2048, omission: "... (truncated, full length: #{t.length})") },
|
89
100
|
"",
|
90
101
|
"-- Response body --",
|
91
|
-
(response_json ? ::JSON.generate(response_json) : env.body.to_s).yield_self { |t| t.truncate(
|
92
|
-
|
93
|
-
|
102
|
+
(response_json ? ::JSON.generate(response_json) : env.body.to_s).yield_self { |t| t.truncate(2048, omission: "... (truncated, full length: #{t.length})") }
|
103
|
+
]
|
104
|
+
|
105
|
+
if env.response_received_at
|
106
|
+
lines.concat [
|
107
|
+
"",
|
108
|
+
"-- Response received at --",
|
109
|
+
env.response_received_at.strftime("%Y-%m-%d %H:%M:%S.%2N") + " UTC",
|
110
|
+
"",
|
111
|
+
"-- Response received in --",
|
112
|
+
"#{((env.response_received_at.to_f - env.request_sent_at.to_f) * 1000.0).round(2)}ms"
|
113
|
+
]
|
114
|
+
end
|
115
|
+
|
116
|
+
lines.join("\n")
|
94
117
|
end
|
95
118
|
|
96
119
|
private
|
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.1.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
|
+
date: 2019-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|