Skip to content

Commit

Permalink
refactor: remove compat methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ksol committed Feb 11, 2024
1 parent 38a9e5d commit 82c8d36
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 27 deletions.
6 changes: 3 additions & 3 deletions lib/scalingo/core_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions lib/scalingo/faraday/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/scalingo/regional/addons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/scalingo/regional/logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/scalingo/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions spec/support/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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?)
Expand Down

0 comments on commit 82c8d36

Please sign in to comment.