Skip to content

Commit 322785d

Browse files
committed
Drop old ruby support
Keeping 2.7 even though its EOL because kind john is kind.
1 parent ca47360 commit 322785d

File tree

6 files changed

+69
-107
lines changed

6 files changed

+69
-107
lines changed

.github/workflows/ci.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ jobs:
66
strategy:
77
matrix:
88
ruby:
9-
- 2.3
10-
- 2.4
11-
- 2.5
12-
- 2.6
139
- 2.7
14-
- '3.0' # Quoted, to avoid YAML float 3.0 interplated to "3"
10+
- "3.0" # Quoted, to avoid YAML float 3.0 interplated to "3"
1511
- 3.1
1612
- 3.2
1713
- 3.3

httparty.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
1313
s.summary = 'Makes http fun! Also, makes consuming restful web services dead easy.'
1414
s.description = 'Makes http fun! Also, makes consuming restful web services dead easy.'
1515

16-
s.required_ruby_version = '>= 2.3.0'
16+
s.required_ruby_version = '>= 2.7.0'
1717

1818
s.add_dependency 'csv'
1919
s.add_dependency 'multi_xml', ">= 0.5.2"

lib/httparty/connection_adapter.rb

+5-24
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ def connection
119119
if add_timeout?(options[:timeout])
120120
http.open_timeout = options[:timeout]
121121
http.read_timeout = options[:timeout]
122-
123-
from_ruby_version('2.6.0', option: :write_timeout, warn: false) do
124-
http.write_timeout = options[:timeout]
125-
end
122+
http.write_timeout = options[:timeout]
126123
end
127124

128125
if add_timeout?(options[:read_timeout])
@@ -134,15 +131,11 @@ def connection
134131
end
135132

136133
if add_timeout?(options[:write_timeout])
137-
from_ruby_version('2.6.0', option: :write_timeout) do
138-
http.write_timeout = options[:write_timeout]
139-
end
134+
http.write_timeout = options[:write_timeout]
140135
end
141136

142137
if add_max_retries?(options[:max_retries])
143-
from_ruby_version('2.5.0', option: :max_retries) do
144-
http.max_retries = options[:max_retries]
145-
end
138+
http.max_retries = options[:max_retries]
146139
end
147140

148141
if options[:debug_output]
@@ -157,30 +150,18 @@ def connection
157150
#
158151
# @see https://bugs.ruby-lang.org/issues/6617
159152
if options[:local_host]
160-
from_ruby_version('2.0.0', option: :local_host) do
161-
http.local_host = options[:local_host]
162-
end
153+
http.local_host = options[:local_host]
163154
end
164155

165156
if options[:local_port]
166-
from_ruby_version('2.0.0', option: :local_port) do
167-
http.local_port = options[:local_port]
168-
end
157+
http.local_port = options[:local_port]
169158
end
170159

171160
http
172161
end
173162

174163
private
175164

176-
def from_ruby_version(ruby_version, option: nil, warn: true)
177-
if RUBY_VERSION >= ruby_version
178-
yield
179-
elsif warn
180-
Kernel.warn("Warning: option #{ option } requires Ruby version #{ ruby_version } or later")
181-
end
182-
end
183-
184165
def add_timeout?(timeout)
185166
timeout && (timeout.is_a?(Integer) || timeout.is_a?(Float))
186167
end

lib/httparty/response.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ def inspect
6767
end
6868

6969
# Support old multiple_choice? method from pre 2.0.0 era.
70-
if ::RUBY_VERSION >= '2.0.0' && ::RUBY_PLATFORM != 'java'
70+
if ::RUBY_PLATFORM != 'java'
7171
alias_method :multiple_choice?, :multiple_choices?
7272
end
7373

7474
# Support old status codes method from pre 2.6.0 era.
75-
if ::RUBY_VERSION >= '2.6.0' && ::RUBY_PLATFORM != 'java'
75+
if ::RUBY_PLATFORM != 'java'
7676
alias_method :gateway_time_out?, :gateway_timeout?
7777
alias_method :request_entity_too_large?, :payload_too_large?
7878
alias_method :request_time_out?, :request_timeout?

