faraday 2.7.11 → 2.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +3 -0
- data/lib/faraday/adapter/test.rb +1 -1
- data/lib/faraday/adapter.rb +1 -1
- data/lib/faraday/connection.rb +5 -4
- data/lib/faraday/encoders/nested_params_encoder.rb +1 -1
- data/lib/faraday/error.rb +4 -0
- data/lib/faraday/logging/formatter.rb +1 -1
- data/lib/faraday/options/env.rb +2 -2
- data/lib/faraday/options.rb +3 -3
- data/lib/faraday/rack_builder.rb +0 -1
- data/lib/faraday/request/json.rb +8 -2
- data/lib/faraday/response/json.rb +21 -1
- data/lib/faraday/response/raise_error.rb +4 -2
- data/lib/faraday/utils/headers.rb +8 -2
- data/lib/faraday/utils.rb +3 -4
- data/lib/faraday/version.rb +1 -1
- data/spec/faraday/connection_spec.rb +2 -2
- data/spec/faraday/params_encoders/nested_spec.rb +2 -1
- data/spec/faraday/request/json_spec.rb +64 -0
- data/spec/faraday/response/json_spec.rb +89 -0
- data/spec/faraday/response/raise_error_spec.rb +12 -0
- data/spec/faraday/utils/headers_spec.rb +9 -0
- data/spec/faraday_spec.rb +3 -1
- data/spec/spec_helper.rb +6 -5
- metadata +7 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2795a487e8f0330545b6b9720029b597b0f0f36d33ed47bf3a7ab5ec8e2d583
|
4
|
+
data.tar.gz: a892c9ceebf1a9b5499ca7c6f20a1f6bb3c8a632bcf953f83af0ac17814c0691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc55e018b7b5cec1d5538194841c74a643182d0bb6bc3a73bf5ca1c3c7c88f84998f8b4f90165bffe22b01422e3d90c7bbf6c035714c563bb09265bd34029169
|
7
|
+
data.tar.gz: 05c24fe02e969616d069ba3b02fa7fddfb5c70cb504bfd39ca60983d12aaa47207f985c1e5a1a24d29c71c6cecbe899eb2252f4a8f9458d8681e06584d7016fc
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ Need more details? See the [Faraday API Documentation][apidoc] to see how it wor
|
|
35
35
|
This library aims to support and is [tested against][actions] the currently officially supported Ruby
|
36
36
|
implementations. This means that, even without a major release, we could add or drop support for Ruby versions,
|
37
37
|
following their [EOL](https://endoflife.date/ruby).
|
38
|
-
Currently that means we support Ruby
|
38
|
+
Currently that means we support Ruby 3.0+
|
39
39
|
|
40
40
|
If something doesn't work on one of these Ruby versions, it's a bug.
|
41
41
|
|
data/Rakefile
CHANGED
data/lib/faraday/adapter/test.rb
CHANGED
@@ -146,7 +146,7 @@ module Faraday
|
|
146
146
|
# which means that all of a path, parameters, and headers must be the same as an actual request.
|
147
147
|
def strict_mode=(value)
|
148
148
|
@strict_mode = value
|
149
|
-
@stack.
|
149
|
+
@stack.each_value do |stubs|
|
150
150
|
stubs.each do |stub|
|
151
151
|
stub.strict_mode = value
|
152
152
|
end
|
data/lib/faraday/adapter.rb
CHANGED
data/lib/faraday/connection.rb
CHANGED
@@ -15,7 +15,7 @@ module Faraday
|
|
15
15
|
class Connection
|
16
16
|
# A Set of allowed HTTP verbs.
|
17
17
|
METHODS = Set.new %i[get post put delete head patch options trace]
|
18
|
-
USER_AGENT = "Faraday v#{VERSION}"
|
18
|
+
USER_AGENT = "Faraday v#{VERSION}".freeze
|
19
19
|
|
20
20
|
# @return [Hash] URI query unencoded key/value pairs.
|
21
21
|
attr_reader :params
|
@@ -423,8 +423,8 @@ module Faraday
|
|
423
423
|
#
|
424
424
|
# @param method [Symbol] HTTP method.
|
425
425
|
# @param url [String, URI, nil] String or URI to access.
|
426
|
-
# @param body [String, nil] The request body that will eventually be converted to
|
427
|
-
# a string.
|
426
|
+
# @param body [String, Hash, Array, nil] The request body that will eventually be converted to
|
427
|
+
# a string; middlewares can be used to support more complex types.
|
428
428
|
# @param headers [Hash, nil] unencoded HTTP header key/value pairs.
|
429
429
|
#
|
430
430
|
# @return [Faraday::Response]
|
@@ -473,7 +473,8 @@ module Faraday
|
|
473
473
|
if url && !base.path.end_with?('/')
|
474
474
|
base.path = "#{base.path}/" # ensure trailing slash
|
475
475
|
end
|
476
|
-
url
|
476
|
+
# Ensure relative url will be parsed correctly (such as `service:search` )
|
477
|
+
url = "./#{url}" if url.respond_to?(:start_with?) && !url.start_with?('http://', 'https://', '/', './', '../')
|
477
478
|
uri = url ? base + url : base
|
478
479
|
if params
|
479
480
|
uri.query = params.to_query(params_encoder || options.params_encoder)
|
data/lib/faraday/error.rb
CHANGED
@@ -124,6 +124,10 @@ module Faraday
|
|
124
124
|
class UnprocessableEntityError < ClientError
|
125
125
|
end
|
126
126
|
|
127
|
+
# Raised by Faraday::Response::RaiseError in case of a 429 response.
|
128
|
+
class TooManyRequestsError < ClientError
|
129
|
+
end
|
130
|
+
|
127
131
|
# Faraday server error class. Represents 5xx status responses.
|
128
132
|
class ServerError < Error
|
129
133
|
end
|
data/lib/faraday/options/env.rb
CHANGED
@@ -60,7 +60,7 @@ module Faraday
|
|
60
60
|
:reason_phrase, :response_body) do
|
61
61
|
const_set(:ContentLength, 'Content-Length')
|
62
62
|
const_set(:StatusesWithoutBody, Set.new([204, 304]))
|
63
|
-
const_set(:SuccessfulStatuses, (200..299)
|
63
|
+
const_set(:SuccessfulStatuses, (200..299))
|
64
64
|
|
65
65
|
# A Set of HTTP verbs that typically send a body. If no body is set for
|
66
66
|
# these requests, the Content-Length header is set to 0.
|
@@ -169,7 +169,7 @@ module Faraday
|
|
169
169
|
def stream_response(&block)
|
170
170
|
size = 0
|
171
171
|
yielded = false
|
172
|
-
block_result = block.call do |chunk|
|
172
|
+
block_result = block.call do |chunk|
|
173
173
|
if chunk.bytesize.positive? || size.positive?
|
174
174
|
yielded = true
|
175
175
|
size += chunk.bytesize
|
data/lib/faraday/options.rb
CHANGED
@@ -30,7 +30,7 @@ module Faraday
|
|
30
30
|
new_value = value
|
31
31
|
end
|
32
32
|
|
33
|
-
send("#{key}=", new_value) unless new_value.nil?
|
33
|
+
send(:"#{key}=", new_value) unless new_value.nil?
|
34
34
|
end
|
35
35
|
self
|
36
36
|
end
|
@@ -38,7 +38,7 @@ module Faraday
|
|
38
38
|
# Public
|
39
39
|
def delete(key)
|
40
40
|
value = send(key)
|
41
|
-
send("#{key}=", nil)
|
41
|
+
send(:"#{key}=", nil)
|
42
42
|
value
|
43
43
|
end
|
44
44
|
|
@@ -57,7 +57,7 @@ module Faraday
|
|
57
57
|
else
|
58
58
|
other_value
|
59
59
|
end
|
60
|
-
send("#{key}=", new_value) unless new_value.nil?
|
60
|
+
send(:"#{key}=", new_value) unless new_value.nil?
|
61
61
|
end
|
62
62
|
self
|
63
63
|
end
|
data/lib/faraday/rack_builder.rb
CHANGED
data/lib/faraday/request/json.rb
CHANGED
@@ -13,7 +13,7 @@ module Faraday
|
|
13
13
|
# Doesn't try to encode bodies that already are in string form.
|
14
14
|
class Json < Middleware
|
15
15
|
MIME_TYPE = 'application/json'
|
16
|
-
MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}
|
16
|
+
MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}
|
17
17
|
|
18
18
|
def on_request(env)
|
19
19
|
match_content_type(env) do |data|
|
@@ -24,7 +24,13 @@ module Faraday
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def encode(data)
|
27
|
-
|
27
|
+
if options[:encoder].is_a?(Array) && options[:encoder].size >= 2
|
28
|
+
options[:encoder][0].public_send(options[:encoder][1], data)
|
29
|
+
elsif options[:encoder].respond_to?(:dump)
|
30
|
+
options[:encoder].dump(data)
|
31
|
+
else
|
32
|
+
::JSON.generate(data)
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
def match_content_type(env)
|
@@ -11,6 +11,8 @@ module Faraday
|
|
11
11
|
@parser_options = parser_options
|
12
12
|
@content_types = Array(content_type)
|
13
13
|
@preserve_raw = preserve_raw
|
14
|
+
|
15
|
+
process_parser_options
|
14
16
|
end
|
15
17
|
|
16
18
|
def on_complete(env)
|
@@ -27,7 +29,11 @@ module Faraday
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def parse(body)
|
30
|
-
|
32
|
+
return if body.strip.empty?
|
33
|
+
|
34
|
+
decoder, method_name = @decoder_options
|
35
|
+
|
36
|
+
decoder.public_send(method_name, body, @parser_options || {})
|
31
37
|
end
|
32
38
|
|
33
39
|
def parse_response?(env)
|
@@ -47,6 +53,20 @@ module Faraday
|
|
47
53
|
type = type.split(';', 2).first if type.index(';')
|
48
54
|
type
|
49
55
|
end
|
56
|
+
|
57
|
+
def process_parser_options
|
58
|
+
@decoder_options = @parser_options&.delete(:decoder)
|
59
|
+
|
60
|
+
@decoder_options =
|
61
|
+
if @decoder_options.is_a?(Array) && @decoder_options.size >= 2
|
62
|
+
@decoder_options.slice(0, 2)
|
63
|
+
elsif @decoder_options&.respond_to?(:load) # rubocop:disable Lint/RedundantSafeNavigation
|
64
|
+
# In some versions of Rails, `nil` responds to `load` - hence the safe navigation check above
|
65
|
+
[@decoder_options, :load]
|
66
|
+
else
|
67
|
+
[::JSON, :parse]
|
68
|
+
end
|
69
|
+
end
|
50
70
|
end
|
51
71
|
end
|
52
72
|
end
|
@@ -6,8 +6,8 @@ module Faraday
|
|
6
6
|
# client or server error responses.
|
7
7
|
class RaiseError < Middleware
|
8
8
|
# rubocop:disable Naming/ConstantName
|
9
|
-
ClientErrorStatuses = (400...500)
|
10
|
-
ServerErrorStatuses = (500...600)
|
9
|
+
ClientErrorStatuses = (400...500)
|
10
|
+
ServerErrorStatuses = (500...600)
|
11
11
|
# rubocop:enable Naming/ConstantName
|
12
12
|
|
13
13
|
def on_complete(env)
|
@@ -30,6 +30,8 @@ module Faraday
|
|
30
30
|
raise Faraday::ConflictError, response_values(env)
|
31
31
|
when 422
|
32
32
|
raise Faraday::UnprocessableEntityError, response_values(env)
|
33
|
+
when 429
|
34
|
+
raise Faraday::TooManyRequestsError, response_values(env)
|
33
35
|
when ClientErrorStatuses
|
34
36
|
raise Faraday::ClientError, response_values(env)
|
35
37
|
when ServerErrorStatuses
|
@@ -62,10 +62,10 @@ module Faraday
|
|
62
62
|
super(key, val)
|
63
63
|
end
|
64
64
|
|
65
|
-
def fetch(key,
|
65
|
+
def fetch(key, ...)
|
66
66
|
key = KeyMap[key]
|
67
67
|
key = @names.fetch(key.downcase, key)
|
68
|
-
super(key,
|
68
|
+
super(key, ...)
|
69
69
|
end
|
70
70
|
|
71
71
|
def delete(key)
|
@@ -77,6 +77,12 @@ module Faraday
|
|
77
77
|
super(key)
|
78
78
|
end
|
79
79
|
|
80
|
+
def dig(key, *rest)
|
81
|
+
key = KeyMap[key]
|
82
|
+
key = @names.fetch(key.downcase, key)
|
83
|
+
super(key, *rest)
|
84
|
+
end
|
85
|
+
|
80
86
|
def include?(key)
|
81
87
|
@names.include? key.downcase
|
82
88
|
end
|
data/lib/faraday/utils.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'base64'
|
4
3
|
require 'uri'
|
5
4
|
require 'faraday/utils/headers'
|
6
5
|
require 'faraday/utils/params_hash'
|
@@ -26,7 +25,7 @@ module Faraday
|
|
26
25
|
attr_writer :default_space_encoding
|
27
26
|
end
|
28
27
|
|
29
|
-
ESCAPE_RE = /[^a-zA-Z0-9 .~_-]
|
28
|
+
ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/
|
30
29
|
|
31
30
|
def escape(str)
|
32
31
|
str.to_s.gsub(ESCAPE_RE) do |match|
|
@@ -38,7 +37,7 @@ module Faraday
|
|
38
37
|
CGI.unescape str.to_s
|
39
38
|
end
|
40
39
|
|
41
|
-
DEFAULT_SEP = /[&;] */n
|
40
|
+
DEFAULT_SEP = /[&;] */n
|
42
41
|
|
43
42
|
# Adapted from Rack
|
44
43
|
def parse_query(query)
|
@@ -54,7 +53,7 @@ module Faraday
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def basic_header_from(login, pass)
|
57
|
-
value =
|
56
|
+
value = ["#{login}:#{pass}"].pack('m') # Base64 encoding
|
58
57
|
value.delete!("\n")
|
59
58
|
"Basic #{value}"
|
60
59
|
end
|
data/lib/faraday/version.rb
CHANGED
@@ -300,14 +300,14 @@ RSpec.describe Faraday::Connection do
|
|
300
300
|
it 'joins url to base when used relative path' do
|
301
301
|
conn = Faraday.new(url: url)
|
302
302
|
uri = conn.build_exclusive_url('service:search?limit=400')
|
303
|
-
expect(uri.to_s).to eq('http://service.com/service
|
303
|
+
expect(uri.to_s).to eq('http://service.com/service:search?limit=400')
|
304
304
|
end
|
305
305
|
|
306
306
|
it 'joins url to base when used with path prefix' do
|
307
307
|
conn = Faraday.new(url: url)
|
308
308
|
conn.path_prefix = '/api'
|
309
309
|
uri = conn.build_exclusive_url('service:search?limit=400')
|
310
|
-
expect(uri.to_s).to eq('http://service.com/api/service
|
310
|
+
expect(uri.to_s).to eq('http://service.com/api/service:search?limit=400')
|
311
311
|
end
|
312
312
|
end
|
313
313
|
|
@@ -62,7 +62,8 @@ RSpec.describe Faraday::NestedParamsEncoder do
|
|
62
62
|
it 'encodes rack compat' do
|
63
63
|
params = { a: [{ one: '1', two: '2' }, '3', ''] }
|
64
64
|
result = Faraday::Utils.unescape(Faraday::NestedParamsEncoder.encode(params)).split('&')
|
65
|
-
|
65
|
+
escaped = Rack::Utils.build_nested_query(params)
|
66
|
+
expected = Rack::Utils.unescape(escaped).split('&')
|
66
67
|
expect(result).to match_array(expected)
|
67
68
|
end
|
68
69
|
|
@@ -132,4 +132,68 @@ RSpec.describe Faraday::Request::Json do
|
|
132
132
|
expect(result_type).to eq('application/xml; charset=utf-8')
|
133
133
|
end
|
134
134
|
end
|
135
|
+
|
136
|
+
context 'with encoder' do
|
137
|
+
let(:encoder) do
|
138
|
+
double('Encoder').tap do |e|
|
139
|
+
allow(e).to receive(:dump) { |s, opts| JSON.generate(s, opts) }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
let(:result) { process(a: 1) }
|
144
|
+
|
145
|
+
context 'when encoder is passed as object' do
|
146
|
+
let(:middleware) { described_class.new(->(env) { Faraday::Response.new(env) }, { encoder: encoder }) }
|
147
|
+
|
148
|
+
it 'calls specified JSON encoder\'s dump method' do
|
149
|
+
expect(encoder).to receive(:dump).with({ a: 1 })
|
150
|
+
|
151
|
+
result
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'encodes body' do
|
155
|
+
expect(result_body).to eq('{"a":1}')
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'adds content type' do
|
159
|
+
expect(result_type).to eq('application/json')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'when encoder is passed as an object-method pair' do
|
164
|
+
let(:middleware) { described_class.new(->(env) { Faraday::Response.new(env) }, { encoder: [encoder, :dump] }) }
|
165
|
+
|
166
|
+
it 'calls specified JSON encoder' do
|
167
|
+
expect(encoder).to receive(:dump).with({ a: 1 })
|
168
|
+
|
169
|
+
result
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'encodes body' do
|
173
|
+
expect(result_body).to eq('{"a":1}')
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'adds content type' do
|
177
|
+
expect(result_type).to eq('application/json')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'when encoder is not passed' do
|
182
|
+
let(:middleware) { described_class.new(->(env) { Faraday::Response.new(env) }) }
|
183
|
+
|
184
|
+
it 'calls JSON.generate' do
|
185
|
+
expect(JSON).to receive(:generate).with({ a: 1 })
|
186
|
+
|
187
|
+
result
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'encodes body' do
|
191
|
+
expect(result_body).to eq('{"a":1}')
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'adds content type' do
|
195
|
+
expect(result_type).to eq('application/json')
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
135
199
|
end
|
@@ -114,4 +114,93 @@ RSpec.describe Faraday::Response::Json, type: :response do
|
|
114
114
|
expect(response.body).to eq(result)
|
115
115
|
end
|
116
116
|
end
|
117
|
+
|
118
|
+
context 'with decoder' do
|
119
|
+
let(:decoder) do
|
120
|
+
double('Decoder').tap do |e|
|
121
|
+
allow(e).to receive(:load) { |s, opts| JSON.parse(s, opts) }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
let(:body) { '{"a": 1}' }
|
126
|
+
let(:result) { { a: 1 } }
|
127
|
+
|
128
|
+
context 'when decoder is passed as object' do
|
129
|
+
let(:options) do
|
130
|
+
{
|
131
|
+
parser_options: {
|
132
|
+
decoder: decoder,
|
133
|
+
option: :option_value,
|
134
|
+
symbolize_names: true
|
135
|
+
}
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'passes relevant options to specified decoder\'s load method' do
|
140
|
+
expect(decoder).to receive(:load)
|
141
|
+
.with(body, { option: :option_value, symbolize_names: true })
|
142
|
+
.and_return(result)
|
143
|
+
|
144
|
+
response = process(body)
|
145
|
+
expect(response.body).to eq(result)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'when decoder is passed as an object-method pair' do
|
150
|
+
let(:options) do
|
151
|
+
{
|
152
|
+
parser_options: {
|
153
|
+
decoder: [decoder, :load],
|
154
|
+
option: :option_value,
|
155
|
+
symbolize_names: true
|
156
|
+
}
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'passes relevant options to specified decoder\'s method' do
|
161
|
+
expect(decoder).to receive(:load)
|
162
|
+
.with(body, { option: :option_value, symbolize_names: true })
|
163
|
+
.and_return(result)
|
164
|
+
|
165
|
+
response = process(body)
|
166
|
+
expect(response.body).to eq(result)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when decoder is not passed' do
|
171
|
+
let(:options) do
|
172
|
+
{
|
173
|
+
parser_options: {
|
174
|
+
symbolize_names: true
|
175
|
+
}
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'passes relevant options to JSON parse' do
|
180
|
+
expect(JSON).to receive(:parse)
|
181
|
+
.with(body, { symbolize_names: true })
|
182
|
+
.and_return(result)
|
183
|
+
|
184
|
+
response = process(body)
|
185
|
+
expect(response.body).to eq(result)
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'passes relevant options to JSON parse even when nil responds to :load' do
|
189
|
+
original_allow_message_expectations_on_nil = RSpec::Mocks.configuration.allow_message_expectations_on_nil
|
190
|
+
RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
|
191
|
+
allow(nil).to receive(:respond_to?)
|
192
|
+
.with(:load)
|
193
|
+
.and_return(true)
|
194
|
+
|
195
|
+
expect(JSON).to receive(:parse)
|
196
|
+
.with(body, { symbolize_names: true })
|
197
|
+
.and_return(result)
|
198
|
+
|
199
|
+
response = process(body)
|
200
|
+
expect(response.body).to eq(result)
|
201
|
+
ensure
|
202
|
+
RSpec::Mocks.configuration.allow_message_expectations_on_nil = original_allow_message_expectations_on_nil
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
117
206
|
end
|
@@ -14,6 +14,7 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
14
14
|
stub.get('request-timeout') { [408, { 'X-Reason' => 'because' }, 'keep looking'] }
|
15
15
|
stub.get('conflict') { [409, { 'X-Reason' => 'because' }, 'keep looking'] }
|
16
16
|
stub.get('unprocessable-entity') { [422, { 'X-Reason' => 'because' }, 'keep looking'] }
|
17
|
+
stub.get('too-many-requests') { [429, { 'X-Reason' => 'because' }, 'keep looking'] }
|
17
18
|
stub.get('4xx') { [499, { 'X-Reason' => 'because' }, 'keep looking'] }
|
18
19
|
stub.get('nil-status') { [nil, { 'X-Reason' => 'nil' }, 'fail'] }
|
19
20
|
stub.get('server-error') { [500, { 'X-Error' => 'bailout' }, 'fail'] }
|
@@ -113,6 +114,17 @@ RSpec.describe Faraday::Response::RaiseError do
|
|
113
114
|
end
|
114
115
|
end
|
115
116
|
|
117
|
+
it 'raises Faraday::TooManyRequestsError for 429 responses' do
|
118
|
+
expect { conn.get('too-many-requests') }.to raise_error(Faraday::TooManyRequestsError) do |ex|
|
119
|
+
expect(ex.message).to eq('the server responded with status 429')
|
120
|
+
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
121
|
+
expect(ex.response[:status]).to eq(429)
|
122
|
+
expect(ex.response_status).to eq(429)
|
123
|
+
expect(ex.response_body).to eq('keep looking')
|
124
|
+
expect(ex.response_headers['X-Reason']).to eq('because')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
116
128
|
it 'raises Faraday::NilStatusError for nil status in response' do
|
117
129
|
expect { conn.get('nil-status') }.to raise_error(Faraday::NilStatusError) do |ex|
|
118
130
|
expect(ex.message).to eq('http status could not be derived from the server response')
|
@@ -56,6 +56,15 @@ RSpec.describe Faraday::Utils::Headers do
|
|
56
56
|
it { expect(subject.delete('content-type')).to be_nil }
|
57
57
|
end
|
58
58
|
|
59
|
+
describe '#dig' do
|
60
|
+
before { subject['Content-Type'] = 'application/json' }
|
61
|
+
|
62
|
+
it { expect(subject&.dig('Content-Type')).to eq('application/json') }
|
63
|
+
it { expect(subject&.dig('CONTENT-TYPE')).to eq('application/json') }
|
64
|
+
it { expect(subject&.dig(:content_type)).to eq('application/json') }
|
65
|
+
it { expect(subject&.dig('invalid')).to be_nil }
|
66
|
+
end
|
67
|
+
|
59
68
|
describe '#parse' do
|
60
69
|
context 'when response headers leave http status line out' do
|
61
70
|
let(:headers) { "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n" }
|
data/spec/faraday_spec.rb
CHANGED
@@ -19,7 +19,9 @@ RSpec.describe Faraday do
|
|
19
19
|
|
20
20
|
it 'uses method_missing on Faraday if there is no proxyable method' do
|
21
21
|
expected_message =
|
22
|
-
if RUBY_VERSION >= '3.
|
22
|
+
if RUBY_VERSION >= '3.4'
|
23
|
+
"undefined method 'this_method_does_not_exist' for module Faraday"
|
24
|
+
elsif RUBY_VERSION >= '3.3'
|
23
25
|
"undefined method `this_method_does_not_exist' for module Faraday"
|
24
26
|
else
|
25
27
|
"undefined method `this_method_does_not_exist' for Faraday:Module"
|
data/spec/spec_helper.rb
CHANGED
@@ -29,14 +29,15 @@ SimpleCov.start do
|
|
29
29
|
minimum_coverage_by_file 26
|
30
30
|
end
|
31
31
|
|
32
|
-
# Ensure all /lib files are loaded
|
33
|
-
# so they will be included in the test coverage report.
|
34
|
-
Dir['./lib/**/*.rb'].sort.each { |file| require file }
|
35
|
-
|
36
32
|
require 'faraday'
|
37
33
|
require 'pry'
|
38
34
|
|
39
|
-
|
35
|
+
# Ensure all /lib files are loaded
|
36
|
+
# so they will be included in the test coverage report.
|
37
|
+
Dir['./lib/**/*.rb'].each { |file| require file }
|
38
|
+
|
39
|
+
# Load all Rspec support files
|
40
|
+
Dir['./spec/support/**/*.rb'].each { |file| require file }
|
40
41
|
|
41
42
|
RSpec.configure do |config|
|
42
43
|
# rspec-expectations config goes here. You can use an alternate
|
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: 2.
|
4
|
+
version: 2.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@technoweenie"
|
@@ -10,22 +10,8 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-06-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: base64
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
requirements:
|
19
|
-
- - ">="
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
requirements:
|
26
|
-
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
version: '0'
|
29
15
|
- !ruby/object:Gem::Dependency
|
30
16
|
name: faraday-net_http
|
31
17
|
requirement: !ruby/object:Gem::Requirement
|
@@ -35,7 +21,7 @@ dependencies:
|
|
35
21
|
version: '2.0'
|
36
22
|
- - "<"
|
37
23
|
- !ruby/object:Gem::Version
|
38
|
-
version: '3.
|
24
|
+
version: '3.2'
|
39
25
|
type: :runtime
|
40
26
|
prerelease: false
|
41
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -45,21 +31,7 @@ dependencies:
|
|
45
31
|
version: '2.0'
|
46
32
|
- - "<"
|
47
33
|
- !ruby/object:Gem::Version
|
48
|
-
version: '3.
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: ruby2_keywords
|
51
|
-
requirement: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 0.0.4
|
56
|
-
type: :runtime
|
57
|
-
prerelease: false
|
58
|
-
version_requirements: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 0.0.4
|
34
|
+
version: '3.2'
|
63
35
|
description:
|
64
36
|
email: technoweenie@gmail.com
|
65
37
|
executables: []
|
@@ -145,7 +117,7 @@ licenses:
|
|
145
117
|
- MIT
|
146
118
|
metadata:
|
147
119
|
homepage_uri: https://lostisland.github.io/faraday
|
148
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.
|
120
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.9.2
|
149
121
|
source_code_uri: https://github.com/lostisland/faraday
|
150
122
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
151
123
|
post_install_message:
|
@@ -157,14 +129,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
129
|
requirements:
|
158
130
|
- - ">="
|
159
131
|
- !ruby/object:Gem::Version
|
160
|
-
version: '
|
132
|
+
version: '3.0'
|
161
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
134
|
requirements:
|
163
135
|
- - ">="
|
164
136
|
- !ruby/object:Gem::Version
|
165
137
|
version: '0'
|
166
138
|
requirements: []
|
167
|
-
rubygems_version: 3.
|
139
|
+
rubygems_version: 3.5.11
|
168
140
|
signing_key:
|
169
141
|
specification_version: 4
|
170
142
|
summary: HTTP/REST API client library.
|