faraday 2.8.1 → 2.9.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: 14056963c7f6d474cd9c3a407ea2bfbe9e9fd2246b3b3a69aa57585668bc0739
4
- data.tar.gz: d8d3125754e43fdfdfbaf134d53d2e6524944cd68422f7b10b13fb587a9ff288
3
+ metadata.gz: fbbd7a7b6e5382874543228f830a4a39eb1a361a1bfcd62b6e2f0eb263419745
4
+ data.tar.gz: 60e27b5daa918f03860755e49e121729478956eac286636b50cc116118a9936d
5
5
  SHA512:
6
- metadata.gz: 026fcfad3c5696d387f4bd68c6ddbe36ef6b13a640771209954adf4fb191d27e8fcc13af61b23645cba44cf4f92c71e720a3e7d022081402143b8639ca0a8fa7
7
- data.tar.gz: 21bce5de8543dc53735214b7a35d6dcf3387f93be56e1a1c575522ce07e66d6de555fbb5673aede73f3fa9ca3fa3613e06a5aa7e9a63035b8028553f2cb4ccfe
6
+ metadata.gz: 9fff33c6bfa400da8b05d91329bb69fda8e09b0b3d686651017b6025f947a98fc4e4c3608af72a5e814e40fb5da701bd6b29f53a9768ee27820e2238c33a9840
7
+ data.tar.gz: bd9a550f1f0d99284e9d619749396fa32ef00a0febd22f700e0f2ce5e9675f73d66d18e2302eb987f384b9bbb39e2f8b317546f79dcce2a60b5ad00cf364d953
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 2.6+
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
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rspec/core/rake_task'
4
+ require 'bundler'
5
+
6
+ Bundler::GemHelper.install_tasks
4
7
 
5
8
  RSpec::Core::RakeTask.new(:spec) do |task|
6
9
  task.ruby_opts = %w[-W]
@@ -26,7 +26,7 @@ module Faraday
26
26
  self.supports_parallel = false
27
27
 
28
28
  def initialize(_app = nil, opts = {}, &block)
29
- @app = ->(env) { env.response }
29
+ @app = lambda(&:response)
30
30
  @connection_options = opts
31
31
  @config_block = block
32
32
  end
@@ -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]
@@ -102,7 +102,7 @@ module Faraday
102
102
 
103
103
  protected
104
104
 
105
- SUBKEYS_REGEX = /[^\[\]]+(?:\]?\[\])?/.freeze
105
+ SUBKEYS_REGEX = /[^\[\]]+(?:\]?\[\])?/
106
106
 
107
107
  def decode_pair(key, value, context)
108
108
  subkeys = key.scan(SUBKEYS_REGEX)
@@ -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).freeze)
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| # rubocop:disable Performance/RedundantBlockCall
172
+ block_result = block.call do |chunk|
173
173
  if chunk.bytesize.positive? || size.positive?
174
174
  yielded = true
175
175
  size += chunk.bytesize
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ruby2_keywords'
4
3
  require 'faraday/adapter_registry'
5
4
 
6
5
  module Faraday
@@ -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$}.freeze
16
+ MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}
17
17
 
18
18
  def on_request(env)
19
19
  match_content_type(env) do |data|
@@ -60,7 +60,8 @@ module Faraday
60
60
  @decoder_options =
61
61
  if @decoder_options.is_a?(Array) && @decoder_options.size >= 2
62
62
  @decoder_options.slice(0, 2)
63
- elsif @decoder_options.respond_to?(:load)
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
64
65
  [@decoder_options, :load]
65
66
  else
66
67
  [::JSON, :parse]
@@ -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).freeze
10
- ServerErrorStatuses = (500...600).freeze
9
+ ClientErrorStatuses = (400...500)
10
+ ServerErrorStatuses = (500...600)
11
11
  # rubocop:enable Naming/ConstantName
12
12
 
13
13
  def on_complete(env)
@@ -62,10 +62,10 @@ module Faraday
62
62
  super(key, val)
63
63
  end
64
64
 
65
- def fetch(key, *args, &block)
65
+ def fetch(key, ...)
66
66
  key = KeyMap[key]
67
67
  key = @names.fetch(key.downcase, key)
68
- super(key, *args, &block)
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 .~_-]/.freeze
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.freeze
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 = Base64.encode64("#{login}:#{pass}")
56
+ value = ["#{login}:#{pass}"].pack('m') # Base64 encoding
58
57
  value.delete!("\n")
59
58
  "Basic #{value}"
60
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '2.8.1'
4
+ VERSION = '2.9.1'
5
5
  end
@@ -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
- expected = Rack::Utils.build_nested_query(params).split('&')
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
 
@@ -184,6 +184,23 @@ RSpec.describe Faraday::Response::Json, type: :response do
184
184
  response = process(body)
185
185
  expect(response.body).to eq(result)
186
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
187
204
  end
188
205
  end
189
206
  end
@@ -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.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
- Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
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.8.1
4
+ version: 2.9.1
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: 2023-12-21 00:00:00.000000000 Z
13
+ date: 2024-06-05 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.1'
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.1'
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.8.1
120
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.9.1
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: '2.6'
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.1.6
139
+ rubygems_version: 3.5.9
168
140
  signing_key:
169
141
  specification_version: 4
170
142
  summary: HTTP/REST API client library.