Skip to content

Commit

Permalink
Merge pull request #37 from looker-open-source/fix-for-faraday-multip…
Browse files Browse the repository at this point in the history
…art-disabled

fix(deps): Fix for faraday multipart disabled
  • Loading branch information
drstrangelooker authored Jan 17, 2024
2 parents 688d247 + 37b46ad commit c3ba573
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ruby-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
matrix:
ruby-version: [2.7.7]
looker: ${{ fromJson(needs.setup.outputs.matrix_json) }}
use_faraday_multipart: ['true', 'false']

steps:
- name: Cancel Previous Runs
Expand Down Expand Up @@ -98,6 +99,8 @@ jobs:

- name: Run tests
run: bundle exec rake test --trace
env:
USE_FARADAY_MULTIPART: ${{ matrix.use_faraday_multipart }}

- name: remove mock .netrc
if: ${{ always() }}
Expand Down
8 changes: 5 additions & 3 deletions lib/looker-sdk/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def encode(data)
if Gem.loaded_specs['faraday'].version < Gem::Version.new('2.0')
data.kind_of?(Faraday::UploadIO) ? data : super
else
data.kind_of?(Faraday::FilePart) ? data : super
defined?(Faraday::FilePart) && data.kind_of?(Faraday::FilePart) ? data : super
end
end

Expand Down Expand Up @@ -476,9 +476,11 @@ def sawyer_options(options = {})

def merge_content_type_if_body(body, options = {})
if body
type = Gem.loaded_specs['faraday'].version < Gem::Version.new('2.0') ? Faraday::UploadIO : Faraday::FilePart
multipart = Gem.loaded_specs['faraday'].version < Gem::Version.new('2.0') ?
body.kind_of?(Faraday::UploadIO) :
defined?(Faraday::FilePart) && body.kind_of?(Faraday::FilePart)

if body.kind_of?(type)
if multipart
length = File.new(body.local_path).size.to_s
headers = {:content_type => body.content_type, :content_length => length}.merge(options[:headers] || {})
else
Expand Down
2 changes: 1 addition & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
require "rack/test"
require "rack/request"
require "faraday/rack"
require "faraday/multipart"
require "faraday/multipart" if ENV['USE_FARADAY_MULTIPART'] == 'true'

def fixture_path
File.expand_path("../fixtures", __FILE__)
Expand Down
2 changes: 1 addition & 1 deletion test/looker/test_dynamic_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ def verify(response, method, path, body='', query={}, content_type = nil)
if Gem.loaded_specs['faraday'].version < Gem::Version.new('2.0')
sdk.create_user(Faraday::UploadIO.new(name, "application/vnd.BOGUS3+json"))
else
skip unless defined?(Faraday::FilePart)
sdk.create_user(Faraday::FilePart.new(name, "application/vnd.BOGUS3+json"))
end

end
end

Expand Down

0 comments on commit c3ba573

Please sign in to comment.