better-faraday 1.0.6 → 1.0.7

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: 48028546f73694c5803cc254cf7301337b7c7a231451e45abd7aba214b321baa
4
- data.tar.gz: 498d6550e544f4e8fb703d14f5f8f2cbd9bd8d369db58c65aa91d1d237e52d4d
3
+ metadata.gz: 566a4665f7f21fbc42e2ab20190caf5d87d3d49d775ac376135c273728132334
4
+ data.tar.gz: 4ab4177eb90929e0c3f1f89aa8418c74af97120770c68595cf6ba630e9d8894c
5
5
  SHA512:
6
- metadata.gz: 4ce4fca25c344845a1be578063849c96cc55e0790e1d2bbecd45cab67cdbaf647e3bd04875beae0ccf5bff607026302fd055c902d478e7166c07a4e4bbc9bd23
7
- data.tar.gz: f4c9fc09053ab9ec50080f32c1fd97e7ae7c44c267c41519a76d4f0c6b7f4f93e7fe9e227b0dfddea541b54de01b327fb6d62b72b25a4c885bf3c75c350423a5
6
+ metadata.gz: 0c459e43aed401c92e6e57957c057bfef94a4194dfb77bb789e3d5466cd99153f17a43b883a9a5896c3c0c5a074ab42f39ddda0ae749bc33744c40aebeb34054
7
+ data.tar.gz: ceddc5b83c55fc7546b0dd2c6edb88a9711f8308c7c9363f1868b32b67e419b9b44ad41b0a6a3c8a114c34b2497a6db11b79d924a45a64c0ec128c56340f95db
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "better-faraday"
6
- s.version = "1.0.6"
6
+ s.version = "1.0.7"
7
7
  s.author = "Yaroslav Konoplov"
8
8
  s.email = "eahome00@gmail.com"
9
9
  s.summary = "Extends Faraday with useful features."
@@ -31,9 +31,9 @@ module Faraday
31
31
 
32
32
  class Response
33
33
  def assert_2xx!
34
- return self if status >= 200 && status <= 299
34
+ return self if status_2xx?
35
35
 
36
- klass = if status >= 400 && status <= 499
36
+ klass = if status_4xx?
37
37
  "Faraday::HTTP#{status}".safe_constantize || Faraday::HTTP4xx
38
38
  else
39
39
  Faraday::Error
@@ -47,12 +47,27 @@ module Faraday
47
47
  alias ok! assert_2xx! # Short name.
48
48
  alias assert_success! assert_2xx! # Compatibility.
49
49
 
50
+ def status_2xx?
51
+ status >= 200 && status <= 299
52
+ end
53
+
54
+ def status_3xx?
55
+ status >= 300 && status <= 399
56
+ end
57
+
58
+ def status_4xx?
59
+ status >= 400 && status <= 499
60
+ end
61
+
62
+ def status_5xx?
63
+ status >= 500 && status <= 599
64
+ end
65
+
50
66
  def describe
51
- request_headers = env.request_headers.deep_dup
52
- request_json = parse_json(env.request_body)
53
- response_headers = ::Hash === env.response_headers ? env.response_headers.deep_dup : {}
54
- response_json = parse_json(env.body)
55
- [request_headers, request_json, response_headers, response_json].compact.each(&method(:protect!))
67
+ request_headers = __protect_data(env.request_headers.deep_dup)
68
+ request_json = __protect_data(parse_json(env.request_body))
69
+ response_headers = __protect_data(::Hash === env.response_headers ? env.response_headers.deep_dup : {})
70
+ response_json = __protect_data(__parse_json(env.body))
56
71
 
57
72
  [ "",
58
73
  "-- #{status} #{reason_phrase} --",
@@ -80,18 +95,23 @@ module Faraday
80
95
 
81
96
  private
82
97
 
83
- def parse_json(json)
84
- data = ::JSON.parse(::String === json ? json : json.to_s)
98
+ def __parse_json(json)
99
+ return nil unless ::String === json
100
+ data = ::JSON.parse(json)
85
101
  data if ::Hash === data || ::Array === data
86
102
  rescue ::JSON::ParserError
87
103
  nil
88
104
  end
89
105
 
90
- def protect!(x)
91
- return x.map!(&method(:protect!)) if ::Array === x
92
- x.keys.each do |k|
93
- x[k] = "SECRET" if k.respond_to?(:=~) && Faraday.secrets.any? { |s| k =~ s }
94
- protect!(x[k]) if ::Hash === x[k]
106
+ def __protect_data(data)
107
+ return data.map(&method(:__protect_data)) if ::Array === data
108
+ return data unless ::Hash === data
109
+ data.each_with_object({}) do |(key, value), memo|
110
+ memo[key] = if key.respond_to?(:=~) && Faraday.secrets.any? { |s| key =~ s }
111
+ "SECRET"
112
+ else
113
+ __protect_data(value)
114
+ end
95
115
  end
96
116
  end
97
117
  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.6
4
+ version: 1.0.7
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-06-03 00:00:00.000000000 Z
11
+ date: 2019-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.0.1
79
+ rubygems_version: 3.0.3
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Extends Faraday with useful features.