From 5d1335f3ee9c72bab2008842a88b4895028f1fc3 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 29 Apr 2022 12:08:34 +0200 Subject: [PATCH 1/2] fix: Avoid #basic_auth on Faraday::Connection This avoids a deprecation warning. https://lostisland.github.io/faraday/middleware/authentication --- lib/librato/metrics/connection.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/librato/metrics/connection.rb b/lib/librato/metrics/connection.rb index 86b5f2a..fa01eab 100644 --- a/lib/librato/metrics/connection.rb +++ b/lib/librato/metrics/connection.rb @@ -44,7 +44,7 @@ def transport end.tap do |transport| transport.headers[:user_agent] = user_agent transport.headers[:content_type] = 'application/json' - transport.basic_auth @client.email, @client.api_key + transport.request :basic_auth, @client.email, @client.api_key end end @@ -98,4 +98,4 @@ def transport_adapter end end -end \ No newline at end of file +end From 5eb4536a47e8e2bf6a31ca225cd638b8bbf59b7a Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 29 Apr 2022 16:17:42 +0200 Subject: [PATCH 2/2] Support Faraday 2, too --- lib/librato/metrics/connection.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/librato/metrics/connection.rb b/lib/librato/metrics/connection.rb index fa01eab..b668795 100644 --- a/lib/librato/metrics/connection.rb +++ b/lib/librato/metrics/connection.rb @@ -44,7 +44,12 @@ def transport end.tap do |transport| transport.headers[:user_agent] = user_agent transport.headers[:content_type] = 'application/json' - transport.request :basic_auth, @client.email, @client.api_key + # The Basic Auth middleware usage differs before and after Faraday v2 + if Gem::Version.new(Faraday::VERSION).segments.first >= 2 + transport.request :authorization, :basic, @client.email, @client.api_key + else + transport.request :basic_auth, @client.email, @client.api_key + end end end