faraday 1.10.0 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/faraday/connection.rb +15 -15
- data/lib/faraday/deprecate.rb +110 -0
- data/lib/faraday/request.rb +3 -4
- data/lib/faraday/version.rb +1 -1
- data/spec/faraday/deprecate_spec.rb +147 -0
- data/spec/faraday/request_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '04749d3979d4a9915c3370ec09dcf6155a2e8d4853d3678258224d77c99604d0'
|
4
|
+
data.tar.gz: 6a63e7608e50809a9d5fe4b1abefce9a0857a6095829bd5e631b893257899fae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a71c4649227869ac7f1b5fa6e59bac3587a8080011da3acf6ad5426e890d64be2809b0ad0a2d04bceb8bc08a0c4f2c1b20841429e0d6bde6f69dccf7a707ca5
|
7
|
+
data.tar.gz: 86f69b8d0c7af7ed0b37f0ce4accaf2a9b286489e70f175ffbdc7161c50126747fa32fb56a243b7cb38b8682164d7e9e14e8c3ee28b27dd8fc86a800054d15a7
|
data/lib/faraday/connection.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'faraday/deprecate'
|
4
|
+
|
3
5
|
module Faraday
|
4
6
|
# Connection objects manage the default properties and the middleware
|
5
7
|
# stack for fulfilling an HTTP request.
|
@@ -297,14 +299,12 @@ module Faraday
|
|
297
299
|
#
|
298
300
|
# @return [void]
|
299
301
|
def basic_auth(login, pass)
|
300
|
-
warn <<~TEXT
|
301
|
-
WARNING: `Faraday::Connection#basic_auth` is deprecated; it will be removed in version 2.0.
|
302
|
-
While initializing your connection, use `#request(:basic_auth, ...)` instead.
|
303
|
-
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
|
304
|
-
TEXT
|
305
302
|
set_authorization_header(:basic_auth, login, pass)
|
306
303
|
end
|
307
304
|
|
305
|
+
extend Faraday::Deprecate
|
306
|
+
deprecate :basic_auth, '#request(:basic_auth, ...)', '2.0'
|
307
|
+
|
308
308
|
# Sets up the Authorization header with the given token.
|
309
309
|
#
|
310
310
|
# @param token [String]
|
@@ -319,14 +319,14 @@ module Faraday
|
|
319
319
|
#
|
320
320
|
# @return [void]
|
321
321
|
def token_auth(token, options = nil)
|
322
|
-
warn <<~TEXT
|
323
|
-
WARNING: `Faraday::Connection#token_auth` is deprecated; it will be removed in version 2.0.
|
324
|
-
While initializing your connection, use `#request(:token_auth, ...)` instead.
|
325
|
-
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
|
326
|
-
TEXT
|
327
322
|
set_authorization_header(:token_auth, token, options)
|
328
323
|
end
|
329
324
|
|
325
|
+
deprecate :token_auth,
|
326
|
+
'#request(:token_auth, ...)',
|
327
|
+
'2.0',
|
328
|
+
'See https://lostisland.github.io/faraday/middleware/authentication for more usage info.'
|
329
|
+
|
330
330
|
# Sets up a custom Authorization header.
|
331
331
|
#
|
332
332
|
# @param type [String] authorization type
|
@@ -346,14 +346,14 @@ module Faraday
|
|
346
346
|
#
|
347
347
|
# @return [void]
|
348
348
|
def authorization(type, token)
|
349
|
-
warn <<~TEXT
|
350
|
-
WARNING: `Faraday::Connection#authorization` is deprecated; it will be removed in version 2.0.
|
351
|
-
While initializing your connection, use `#request(:authorization, ...)` instead.
|
352
|
-
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
|
353
|
-
TEXT
|
354
349
|
set_authorization_header(:authorization, type, token)
|
355
350
|
end
|
356
351
|
|
352
|
+
deprecate :authorization,
|
353
|
+
'#request(:authorization, ...)',
|
354
|
+
'2.0',
|
355
|
+
'See https://lostisland.github.io/faraday/middleware/authentication for more usage info.'
|
356
|
+
|
357
357
|
# Check if the adapter is parallel-capable.
|
358
358
|
#
|
359
359
|
# @yield if the adapter isn't parallel-capable, or if no adapter is set yet.
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
# @param new_klass [Class] new Klass to use
|
5
|
+
#
|
6
|
+
# @return [Class] A modified version of new_klass that warns on
|
7
|
+
# usage about deprecation.
|
8
|
+
# @see Faraday::Deprecate
|
9
|
+
module DeprecatedClass
|
10
|
+
def self.proxy_class(origclass, ver = '1.0')
|
11
|
+
proxy = Class.new(origclass) do
|
12
|
+
const_set('ORIG_CLASS', origclass)
|
13
|
+
|
14
|
+
class << self
|
15
|
+
extend Faraday::Deprecate
|
16
|
+
|
17
|
+
def ===(other)
|
18
|
+
(superclass == const_get('ORIG_CLASS') && other.is_a?(superclass)) || super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
proxy.singleton_class.send(:deprecate, :new, "#{origclass}.new", ver)
|
23
|
+
proxy.singleton_class.send(:deprecate, :inherited, origclass.name, ver)
|
24
|
+
proxy
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Deprecation using semver instead of date, based on Gem::Deprecate
|
29
|
+
# Provides a single method +deprecate+ to be used to declare when
|
30
|
+
# something is going away.
|
31
|
+
#
|
32
|
+
# class Legacy
|
33
|
+
# def self.klass_method
|
34
|
+
# # ...
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# def instance_method
|
38
|
+
# # ...
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# extend Faraday::Deprecate
|
42
|
+
# deprecate :instance_method, "X.z", '1.0'
|
43
|
+
#
|
44
|
+
# class << self
|
45
|
+
# extend Faraday::Deprecate
|
46
|
+
# deprecate :klass_method, :none, '1.0'
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
module Deprecate
|
50
|
+
def self.skip # :nodoc:
|
51
|
+
@skip ||= begin
|
52
|
+
case ENV['FARADAY_DEPRECATE'].to_s.downcase
|
53
|
+
when '1', 'warn' then :warn
|
54
|
+
else :skip
|
55
|
+
end
|
56
|
+
end
|
57
|
+
@skip == :skip
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.skip=(value) # :nodoc:
|
61
|
+
@skip = value ? :skip : :warn
|
62
|
+
end
|
63
|
+
|
64
|
+
# Temporarily turn off warnings. Intended for tests only.
|
65
|
+
def skip_during
|
66
|
+
original = Faraday::Deprecate.skip
|
67
|
+
Faraday::Deprecate.skip = true
|
68
|
+
yield
|
69
|
+
ensure
|
70
|
+
Faraday::Deprecate.skip = original
|
71
|
+
end
|
72
|
+
|
73
|
+
# Simple deprecation method that deprecates +name+ by wrapping it up
|
74
|
+
# in a dummy method. It warns on each call to the dummy method
|
75
|
+
# telling the user of +repl+ (unless +repl+ is :none) and the
|
76
|
+
# semver that it is planned to go away.
|
77
|
+
# @param name [Symbol] the method symbol to deprecate
|
78
|
+
# @param repl [#to_s, :none] the replacement to use, when `:none` it will
|
79
|
+
# alert the user that no replacement is present.
|
80
|
+
# @param ver [String] the semver the method will be removed.
|
81
|
+
def deprecate(name, repl, ver, custom_message = nil)
|
82
|
+
class_eval do
|
83
|
+
gem_ver = Gem::Version.new(ver)
|
84
|
+
old = "_deprecated_#{name}"
|
85
|
+
alias_method old, name
|
86
|
+
define_method name do |*args, &block|
|
87
|
+
mod = is_a? Module
|
88
|
+
target = mod ? "#{self}." : "#{self.class}#"
|
89
|
+
target_message = if name == :inherited
|
90
|
+
"Inheriting #{self}"
|
91
|
+
else
|
92
|
+
"#{target}#{name}"
|
93
|
+
end
|
94
|
+
|
95
|
+
msg = [
|
96
|
+
"NOTE: #{target_message} is deprecated",
|
97
|
+
repl == :none ? ' with no replacement' : "; use #{repl} instead. ",
|
98
|
+
"It will be removed in or after version #{gem_ver} ",
|
99
|
+
custom_message,
|
100
|
+
"\n#{target}#{name} called from #{Gem.location_of_caller.join(':')}"
|
101
|
+
]
|
102
|
+
warn "#{msg.join}." unless Faraday::Deprecate.skip
|
103
|
+
send old, *args, &block
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
module_function :deprecate, :skip_during
|
109
|
+
end
|
110
|
+
end
|
data/lib/faraday/request.rb
CHANGED
@@ -58,13 +58,12 @@ module Faraday
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def method
|
61
|
-
warn <<~TEXT
|
62
|
-
WARNING: `Faraday::Request##{__method__}` is deprecated; use `#http_method` instead. It will be removed in or after version 2.0.
|
63
|
-
`Faraday::Request##{__method__}` called from #{caller_locations(1..1).first}
|
64
|
-
TEXT
|
65
61
|
http_method
|
66
62
|
end
|
67
63
|
|
64
|
+
extend Faraday::Deprecate
|
65
|
+
deprecate :method, :http_method, '2.0'
|
66
|
+
|
68
67
|
# Replace params, preserving the existing hash type.
|
69
68
|
#
|
70
69
|
# @param hash [Hash] new params
|
data/lib/faraday/version.rb
CHANGED
@@ -0,0 +1,147 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Faraday::DeprecatedClass do
|
4
|
+
class SampleClass < StandardError
|
5
|
+
attr_accessor :foo
|
6
|
+
|
7
|
+
def initialize(foo = nil)
|
8
|
+
@foo = foo || :foo
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
SampleDeprecatedClass = Faraday::DeprecatedClass.proxy_class(SampleClass)
|
13
|
+
|
14
|
+
it 'does not raise error for deprecated classes but prints an error message' do
|
15
|
+
error_message, foobar = with_warn_squelching { SampleDeprecatedClass.new(:foo_bar) }
|
16
|
+
expect(foobar).to be_a(SampleClass)
|
17
|
+
expect(foobar.foo).to eq(:foo_bar)
|
18
|
+
expect(error_message).to match(
|
19
|
+
Regexp.new(
|
20
|
+
'NOTE: SampleDeprecatedClass.new is deprecated; '\
|
21
|
+
'use SampleClass.new instead. It will be removed in or after version 1.0'
|
22
|
+
)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'does not raise an error for inherited error-namespaced classes but prints an error message' do
|
27
|
+
error_message, = with_warn_squelching { Class.new(SampleDeprecatedClass) }
|
28
|
+
|
29
|
+
expect(error_message).to match(
|
30
|
+
Regexp.new(
|
31
|
+
'NOTE: Inheriting SampleDeprecatedClass is deprecated; '\
|
32
|
+
'use SampleClass instead. It will be removed in or after version 1.0'
|
33
|
+
)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'allows backward-compatible class to be subclassed' do
|
38
|
+
expect do
|
39
|
+
with_warn_squelching { Class.new(SampleDeprecatedClass) }
|
40
|
+
end.not_to raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'allows rescuing of a current error with a deprecated error' do
|
44
|
+
expect { raise SampleClass, nil }.to raise_error(SampleDeprecatedClass)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'allows rescuing of a current error with a current error' do
|
48
|
+
expect { raise SampleClass, nil }.to raise_error(SampleClass)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'allows rescuing of a deprecated error with a deprecated error' do
|
52
|
+
expect { raise SampleDeprecatedClass, nil }.to raise_error(SampleDeprecatedClass)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'allows rescuing of a deprecated error with a current error' do
|
56
|
+
expect { raise SampleDeprecatedClass, nil }.to raise_error(SampleClass)
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'match behavior' do
|
60
|
+
class SampleDeprecatedClassA < SampleDeprecatedClass; end
|
61
|
+
class SampleDeprecatedClassB < SampleDeprecatedClass; end
|
62
|
+
|
63
|
+
class SampleDeprecatedClassAX < SampleDeprecatedClassA; end
|
64
|
+
|
65
|
+
class SampleClassA < SampleClass; end
|
66
|
+
|
67
|
+
describe 'undeprecated class' do
|
68
|
+
it 'is === to instance of deprecated class' do
|
69
|
+
expect(SampleDeprecatedClass.new.is_a?(SampleClass)).to be true
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'is === to instance of subclass of deprecated class' do
|
73
|
+
expect(SampleDeprecatedClassA.new.is_a?(SampleClass)).to be true
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'is === to instance of subclass of subclass of deprecated class' do
|
77
|
+
expect(SampleDeprecatedClassAX.new.is_a?(SampleClass)).to be true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'subclass of undeprecated class' do
|
82
|
+
it 'is not === to instance of undeprecated class' do
|
83
|
+
expect(SampleClass.new.is_a?(SampleClassA)).to be false
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'is not === to instance of deprecated class' do
|
87
|
+
expect(SampleDeprecatedClass.new.is_a?(SampleClassA)).to be false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'deprecated class' do
|
92
|
+
it 'is === to instance of undeprecated class' do
|
93
|
+
expect(SampleDeprecatedClass.new.is_a?(SampleClass)).to be true
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'is === to instance of subclass of undeprecated class' do
|
97
|
+
expect(SampleClassA.superclass == SampleDeprecatedClass.superclass).to be true
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'is === to instance of subclass of deprecated class' do
|
101
|
+
expect(SampleDeprecatedClassA.new.is_a?(SampleDeprecatedClass)).to be true
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'is === to instance of subclass of subclass of deprecated class' do
|
105
|
+
expect(SampleDeprecatedClassAX.new.is_a?(SampleDeprecatedClass)).to be true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'subclass of deprecated class' do
|
110
|
+
it 'is not === to instance of subclass of undeprecated class' do
|
111
|
+
expect(SampleClass.new.is_a?(SampleDeprecatedClassA)).to be false
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'is not === to instance of another subclass of deprecated class' do
|
115
|
+
expect(SampleDeprecatedClassB.new.is_a?(SampleDeprecatedClassA)).to be false
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'is === to instance of its subclass' do
|
119
|
+
expect(SampleDeprecatedClassAX.new.is_a?(SampleDeprecatedClassA)).to be true
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'is === to instance of deprecated class' do
|
123
|
+
expect(SampleDeprecatedClassB.new.is_a?(SampleDeprecatedClass)).to be true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe 'subclass of subclass of deprecated class' do
|
128
|
+
it 'is not === to instance of subclass of another subclass of deprecated class' do
|
129
|
+
expect(SampleDeprecatedClassB.new.is_a?(SampleDeprecatedClassAX)).to be false
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'is not === to instance of its superclass' do
|
133
|
+
expect(SampleDeprecatedClass.new.is_a?(SampleDeprecatedClassA)).to be false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def with_warn_squelching
|
139
|
+
stderr_catcher = StringIO.new
|
140
|
+
original_stderr = $stderr
|
141
|
+
$stderr = stderr_catcher
|
142
|
+
result = yield if block_given?
|
143
|
+
[stderr_catcher.tap(&:rewind).string, result]
|
144
|
+
ensure
|
145
|
+
$stderr = original_stderr
|
146
|
+
end
|
147
|
+
end
|
@@ -25,7 +25,7 @@ RSpec.describe Faraday::Request do
|
|
25
25
|
describe 'deprecate method for HTTP method' do
|
26
26
|
let(:http_method) { :post }
|
27
27
|
let(:expected_warning) do
|
28
|
-
%r{
|
28
|
+
%r{NOTE: Faraday::Request#method is deprecated; use http_method instead\. It will be removed in or after version 2.0 \nFaraday::Request#method called from .+/spec/faraday/request_spec.rb:\d+.}
|
29
29
|
end
|
30
30
|
|
31
31
|
it { expect(subject.method).to eq(:post) }
|
data/spec/spec_helper.rb
CHANGED
@@ -38,6 +38,8 @@ require 'pry'
|
|
38
38
|
|
39
39
|
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
|
40
40
|
|
41
|
+
Faraday::Deprecate.skip = false
|
42
|
+
|
41
43
|
RSpec.configure do |config|
|
42
44
|
# rspec-expectations config goes here. You can use an alternate
|
43
45
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
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: 1.10.
|
4
|
+
version: 1.10.2
|
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: 2022-
|
13
|
+
date: 2022-08-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday-em_http
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- lib/faraday/autoload.rb
|
187
187
|
- lib/faraday/connection.rb
|
188
188
|
- lib/faraday/dependency_loader.rb
|
189
|
+
- lib/faraday/deprecate.rb
|
189
190
|
- lib/faraday/encoders/flat_params_encoder.rb
|
190
191
|
- lib/faraday/encoders/nested_params_encoder.rb
|
191
192
|
- lib/faraday/error.rb
|
@@ -230,6 +231,7 @@ files:
|
|
230
231
|
- spec/faraday/adapter_spec.rb
|
231
232
|
- spec/faraday/composite_read_io_spec.rb
|
232
233
|
- spec/faraday/connection_spec.rb
|
234
|
+
- spec/faraday/deprecate_spec.rb
|
233
235
|
- spec/faraday/error_spec.rb
|
234
236
|
- spec/faraday/middleware_spec.rb
|
235
237
|
- spec/faraday/options/env_spec.rb
|
@@ -266,7 +268,7 @@ licenses:
|
|
266
268
|
- MIT
|
267
269
|
metadata:
|
268
270
|
homepage_uri: https://lostisland.github.io/faraday
|
269
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.10.
|
271
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.10.2
|
270
272
|
source_code_uri: https://github.com/lostisland/faraday
|
271
273
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
272
274
|
post_install_message:
|