From 14dcd6b60e79465cc74ef9f89d69dfb5f38bbb36 Mon Sep 17 00:00:00 2001 From: shashank mehra Date: Tue, 30 Jan 2024 17:24:21 +0530 Subject: [PATCH 1/3] Support Faraday version 2.X --- lib/rabbitmq/http/client.rb | 10 +++++++--- lib/rabbitmq/http/client/health_checks.rb | 2 +- lib/rabbitmq/http/client/request_helper.rb | 2 +- lib/rabbitmq/http/client/response_helper.rb | 2 +- rabbitmq_http_api_client.gemspec | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/rabbitmq/http/client.rb b/lib/rabbitmq/http/client.rb index 0c7f854..fe42e1f 100644 --- a/lib/rabbitmq/http/client.rb +++ b/lib/rabbitmq/http/client.rb @@ -1,7 +1,7 @@ require "addressable/uri" require "hashie" require "faraday" -require "faraday_middleware" +require "faraday/follow_redirects" require "multi_json" require "uri" @@ -450,9 +450,13 @@ def initialize_connection(endpoint, options = {}) adapter = options.delete(:adapter) || Faraday.default_adapter @connection = Faraday.new(options) do |conn| - conn.request :basic_auth, user, password + if Gem::Version.new(Faraday::VERSION) < Gem::Version.new("2.0") + conn.request :basic_auth, user, password + else + conn.request :authorization, :basic, user, password + end - conn.use FaradayMiddleware::FollowRedirects, :limit => 3 + conn.use Faraday::FollowRedirects::Middleware, :limit => 3 conn.use Faraday::Response::RaiseError conn.response :json, :content_type => /\bjson$/ diff --git a/lib/rabbitmq/http/client/health_checks.rb b/lib/rabbitmq/http/client/health_checks.rb index 47e5b81..6cdc50d 100644 --- a/lib/rabbitmq/http/client/health_checks.rb +++ b/lib/rabbitmq/http/client/health_checks.rb @@ -1,6 +1,6 @@ require "hashie" require "faraday" -require "faraday_middleware" +require "faraday/follow_redirects" require "multi_json" require "uri" diff --git a/lib/rabbitmq/http/client/request_helper.rb b/lib/rabbitmq/http/client/request_helper.rb index 0cc394b..5bb88e8 100644 --- a/lib/rabbitmq/http/client/request_helper.rb +++ b/lib/rabbitmq/http/client/request_helper.rb @@ -1,6 +1,6 @@ require "hashie" require "faraday" -require "faraday_middleware" +require "faraday/follow_redirects" require "multi_json" require "uri" diff --git a/lib/rabbitmq/http/client/response_helper.rb b/lib/rabbitmq/http/client/response_helper.rb index 452035c..a527a3b 100644 --- a/lib/rabbitmq/http/client/response_helper.rb +++ b/lib/rabbitmq/http/client/response_helper.rb @@ -1,6 +1,6 @@ require "hashie" require "faraday" -require "faraday_middleware" +require "faraday/follow_redirects" require "multi_json" require "uri" diff --git a/rabbitmq_http_api_client.gemspec b/rabbitmq_http_api_client.gemspec index 23b718a..f25c5b8 100644 --- a/rabbitmq_http_api_client.gemspec +++ b/rabbitmq_http_api_client.gemspec @@ -21,6 +21,6 @@ Gem::Specification.new do |gem| gem.add_dependency 'addressable', '~> 2.7' gem.add_dependency 'hashie', '~> 4.1' gem.add_dependency 'multi_json', '~> 1.15' - gem.add_dependency 'faraday', '~> 1.3' - gem.add_dependency 'faraday_middleware', '~> 1.2' + gem.add_dependency 'faraday', '>= 1.3', '< 3' + gem.add_dependency 'faraday-follow_redirects', '~> 0.3' end From d07aa2e2bfcee32d1633ce18158015a6fa55c828 Mon Sep 17 00:00:00 2001 From: shashank mehra Date: Tue, 30 Jan 2024 21:32:12 +0530 Subject: [PATCH 2/3] Remove support for Faraday 1.x. --- lib/rabbitmq/http/client.rb | 6 +----- rabbitmq_http_api_client.gemspec | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/rabbitmq/http/client.rb b/lib/rabbitmq/http/client.rb index fe42e1f..adda6c7 100644 --- a/lib/rabbitmq/http/client.rb +++ b/lib/rabbitmq/http/client.rb @@ -450,11 +450,7 @@ def initialize_connection(endpoint, options = {}) adapter = options.delete(:adapter) || Faraday.default_adapter @connection = Faraday.new(options) do |conn| - if Gem::Version.new(Faraday::VERSION) < Gem::Version.new("2.0") - conn.request :basic_auth, user, password - else - conn.request :authorization, :basic, user, password - end + conn.request :authorization, :basic, user, password conn.use Faraday::FollowRedirects::Middleware, :limit => 3 conn.use Faraday::Response::RaiseError diff --git a/rabbitmq_http_api_client.gemspec b/rabbitmq_http_api_client.gemspec index f25c5b8..aa00ad9 100644 --- a/rabbitmq_http_api_client.gemspec +++ b/rabbitmq_http_api_client.gemspec @@ -21,6 +21,6 @@ Gem::Specification.new do |gem| gem.add_dependency 'addressable', '~> 2.7' gem.add_dependency 'hashie', '~> 4.1' gem.add_dependency 'multi_json', '~> 1.15' - gem.add_dependency 'faraday', '>= 1.3', '< 3' + gem.add_dependency 'faraday', '~> 2.0' gem.add_dependency 'faraday-follow_redirects', '~> 0.3' end From 24b4d5c5758dde243ca53f925286391c197031d5 Mon Sep 17 00:00:00 2001 From: shashank mehra Date: Tue, 30 Jan 2024 21:43:09 +0530 Subject: [PATCH 3/3] Fix spacing --- lib/rabbitmq/http/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rabbitmq/http/client.rb b/lib/rabbitmq/http/client.rb index adda6c7..79bcbcd 100644 --- a/lib/rabbitmq/http/client.rb +++ b/lib/rabbitmq/http/client.rb @@ -450,7 +450,7 @@ def initialize_connection(endpoint, options = {}) adapter = options.delete(:adapter) || Faraday.default_adapter @connection = Faraday.new(options) do |conn| - conn.request :authorization, :basic, user, password + conn.request :authorization, :basic, user, password conn.use Faraday::FollowRedirects::Middleware, :limit => 3 conn.use Faraday::Response::RaiseError