Chore: Update faraday to v2.13.4#37
Conversation
| require "faraday" | ||
| require "json" | ||
| require "logger" | ||
| require 'faraday_middleware' |
There was a problem hiding this comment.
This gem is deprecated, some common middlewares are bundled in faraday itself now. Ref
| basic_auth = Faraday::Request | ||
| .lookup_middleware(:basic_auth) | ||
| .header(Incognia.config.client_id, Incognia.config.client_secret) |
There was a problem hiding this comment.
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)
endNew util:
def basic_header_from(login, pass)
value = ["#{login}:#{pass}"].pack('m') # Base64 encoding
value.delete!("\n")
"Basic #{value}"
end| r.headers[Faraday::Request::Authorization::KEY] ||= Faraday::Request | ||
| .lookup_middleware(:authorization) | ||
| .header(:Bearer, credentials.access_token) |
There was a problem hiding this comment.
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
endThere was a problem hiding this comment.
You also removed the .lookup_middleware(:authorization). Could you please explain what is the side effect of this removal?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
046fa3e to
0b7f86a
Compare
0b7f86a to
abde1d3
Compare
No description provided.