better-faraday 1.0.8 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dffcabe229bcdabe18df3b0404af88381d6cf4ef3e8cebde48d95abc34bf717
4
- data.tar.gz: 2ee1d3d4f126fdd52da8e395f5c8cdcc0da7b0f9a1d31708b390989c5f531b8e
3
+ metadata.gz: f6f0c2729ee0008d378633405c1b5b7ce2487d2ff16c78bce61973a4bc524a2f
4
+ data.tar.gz: 3e5dc920399d735b9de37efd781430fa1f19ee51a2fc0d11d88cf3b0fe5771c8
5
5
  SHA512:
6
- metadata.gz: bfb4e6754efb1c44b6074c1cea214bd203c602415f699fe1bf3da728b7049b79ed2b8dfcef93ad378017f74fa1f5016d397af7fcae55802642550d97e32dacba
7
- data.tar.gz: d4e0629efd3ef722c1232c5ca085574d679af1063a8a6ef0e038fcf5de85f2893301dc6a32adacb2deb90cb09e293fe45c38fae58a87da2c67e6161a668887a6
6
+ metadata.gz: 72017939d4eaddce9514bb76d329ae2fba24e9bce2ed4d9bbbc51341f7b21adb68d6a5fa81222abff6d47faae49fb56e0ef1bf648cbc66a69a5553e419529782
7
+ data.tar.gz: 426bab6ab085ca927e4e7999903286371308b00ce551ef60525555043e8807b2ea0e87f2392a12d8f1b8715474399be40261b490dd84e9eca6574c11f163cdb0
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "better-faraday"
6
- s.version = "1.0.8"
6
+ s.version = "1.1.0"
7
7
  s.author = "Yaroslav Konoplov"
8
8
  s.email = "eahome00@gmail.com"
9
9
  s.summary = "Extends Faraday with useful features."
@@ -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 run_request(method, url, body, headers, &block)
15
- super.tap { |response| response.env.instance_variable_set(:@request_body, body) }
14
+ def call(env)
15
+ env.instance_variable_set(:@request_sent_at, Time.now.utc)
16
+ super
16
17
  end
17
- end.tap { |m| Faraday::Connection.send(:prepend, m) }
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
- "-- #{status} #{reason_phrase} --",
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(1024, omission: "... (truncated, full length: #{t.length})") },
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(1024, omission: "... (truncated, full length: #{t.length})") },
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(1024, omission: "... (truncated, full length: #{t.length})") },
92
- ""
93
- ].join("\n")
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.8
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-08-25 00:00:00.000000000 Z
11
+ date: 2019-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday