faraday 0.17.1 → 0.17.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/README.md +11 -0
- data/lib/faraday.rb +2 -3
- data/lib/faraday/adapter/net_http_persistent.rb +1 -1
- data/lib/faraday/deprecate.rb +8 -2
- data/lib/faraday/error.rb +65 -26
- data/lib/faraday/options.rb +2 -2
- data/lib/faraday/rack_builder.rb +2 -2
- data/lib/faraday/response/raise_error.rb +1 -1
- data/spec/faraday/response/raise_error_spec.rb +12 -1
- data/spec/spec_helper.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbaf8ddf8082d43401d642a52b6bc8514455824c90043970871e60b193375f2a
|
4
|
+
data.tar.gz: 89c3f88e540530a293a35839d67f761d1e3dca04266a8f1e4a5534e6e09a6a1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1523207ad94f95fae692736859cf36e17e0bf5cb14a95e8bfc01ad595833bacfc57bb3c95d87cd910c913ccb44aa94391fa6bfe762ebf1b7fe08aaf301ac62fa
|
7
|
+
data.tar.gz: 904372a2c809897cfadd6d856d98bf65396ce869124738f6693c28ebee7254b0792d027ad67bd59d660a0b71d93ac09db73f640da3cee8e479eb81b9458a6fd1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Faraday Changelog
|
2
2
|
|
3
|
+
## v0.17.3
|
4
|
+
|
5
|
+
Fixes:
|
6
|
+
|
7
|
+
* Reverts changes in error classes hierarchy. #1092 (@iMacTia)
|
8
|
+
* Fix Ruby 1.9 syntax errors and improve Error class testing #1094 (@BanzaiMan,
|
9
|
+
@mrexox, @technoweenie)
|
10
|
+
|
11
|
+
Misc:
|
12
|
+
|
13
|
+
* Stops using `&Proc.new` for block forwarding. #1083 (@olleolleolle)
|
14
|
+
* Update CI to test against ruby 2.0-2.7 #1087, #1099 (@iMacTia, @olleolleolle,
|
15
|
+
@technoweenie)
|
16
|
+
* require FARADAY_DEPRECATE=warn to show Faraday v1.0 deprecation warnings
|
17
|
+
#1098 (@technoweenie)
|
18
|
+
|
3
19
|
## v0.17.1
|
4
20
|
|
5
21
|
Final release before Faraday v1.0, with important fixes for Ruby 2.7.
|
@@ -7,7 +23,7 @@ Final release before Faraday v1.0, with important fixes for Ruby 2.7.
|
|
7
23
|
Fixes:
|
8
24
|
|
9
25
|
* RaiseError response middleware raises exception if HTTP client returns a nil
|
10
|
-
status.
|
26
|
+
status. #1042 (@jonnyom, @BobbyMcWho)
|
11
27
|
|
12
28
|
Misc:
|
13
29
|
|
data/README.md
CHANGED
@@ -31,6 +31,17 @@ Rack::Test, and a Test adapter for stubbing requests by hand.
|
|
31
31
|
|
32
32
|
Available at [rubydoc.info](http://www.rubydoc.info/gems/faraday).
|
33
33
|
|
34
|
+
## Faraday 1.0
|
35
|
+
|
36
|
+
Faraday 1.0 will ship soon! Faraday 0.17 will be the last 0.x release, except for serious bugs or security issues.
|
37
|
+
Faraday 1.0 is a major release, but it will be mostly backwards-compatible with 0.x, so we strongly encourage you
|
38
|
+
to use it on your next projects and/or consider to upgrade your existing ones.
|
39
|
+
Upgrading is simple:
|
40
|
+
|
41
|
+
* Checkout the new code from [`master`](https://github.com/lostisland/faraday) and the new [Documentation Website](https://lostisland.github.io/faraday/).
|
42
|
+
* If you're upgrading an existing project, check the [UPGRADING](https://github.com/lostisland/faraday/blob/master/UPGRADING.md) file.
|
43
|
+
* You can also enable upgrade warnings on apps with Faraday 0.x if you run them with `FARADAY_DEPRECATE=warn` or `FARADAY_DEPRECATE=1` in ENV.
|
44
|
+
|
34
45
|
## Usage
|
35
46
|
|
36
47
|
### Basic Use
|
data/lib/faraday.rb
CHANGED
@@ -14,7 +14,7 @@ require 'forwardable'
|
|
14
14
|
# conn.get '/'
|
15
15
|
#
|
16
16
|
module Faraday
|
17
|
-
VERSION = "0.17.
|
17
|
+
VERSION = "0.17.3"
|
18
18
|
|
19
19
|
class << self
|
20
20
|
# Public: Gets or sets the root path that Faraday is being loaded from.
|
@@ -64,8 +64,7 @@ module Faraday
|
|
64
64
|
# :params => {:page => 1}
|
65
65
|
#
|
66
66
|
# Returns a Faraday::Connection.
|
67
|
-
def new(url = nil, options = nil)
|
68
|
-
block = block_given? ? Proc.new : nil
|
67
|
+
def new(url = nil, options = nil, &block)
|
69
68
|
options = options ? default_connection_options.merge(options) : default_connection_options
|
70
69
|
Faraday::Connection.new(url, options, &block)
|
71
70
|
end
|
@@ -10,7 +10,7 @@ module Faraday
|
|
10
10
|
if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == [:key, :name]
|
11
11
|
options = {name: 'Faraday'}
|
12
12
|
options[:pool_size] = @connection_options[:pool_size] if @connection_options.key?(:pool_size)
|
13
|
-
Net::HTTP::Persistent.new(options)
|
13
|
+
Net::HTTP::Persistent.new(**options)
|
14
14
|
else
|
15
15
|
Net::HTTP::Persistent.new('Faraday')
|
16
16
|
end
|
data/lib/faraday/deprecate.rb
CHANGED
@@ -46,11 +46,17 @@ module Faraday
|
|
46
46
|
# end
|
47
47
|
module Deprecate
|
48
48
|
def self.skip # :nodoc:
|
49
|
-
@skip ||=
|
49
|
+
@skip ||= begin
|
50
|
+
case ENV['FARADAY_DEPRECATE'].to_s.downcase
|
51
|
+
when '1', 'warn' then :warn
|
52
|
+
else :skip
|
53
|
+
end
|
54
|
+
end
|
55
|
+
@skip == :skip
|
50
56
|
end
|
51
57
|
|
52
58
|
def self.skip=(value) # :nodoc:
|
53
|
-
@skip = value
|
59
|
+
@skip = value ? :skip : :warn
|
54
60
|
end
|
55
61
|
|
56
62
|
# Temporarily turn off warnings. Intended for tests only.
|
data/lib/faraday/error.rb
CHANGED
@@ -9,18 +9,9 @@ module Faraday
|
|
9
9
|
attr_reader :response, :wrapped_exception
|
10
10
|
|
11
11
|
def initialize(exc, response = nil)
|
12
|
-
@wrapped_exception = nil
|
13
|
-
@response = response
|
14
|
-
|
15
|
-
if exc.respond_to?(:backtrace)
|
16
|
-
super(exc.message)
|
17
|
-
@wrapped_exception = exc
|
18
|
-
elsif exc.respond_to?(:each_key)
|
19
|
-
super("the server responded with status #{exc[:status]}")
|
20
|
-
@response = exc
|
21
|
-
else
|
22
|
-
super(exc.to_s)
|
23
|
-
end
|
12
|
+
@wrapped_exception = nil unless defined?(@wrapped_exception)
|
13
|
+
@response = nil unless defined?(@response)
|
14
|
+
super(exc_msg_and_response!(exc, response))
|
24
15
|
end
|
25
16
|
|
26
17
|
def backtrace
|
@@ -32,12 +23,44 @@ module Faraday
|
|
32
23
|
end
|
33
24
|
|
34
25
|
def inspect
|
35
|
-
inner =
|
36
|
-
inner
|
37
|
-
inner
|
38
|
-
inner
|
26
|
+
inner = ''
|
27
|
+
inner += " wrapped=#{@wrapped_exception.inspect}" if @wrapped_exception
|
28
|
+
inner += " response=#{@response.inspect}" if @response
|
29
|
+
inner += " #{super}" if inner.empty?
|
39
30
|
%(#<#{self.class}#{inner}>)
|
40
31
|
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
# Pulls out potential parent exception and response hash, storing them in
|
36
|
+
# instance variables.
|
37
|
+
# exc - Either an Exception, a string message, or a response hash.
|
38
|
+
# response - Hash
|
39
|
+
# :status - Optional integer HTTP response status
|
40
|
+
# :headers - String key/value hash of HTTP response header
|
41
|
+
# values.
|
42
|
+
# :body - Optional string HTTP response body.
|
43
|
+
#
|
44
|
+
# If a subclass has to call this, then it should pass a string message
|
45
|
+
# to `super`. See NilStatusError.
|
46
|
+
def exc_msg_and_response!(exc, response = nil)
|
47
|
+
if @response.nil? && @wrapped_exception.nil?
|
48
|
+
@wrapped_exception, msg, @response = exc_msg_and_response(exc, response)
|
49
|
+
return msg
|
50
|
+
end
|
51
|
+
|
52
|
+
exc.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
# Pulls out potential parent exception and response hash.
|
56
|
+
def exc_msg_and_response(exc, response = nil)
|
57
|
+
return [exc, exc.message, response] if exc.respond_to?(:backtrace)
|
58
|
+
|
59
|
+
return [nil, "the server responded with status #{exc[:status]}", exc] \
|
60
|
+
if exc.respond_to?(:each_key)
|
61
|
+
|
62
|
+
[nil, exc.to_s, response]
|
63
|
+
end
|
41
64
|
end
|
42
65
|
|
43
66
|
# Faraday client error class. Represents 4xx status responses.
|
@@ -77,7 +100,7 @@ module Faraday
|
|
77
100
|
end
|
78
101
|
|
79
102
|
# A unified client error for timeouts.
|
80
|
-
class TimeoutError <
|
103
|
+
class TimeoutError < ClientError
|
81
104
|
def initialize(exc = 'timeout', response = nil)
|
82
105
|
super(exc, response)
|
83
106
|
end
|
@@ -85,32 +108,48 @@ module Faraday
|
|
85
108
|
|
86
109
|
# Raised by Faraday::Response::RaiseError in case of a nil status in response.
|
87
110
|
class NilStatusError < ServerError
|
88
|
-
def initialize(
|
89
|
-
|
90
|
-
|
111
|
+
def initialize(exc, response = nil)
|
112
|
+
exc_msg_and_response!(exc, response)
|
113
|
+
@response = unwrap_resp!(@response)
|
114
|
+
super('http status could not be derived from the server response')
|
91
115
|
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
extend Faraday::Deprecate
|
120
|
+
|
121
|
+
def unwrap_resp(resp)
|
122
|
+
if inner = (resp.keys.size == 1 && resp[:response])
|
123
|
+
return unwrap_resp(inner)
|
124
|
+
end
|
125
|
+
|
126
|
+
resp
|
127
|
+
end
|
128
|
+
|
129
|
+
alias_method :unwrap_resp!, :unwrap_resp
|
130
|
+
deprecate('unwrap_resp', nil, '1.0')
|
92
131
|
end
|
93
132
|
|
94
133
|
# A unified error for failed connections.
|
95
|
-
class ConnectionFailed <
|
134
|
+
class ConnectionFailed < ClientError
|
96
135
|
end
|
97
136
|
|
98
137
|
# A unified client error for SSL errors.
|
99
|
-
class SSLError <
|
138
|
+
class SSLError < ClientError
|
100
139
|
end
|
101
140
|
|
102
141
|
# Raised by FaradayMiddleware::ResponseMiddleware
|
103
|
-
class ParsingError <
|
142
|
+
class ParsingError < ClientError
|
104
143
|
end
|
105
144
|
|
106
145
|
# Exception used to control the Retry middleware.
|
107
146
|
#
|
108
147
|
# @see Faraday::Request::Retry
|
109
|
-
class RetriableResponse <
|
148
|
+
class RetriableResponse < ClientError
|
110
149
|
end
|
111
150
|
|
112
|
-
|
113
|
-
|
151
|
+
[:ClientError, :ConnectionFailed, :ResourceNotFound,
|
152
|
+
:ParsingError, :TimeoutError, :SSLError, :RetriableResponse].each do |const|
|
114
153
|
Error.const_set(
|
115
154
|
const,
|
116
155
|
DeprecatedClass.proxy_class(Faraday.const_get(const))
|
data/lib/faraday/options.rb
CHANGED
@@ -162,8 +162,8 @@ module Faraday
|
|
162
162
|
@attribute_options ||= {}
|
163
163
|
end
|
164
164
|
|
165
|
-
def self.memoized(key)
|
166
|
-
memoized_attributes[key.to_sym] =
|
165
|
+
def self.memoized(key, &block)
|
166
|
+
memoized_attributes[key.to_sym] = block
|
167
167
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
168
168
|
def #{key}() self[:#{key}]; end
|
169
169
|
RUBY
|
data/lib/faraday/rack_builder.rb
CHANGED
@@ -49,10 +49,10 @@ module Faraday
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
def initialize(handlers = [])
|
52
|
+
def initialize(handlers = [], &block)
|
53
53
|
@handlers = handlers
|
54
54
|
if block_given?
|
55
|
-
build(&
|
55
|
+
build(&block)
|
56
56
|
elsif @handlers.empty?
|
57
57
|
# default stack, if nothing else is configured
|
58
58
|
self.request :url_encoded
|
@@ -14,7 +14,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
14
14
|
stub.get('conflict') { [409, { 'X-Reason' => 'because' }, 'keep looking'] }
|
15
15
|
stub.get('unprocessable-entity') { [422, { 'X-Reason' => 'because' }, 'keep looking'] }
|
16
16
|
stub.get('4xx') { [499, { 'X-Reason' => 'because' }, 'keep looking'] }
|
17
|
-
stub.get('nil-status') { [nil, { 'X-Reason' => '
|
17
|
+
stub.get('nil-status') { [nil, { 'X-Reason' => 'nil' }, 'fail'] }
|
18
18
|
stub.get('server-error') { [500, { 'X-Error' => 'bailout' }, 'fail'] }
|
19
19
|
end
|
20
20
|
end
|
@@ -28,6 +28,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
28
28
|
expect { conn.get('bad-request') }.to raise_error(Faraday::ClientError) do |ex|
|
29
29
|
expect(ex.message).to eq('the server responded with status 400')
|
30
30
|
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
31
|
+
expect(ex.response[:status]).to eq(400)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
@@ -35,6 +36,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
35
36
|
expect { conn.get('unauthorized') }.to raise_error(Faraday::ClientError) do |ex|
|
36
37
|
expect(ex.message).to eq('the server responded with status 401')
|
37
38
|
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
39
|
+
expect(ex.response[:status]).to eq(401)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
@@ -42,6 +44,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
42
44
|
expect { conn.get('forbidden') }.to raise_error(Faraday::ClientError) do |ex|
|
43
45
|
expect(ex.message).to eq('the server responded with status 403')
|
44
46
|
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
47
|
+
expect(ex.response[:status]).to eq(403)
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
@@ -49,6 +52,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
49
52
|
expect { conn.get('not-found') }.to raise_error(Faraday::ResourceNotFound) do |ex|
|
50
53
|
expect(ex.message).to eq('the server responded with status 404')
|
51
54
|
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
55
|
+
expect(ex.response[:status]).to eq(404)
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
@@ -56,6 +60,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
56
60
|
expect { conn.get('proxy-error') }.to raise_error(Faraday::ConnectionFailed) do |ex|
|
57
61
|
expect(ex.message).to eq('407 "Proxy Authentication Required "')
|
58
62
|
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
63
|
+
expect(ex.response[:status]).to eq(407)
|
59
64
|
end
|
60
65
|
end
|
61
66
|
|
@@ -63,6 +68,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
63
68
|
expect { conn.get('conflict') }.to raise_error(Faraday::ClientError) do |ex|
|
64
69
|
expect(ex.message).to eq('the server responded with status 409')
|
65
70
|
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
71
|
+
expect(ex.response[:status]).to eq(409)
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
@@ -70,12 +76,15 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
70
76
|
expect { conn.get('unprocessable-entity') }.to raise_error(Faraday::ClientError) do |ex|
|
71
77
|
expect(ex.message).to eq('the server responded with status 422')
|
72
78
|
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
79
|
+
expect(ex.response[:status]).to eq(422)
|
73
80
|
end
|
74
81
|
end
|
75
82
|
|
76
83
|
it 'raises Faraday::NilStatusError for nil status in response' do
|
77
84
|
expect { conn.get('nil-status') }.to raise_error(Faraday::NilStatusError) do |ex|
|
78
85
|
expect(ex.message).to eq('http status could not be derived from the server response')
|
86
|
+
expect(ex.response[:headers]['X-Reason']).to eq('nil')
|
87
|
+
expect(ex.response[:status]).to be_nil
|
79
88
|
end
|
80
89
|
end
|
81
90
|
|
@@ -83,6 +92,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
83
92
|
expect { conn.get('4xx') }.to raise_error(Faraday::ClientError) do |ex|
|
84
93
|
expect(ex.message).to eq('the server responded with status 499')
|
85
94
|
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
95
|
+
expect(ex.response[:status]).to eq(499)
|
86
96
|
end
|
87
97
|
end
|
88
98
|
|
@@ -90,6 +100,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
90
100
|
expect { conn.get('server-error') }.to raise_error(Faraday::ClientError) do |ex|
|
91
101
|
expect(ex.message).to eq('the server responded with status 500')
|
92
102
|
expect(ex.response[:headers]['X-Error']).to eq('bailout')
|
103
|
+
expect(ex.response[:status]).to eq(500)
|
93
104
|
end
|
94
105
|
end
|
95
106
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.17.
|
4
|
+
version: 0.17.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@technoweenie"
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-12-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multipart-post
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
|
-
rubygems_version: 3.
|
136
|
+
rubygems_version: 3.1.2
|
137
137
|
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: HTTP/REST API client library.
|