spec/httparty/connection_adapter_spec.rb

+58-72
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
it "sets ssl version" do
103103
expect(subject.ssl_version).to eq(:TLSv1)
104104
end
105-
end if RUBY_VERSION > '1.9'
105+
end
106106
end
107107

108108
context "when dealing with IPv6" do
@@ -119,7 +119,7 @@
119119
it "should set the ciphers on the connection" do
120120
expect(subject.ciphers).to eq('RC4-SHA')
121121
end
122-
end if RUBY_VERSION > '1.9'
122+
end
123123

124124
context "when timeout is not set" do
125125
it "doesn't set the timeout" do
@@ -152,11 +152,9 @@
152152
it { is_expected.to eq(5) }
153153
end
154154

155-
if RUBY_VERSION >= '2.6.0'
156-
describe '#write_timeout' do
157-
subject { super().write_timeout }
158-
it { is_expected.to eq(5) }
159-
end
155+
describe '#write_timeout' do
156+
subject { super().write_timeout }
157+
it { is_expected.to eq(5) }
160158
end
161159
end
162160

@@ -223,11 +221,9 @@
223221
it { is_expected.to eq(5) }
224222
end
225223

226-
if RUBY_VERSION >= '2.6.0'
227-
describe '#write_timeout' do
228-
subject { super().write_timeout }
229-
it { is_expected.to eq(5) }
230-
end
224+
describe '#write_timeout' do
225+
subject { super().write_timeout }
226+
it { is_expected.to eq(5) }
231227
end
232228

233229
describe '#read_timeout' do
@@ -247,9 +243,7 @@
247243
)
248244
expect(http).to receive(:open_timeout=)
249245
expect(http).to receive(:read_timeout=).twice
250-
if RUBY_VERSION >= '2.6.0'
251-
expect(http).to receive(:write_timeout=)
252-
end
246+
expect(http).to receive(:write_timeout=)
253247
allow(Net::HTTP).to receive_messages(new: http)
254248
adapter.connection
255249
end
@@ -298,11 +292,9 @@
298292
it { is_expected.to eq(7) }
299293
end
300294

301-
if RUBY_VERSION >= '2.6.0'
302-
describe '#write_timeout' do
303-
subject { super().write_timeout }
304-
it { is_expected.to eq(5) }
305-
end
295+
describe '#write_timeout' do
296+
subject { super().write_timeout }
297+
it { is_expected.to eq(5) }
306298
end
307299

308300
describe '#read_timeout' do
@@ -322,54 +314,50 @@
322314
)
323315
expect(http).to receive(:open_timeout=).twice
324316
expect(http).to receive(:read_timeout=)
325-
if RUBY_VERSION >= '2.6.0'
326-
expect(http).to receive(:write_timeout=)
327-
end
317+
expect(http).to receive(:write_timeout=)
328318
allow(Net::HTTP).to receive_messages(new: http)
329319
adapter.connection
330320
end
331321
end
332322

333-
if RUBY_VERSION >= '2.6.0'
334-
context "when timeout is not set and write_timeout is set to 8 seconds" do
335-
let(:options) { {write_timeout: 8} }
323+
context "when timeout is not set and write_timeout is set to 8 seconds" do
324+
let(:options) { {write_timeout: 8} }
336325

337-
describe '#write_timeout' do
338-
subject { super().write_timeout }
339-
it { is_expected.to eq(8) }
340-
end
326+
describe '#write_timeout' do
327+
subject { super().write_timeout }
328+
it { is_expected.to eq(8) }
329+
end
341330

342-
it "should not set the open timeout" do
343-
http = double(
344-
"http",
345-
:null_object => true,
346-
:use_ssl= => false,
347-
:use_ssl? => false,
348-
:read_timeout= => 0,
349-
:open_timeout= => 0,
350-
:write_timeout= => 0,
331+
it "should not set the open timeout" do
332+
http = double(
333+
"http",
334+
:null_object => true,
335+
:use_ssl= => false,
336+
:use_ssl? => false,
337+
:read_timeout= => 0,
338+
:open_timeout= => 0,
339+
:write_timeout= => 0,
351340

352-
)
353-
expect(http).not_to receive(:open_timeout=)
354-
allow(Net::HTTP).to receive_messages(new: http)
355-
adapter.connection
356-
end
341+
)
342+
expect(http).not_to receive(:open_timeout=)
343+
allow(Net::HTTP).to receive_messages(new: http)
344+
adapter.connection
345+
end
357346

358-
it "should not set the read timeout" do
359-
http = double(
360-
"http",
361-
:null_object => true,
362-
:use_ssl= => false,
363-
:use_ssl? => false,
364-
:read_timeout= => 0,
365-
:open_timeout= => 0,
366-
:write_timeout= => 0,
347+
it "should not set the read timeout" do
348+
http = double(
349+
"http",
350+
:null_object => true,
351+
:use_ssl= => false,
352+
:use_ssl? => false,
353+
:read_timeout= => 0,
354+
:open_timeout= => 0,
355+
:write_timeout= => 0,
367356

368-
)
369-
expect(http).not_to receive(:read_timeout=)
370-
allow(Net::HTTP).to receive_messages(new: http)
371-
adapter.connection
372-
end
357+
)
358+
expect(http).not_to receive(:read_timeout=)
359+
allow(Net::HTTP).to receive_messages(new: http)
360+
adapter.connection
373361
end
374362

375363
context "when timeout is set and write_timeout is set to 8 seconds" do
@@ -415,21 +403,19 @@
415403
end
416404

417405
context "when setting max_retries" do
418-
if RUBY_VERSION >= '2.5.0'
419-
context "to 5 times" do
420-
let(:options) { {max_retries: 5} }
421-
describe '#max_retries' do
422-
subject { super().max_retries }
423-
it { is_expected.to eq(5) }
424-
end
406+
context "to 5 times" do
407+
let(:options) { {max_retries: 5} }
408+
describe '#max_retries' do
409+
subject { super().max_retries }
410+
it { is_expected.to eq(5) }
425411
end
412+
end
426413

427-
context "to 0 times" do
428-
let(:options) { {max_retries: 0} }
429-
describe '#max_retries' do
430-
subject { super().max_retries }
431-
it { is_expected.to eq(0) }
432-
end
414+
context "to 0 times" do
415+
let(:options) { {max_retries: 0} }
416+
describe '#max_retries' do
417+
subject { super().max_retries }
418+
it { is_expected.to eq(0) }
433419
end
434420
end
435421

@@ -545,7 +531,7 @@
545531
subject { super().local_port }
546532
it { is_expected.to eq(12345) }
547533
end
548-
end if RUBY_VERSION >= '2.0'
534+
end
549535

550536
context "when providing PEM certificates" do
551537
let(:pem) { :pem_contents }

spec/httparty/response_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,12 @@ def response_mock(klass)
305305
version_not_supported?: Net::HTTPVersionNotSupported
306306
}
307307

308-
# Ruby 2.0, new name for this response.
309-
if RUBY_VERSION >= "2.0.0" && ::RUBY_PLATFORM != "java"
308+
if ::RUBY_PLATFORM != "java"
310309
SPECIFIC_CODES[:multiple_choices?] = Net::HTTPMultipleChoices
311310
end
312311

313312
# Ruby 2.6, those status codes have been updated.
314-
if RUBY_VERSION >= "2.6.0" && ::RUBY_PLATFORM != "java"
313+
if ::RUBY_PLATFORM != "java"
315314
SPECIFIC_CODES[:gateway_timeout?] = Net::HTTPGatewayTimeout
316315
SPECIFIC_CODES[:payload_too_large?] = Net::HTTPPayloadTooLarge
317316
SPECIFIC_CODES[:request_timeout?] = Net::HTTPRequestTimeout

0 commit comments

Comments
 (0)