better-faraday 1.0.3 → 1.0.4

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: e2c396050eb803fc44370487683e12b77b07b808d563264aa372c847cd5be21c
4
- data.tar.gz: e8a5f25e26e98d39adf5cb87653fa99b25f2a365382b8996434f68c0c8215a4d
3
+ metadata.gz: 99c10f80bd720f60bad4cef31fa82b7eb35eff291c7375c6b16afecaeeea768b
4
+ data.tar.gz: f22d48fb3b8f72bce97751e66562e7bc5afe16ccc4236a4d1ac2b02dce214bc1
5
5
  SHA512:
6
- metadata.gz: d68b1aec17fdbc160393fad93a9afdfa5650cdab9413226830054f84568efca1315ef1a34de2b3b44075b5a843627cfb75bb8b451d03fea405c02fae634aa097
7
- data.tar.gz: 5dfb59a2f91082cf3e305db4d965a8f7c41d7617f7642adb1f7505fac1673bcedce22124465053a950ab2434878e434a34a835d39cefaec36c343975b9d099e3
6
+ metadata.gz: 4ced29c94068d38cc9e648639af9e1f41522527fdae7374042b6e61316b935410d0d5231e720957f260fd53f07e92d0c99575e330a9888438ace0e8c15960051
7
+ data.tar.gz: dc784bf72977b0e0e5591e5b01f33833235619c261a2d12a5424b37e81180355f215bb354e0a0a897b6b904f94cd476649eb578ca9f00d0e83d31472dc89b929
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.1
1
+ 2.6.1
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
1
  # better-faraday
2
2
 
3
3
  A gem extending Faraday (popular Ruby HTTP client) with useful features without breaking anything.
4
+
5
+ ## Ruby before 2.5
6
+
7
+ Please, add `backport_yield_self` to your dependencies.
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "better-faraday"
6
- s.version = "1.0.3"
6
+ s.version = "1.0.4"
7
7
  s.author = "Yaroslav Konoplov"
8
8
  s.email = "eahome00@gmail.com"
9
9
  s.summary = "Extends Faraday with useful features."
@@ -7,6 +7,7 @@ require "faraday/error"
7
7
  require "faraday/options"
8
8
  require "faraday/response"
9
9
  require "active_support/core_ext/object/deep_dup"
10
+ require "active_support/core_ext/string/filters"
10
11
 
11
12
  Module.new do
12
13
  def run_request(method, url, body, headers, &block)
@@ -46,7 +47,7 @@ module Faraday
46
47
  request_json = parse_json(env.request_body)
47
48
  response_headers = ::Hash === env.response_headers ? env.response_headers.deep_dup : {}
48
49
  response_json = parse_json(env.body)
49
- [request_headers, request_json, response_headers, response_json].compact.each { |hash| sanitize(hash) }
50
+ [request_headers, request_json, response_headers, response_json].compact.each(&method(:protect!))
50
51
 
51
52
  [ "",
52
53
  "-- #{status} #{reason_phrase} --",
@@ -58,16 +59,16 @@ module Faraday
58
59
  env.method.to_s.upcase,
59
60
  "",
60
61
  "-- Request headers --",
61
- ::JSON.generate(request_headers),
62
+ ::JSON.generate(request_headers).yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
62
63
  "",
63
64
  "-- Request body --",
64
- request_json ? ::JSON.generate(request_json) : env.request_body.to_s,
65
+ (request_json ? ::JSON.generate(request_json) : env.request_body.to_s).yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
65
66
  "",
66
67
  "-- Response headers --",
67
- response_headers ? ::JSON.generate(response_headers) : env.response_headers.to_s,
68
+ (response_headers ? ::JSON.generate(response_headers) : env.response_headers.to_s).yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
68
69
  "",
69
70
  "-- Response body --",
70
- response_json ? ::JSON.generate(response_json) : env.body.to_s,
71
+ (response_json ? ::JSON.generate(response_json) : env.body.to_s).yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
71
72
  ""
72
73
  ].join("\n")
73
74
  end
@@ -75,15 +76,17 @@ module Faraday
75
76
  private
76
77
 
77
78
  def parse_json(json)
78
- ::JSON.parse(::String === json ? json : json.to_s, quirks_mode: false)
79
+ data = ::JSON.parse(::String === json ? json : json.to_s)
80
+ data if ::Hash === data || ::Array === data
79
81
  rescue ::JSON::ParserError
80
82
  nil
81
83
  end
82
84
 
83
- def sanitize(h)
84
- h.keys.map(&:to_s).each do |k|
85
- h[k] = "SECRET" if k.respond_to?(:=~) && Faraday.secrets.any? { |s| k =~ s }
86
- sanitize(h[k]) if ::Hash === h[k]
85
+ def protect!(x)
86
+ return x.map!(&method(:protect!)) if ::Array === x
87
+ x.keys.each do |k|
88
+ x[k] = "SECRET" if k.respond_to?(:=~) && Faraday.secrets.any? { |s| k =~ s }
89
+ protect!(x[k]) if ::Hash === x[k]
87
90
  end
88
91
  end
89
92
  end
@@ -100,5 +103,5 @@ module Faraday
100
103
  attr_accessor :secrets
101
104
  end
102
105
 
103
- self.secrets = [/pass(?:word|phrase)/i, /authorization/i, /secret/i]
106
+ self.secrets = [/\bpass(?:word|phrase)\b/i, /\bauthorization\b/i, /\bsecret\b/i, /\b(:?access?)token\b/i]
104
107
  end
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.3
4
+ version: 1.0.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: 2018-10-30 00:00:00.000000000 Z
11
+ date: 2019-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -76,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 2.7.6
79
+ rubygems_version: 3.0.1
81
80
  signing_key:
82
81
  specification_version: 4
83
82
  summary: Extends Faraday with useful features.