From 82c8d3683dd2101de57b0a962ca6862b5773e7bc Mon Sep 17 00:00:00 2001 From: Kevin Soltysiak Date: Sun, 11 Feb 2024 17:47:13 +0100 Subject: [PATCH] refactor: remove compat methods --- lib/scalingo/core_client.rb | 6 +++--- lib/scalingo/faraday/response.rb | 10 ---------- lib/scalingo/regional/addons.rb | 2 +- lib/scalingo/regional/logs.rb | 4 ++-- spec/scalingo/client_spec.rb | 6 +++--- spec/support/shared.rb | 16 ++++++++-------- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/lib/scalingo/core_client.rb b/lib/scalingo/core_client.rb index d4c1c76..1a38eb4 100644 --- a/lib/scalingo/core_client.rb +++ b/lib/scalingo/core_client.rb @@ -62,15 +62,15 @@ def authenticate_with(access_token: nil, bearer_token: nil, expires_at: nil) expiration = Time.now + config.exchanged_token_validity response = auth.tokens.exchange(access_token) - if response.successful? + if response.success? self.token = BearerToken.new( - response.data, + response.body, expires_at: expiration, raise_on_expired: config.raise_on_expired_token ) end - return response.successful? + return response.success? end if bearer_token diff --git a/lib/scalingo/faraday/response.rb b/lib/scalingo/faraday/response.rb index d969f17..e7c8e7f 100644 --- a/lib/scalingo/faraday/response.rb +++ b/lib/scalingo/faraday/response.rb @@ -4,16 +4,6 @@ # Some additional methods for Faraday::Response in order to enhance expressiveness module Faraday class Response - # @deprecated Use {#success?} instead - def successful? - success? - end - - # @deprecated Use {#body} instead - def data - body - end - def client_error? RaiseError::ClientErrorStatuses.include?(status) end diff --git a/lib/scalingo/regional/addons.rb b/lib/scalingo/regional/addons.rb index aceef10..dbf1165 100644 --- a/lib/scalingo/regional/addons.rb +++ b/lib/scalingo/regional/addons.rb @@ -72,7 +72,7 @@ def authenticate!(app_id, addon_id, headers = nil, &block) response = token(app_id, addon_id, headers, &block) return response unless response.status == 200 - token = response.data[:token] + token = response.body[:token] client.token_holder.authenticate_database_with_bearer_token( addon_id, token, diff --git a/lib/scalingo/regional/logs.rb b/lib/scalingo/regional/logs.rb index f86ffe1..a7ad752 100644 --- a/lib/scalingo/regional/logs.rb +++ b/lib/scalingo/regional/logs.rb @@ -26,9 +26,9 @@ def archives(app_id, headers = nil, &block) def for(app_id, payload = {}, headers = nil, &block) logs_response = scalingo.apps.logs_url(app_id) - return logs_response unless logs_response.successful? + return logs_response unless logs_response.success? - get(logs_response.data, payload, headers, &block) + get(logs_response.body, payload, headers, &block) end end end diff --git a/spec/scalingo/client_spec.rb b/spec/scalingo/client_spec.rb index 0f44f6f..d7c5ed2 100644 --- a/spec/scalingo/client_spec.rb +++ b/spec/scalingo/client_spec.rb @@ -51,8 +51,8 @@ context "with access token" do it "is successful with valid token" do fake_response = OpenStruct.new( - successful?: true, - data: "response token" + success?: true, + body: "response token" ) expect(subject.auth.tokens).to receive(:exchange).and_return(fake_response) @@ -64,7 +64,7 @@ it "fails with invalid token" do fake_response = OpenStruct.new( - successful?: false + success?: false ) expect(subject.auth.tokens).to receive(:exchange).and_return(fake_response) diff --git a/spec/support/shared.rb b/spec/support/shared.rb index 771fc70..b652db7 100644 --- a/spec/support/shared.rb +++ b/spec/support/shared.rb @@ -3,7 +3,7 @@ let(:custom_headers) { {"X-Custom-Header" => "custom"} } it "is successful" do - expect(response).to be_successful + expect(response).to be_success expect(response.status).to eq code end @@ -67,11 +67,11 @@ let(:expected_keys) { %i[id] } unless method_defined?(:expected_keys) it "is an object of the expected type (and if applicable, the expected keys)" do - expect(response.data).to be_a_kind_of(expected_type) + expect(response.body).to be_a_kind_of(expected_type) - if response.data.respond_to?(:key?) + if response.body.respond_to?(:key?) expected_keys.each do |key| - expect(response.data.key?(key)).to be true + expect(response.body.key?(key)).to be true end end end @@ -81,7 +81,7 @@ it_behaves_like "a successful response", code it "is empty" do - expect(response.data).to eq("") + expect(response.body).to eq("") end end @@ -93,15 +93,15 @@ let(:expected_keys) { %i[id] } unless method_defined?(:expected_keys) it "is an array" do - expect(response.data).to be_a_kind_of(Array) + expect(response.body).to be_a_kind_of(Array) end it "contains the number of expected elements" do - expect(response.data.size).to eq(expected_count) + expect(response.body.size).to eq(expected_count) end it "items are of the expected type (and if applicable, the expected keys)" do - response.data.each do |item| + response.body.each do |item| expect(item).to be_a_kind_of(expected_type) if item.respond_to?(:key?)