Skip to content

Commit

Permalink
Faraday 2.x and 1.x cross support (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego authored Feb 22, 2023
1 parent f935407 commit 401639e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
fail-fast: false
matrix:
ruby-version: ['2.7', '3.0', '3.2']
faraday-version: ['~> 1', '~> 2']
env:
FARADAY_VERSION: ${{ matrix.faraday-version }}
timeout-minutes: 5 # Typically ends within 1-2 min
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ gemspec

group :development, :test do
gem "tiny-presto", "~> 0.0.10"
gem "faraday", ENV.fetch("FARADAY_VERSION", "~> 2")
end
13 changes: 10 additions & 3 deletions lib/trino/client/faraday_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# limitations under the License.
#
module Trino::Client
FARADAY1_USED = Faraday::VERSION.start_with?("1.")
private_constant :FARADAY1_USED

require 'cgi'

Expand Down Expand Up @@ -76,13 +78,18 @@ def self.faraday_client(options)

faraday = Faraday.new(faraday_options) do |faraday|
if options[:user] && options[:password]
faraday.request(:basic_auth, options[:user], options[:password])
# https://lostisland.github.io/faraday/middleware/authentication
if FARADAY1_USED
faraday.request(:basic_auth, options[:user], options[:password])
else
faraday.request :authorization, :basic, options[:user], options[:password]
end
end
if options[:follow_redirect]
faraday.use FaradayMiddleware::FollowRedirects
faraday.response :follow_redirects
end
if options[:gzip]
faraday.use FaradayMiddleware::Gzip
faraday.request :gzip
end
faraday.response :logger if options[:http_debug]
faraday.adapter Faraday.default_adapter
Expand Down
3 changes: 2 additions & 1 deletion lib/trino/client/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
module Trino::Client

require 'faraday'
require 'faraday_middleware'
require 'faraday/gzip'
require 'faraday/follow_redirects'
require 'trino/client/models'
require 'trino/client/errors'
require 'trino/client/faraday_client'
Expand Down
3 changes: 2 additions & 1 deletion trino-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = ">= 2.7.0"

gem.add_dependency "faraday", ">= 1", "< 3"
gem.add_dependency "faraday_middleware", ["~> 1.0"]
gem.add_dependency "faraday-gzip", ">= 1"
gem.add_dependency "faraday-follow_redirects", ">= 0.3"
gem.add_dependency "msgpack", [">= 1.5.1"]

gem.add_development_dependency "rake", [">= 0.9.2", "< 14.0"]
Expand Down

0 comments on commit 401639e

Please sign in to comment.