Skip to content

Chore: Update faraday to v2.13.4#37

Merged
IanGabriel12 merged 2 commits into
mainfrom
chore/update-faraday
Sep 22, 2025
Merged

Chore: Update faraday to v2.13.4#37
IanGabriel12 merged 2 commits into
mainfrom
chore/update-faraday

Conversation

@IanGabriel12
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread lib/incognia_api/api.rb
require "faraday"
require "json"
require "logger"
require 'faraday_middleware'
Copy link
Copy Markdown
Contributor Author

@IanGabriel12 IanGabriel12 Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gem is deprecated, some common middlewares are bundled in faraday itself now. Ref

Comment on lines -53 to -55
basic_auth = Faraday::Request
.lookup_middleware(:basic_auth)
.header(Incognia.config.client_id, Incognia.config.client_secret)
Copy link
Copy Markdown
Contributor Author

@IanGabriel12 IanGabriel12 Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper function does not exist anymore, but i found an utility function that behaves the same way.

Old helper:

def self.header(login, pass)
  value = Base64.encode64([login, pass].join(':'))
  value.delete!("\n")
  super(:Basic, value)
end

New util:

def basic_header_from(login, pass)
  value = ["#{login}:#{pass}"].pack('m') # Base64 encoding
  value.delete!("\n")
  "Basic #{value}"
end

Comment on lines -17 to -19
r.headers[Faraday::Request::Authorization::KEY] ||= Faraday::Request
.lookup_middleware(:authorization)
.header(:Bearer, credentials.access_token)
Copy link
Copy Markdown
Contributor Author

@IanGabriel12 IanGabriel12 Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper function does not exist anymore, but since credentials.access_token is a string, this just returns Bearer {token}

This is the old helper's code:

def self.header(type, token)
  case token
  when String, Symbol, Proc
    token = token.call if token.is_a?(Proc)
    "#{type} #{token}"
  when Hash
    build_hash(type.to_s, token)
  else
    raise ArgumentError,
          "Can't build an Authorization #{type}" \
            "header from #{token.inspect}"
  end
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also removed the .lookup_middleware(:authorization). Could you please explain what is the side effect of this removal?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no side effects, what the old code did was to use the header method of the middleware :authorization, which behaves the same way as just returning Bearer #{token} in this case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the Faraday HTTP client library from version 1.x to 2.13.4, adapting the codebase to work with the newer API. The upgrade removes the dependency on faraday_middleware and updates authentication header generation methods to use Faraday v2 APIs.

  • Updated Faraday dependency from ~> 1.10 to ~> 2.13 and removed faraday_middleware dependency
  • Replaced deprecated Faraday middleware lookup methods with direct utility methods
  • Updated VCR test fixtures to reflect the new Faraday version

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

File Description
incognia_api.gemspec Updates Faraday dependency version and removes faraday_middleware
lib/incognia_api/api.rb Removes faraday_middleware require statement
lib/incognia_api/client.rb Updates authentication header generation to use Faraday v2 APIs
fixtures/vcr_cassettes/token.yml Updates User-Agent headers in test fixtures to reflect new Faraday version

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Copy Markdown
Contributor

@lucaswilliamgomes lucaswilliamgomes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@IanGabriel12 IanGabriel12 force-pushed the chore/update-faraday branch 2 times, most recently from 046fa3e to 0b7f86a Compare September 22, 2025 13:24
@IanGabriel12 IanGabriel12 merged commit d564161 into main Sep 22, 2025
4 checks passed
@IanGabriel12 IanGabriel12 deleted the chore/update-faraday branch September 22, 2025 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants