better-faraday 1.1.0 → 1.1.1

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: 3c28a4a8921cc595ea37a968efe8127a9ac3da2044ff76168bfe076761965a93
4
+ data.tar.gz: 937005a9d7e8dea011d3872e42f470bded405821186e414bcea64b0cd9953367
5
5
  SHA512:
6
- metadata.gz: 72017939d4eaddce9514bb76d329ae2fba24e9bce2ed4d9bbbc51341f7b21adb68d6a5fa81222abff6d47faae49fb56e0ef1bf648cbc66a69a5553e419529782
7
- data.tar.gz: 426bab6ab085ca927e4e7999903286371308b00ce551ef60525555043e8807b2ea0e87f2392a12d8f1b8715474399be40261b490dd84e9eca6574c11f163cdb0
6
+ metadata.gz: 142c021bc1f27154292f8ce8a8b52ba5742cea07d34d3d7bf5b69700655bb83ae51be5ca89ac4444863711d66d1289116c9be5379d4e7d893f4ef70d29c7aef0
7
+ data.tar.gz: f3a5b027c3be795db544b320b66edcdf537577f580fc231e7ee40e8bdad6935e5d1beb57f9c27e704e6a8c5b1d2b5ba1faf0333ca6dde5aa0724d982eec9b43d
@@ -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.1.1"
7
7
  s.author = "Yaroslav Konoplov"
8
8
  s.email = "eahome00@gmail.com"
9
9
  s.summary = "Extends Faraday with useful features."
@@ -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,7 +148,7 @@ module Faraday
113
148
  ]
114
149
  end
115
150
 
116
- lines.join("\n")
151
+ lines.join("\n") + "\n"
117
152
  end
118
153
 
119
154
  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.1.0
4
+ version: 1.1.1
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: 2019-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday