Skip to content

Commit

Permalink
* Use Faraday 2 gem
Browse files Browse the repository at this point in the history
* Replace custom Faraday GZip implementation with `faraday-gzip` gem

Credit goes to [Zachary Jones/Zajn](https://github.com/Zajn)
Original [PR ruckus#58](ruckus#578)
  • Loading branch information
marcrohloff committed Nov 10, 2022
1 parent d295923 commit 32e892b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 87 deletions.
6 changes: 2 additions & 4 deletions lib/quickbooks-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
require 'forwardable'
require 'oauth2'
require 'net/http/post/multipart'
require 'faraday/multipart'
require 'faraday/gzip'
require 'quickbooks/util/collection'
require 'quickbooks/util/logging'
require 'quickbooks/util/http_encoding_helper'
require 'quickbooks/util/name_entity'
require 'quickbooks/util/query_builder'
require 'quickbooks/faraday/middleware/gzip'

#== OAuth Responses
require 'quickbooks/service/responses/oauth_http_response'
Expand Down Expand Up @@ -187,9 +188,6 @@
require 'quickbooks/service/change_data_capture'
require 'quickbooks/service/refund_receipt_change'

# Register Faraday Middleware
Faraday::Middleware.register_middleware :gzip => lambda { Gzip }

module Quickbooks
@@sandbox_mode = false
@@logger = nil
Expand Down
74 changes: 0 additions & 74 deletions lib/quickbooks/faraday/middleware/gzip.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/quickbooks/service/access_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def renew
def disconnect
connection = Faraday.new(headers: { 'Content-Type' => 'application/json' }) do |f|
f.adapter(::Quickbooks.http_adapter)
f.basic_auth(oauth.client.id, oauth.client.secret)
f.request(:authorization, :basic, oauth.client.id, oauth.client.secret)
end

url = "#{DISCONNECT_URL}?minorversion=#{Quickbooks.minorversion}"
Expand Down
11 changes: 5 additions & 6 deletions lib/quickbooks/service/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ def realm_id=(company_id)
# [OAuth2] The default Faraday connection does not have gzip or multipart support.
# We need to reset the existing connection and build a new one.
def rebuild_connection!
@oauth.client.connection = nil
@oauth.client.connection.build do |builder|
builder.use :gzip
builder.request :multipart
builder.request :url_encoded
builder.adapter ::Quickbooks.http_adapter
@oauth.client.connection = Faraday.new do |f|
f.request :multipart
f.request :gzip
f.request :url_encoded
f.adapter ::Quickbooks.http_adapter
end
end

Expand Down
4 changes: 3 additions & 1 deletion quickbooks-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Gem::Specification.new do |gem|
gem.add_dependency 'net-http-persistent'
gem.add_dependency 'nokogiri' # promiscuous mode
gem.add_dependency 'multipart-post' # promiscuous mode
gem.add_dependency 'faraday', '< 2.0'
gem.add_dependency 'faraday', '< 3.0'
gem.add_dependency 'faraday-multipart', '~> 1.0'
gem.add_dependency 'faraday-gzip', '~> 0.1'

gem.add_development_dependency 'rake'
gem.add_development_dependency 'simplecov'
Expand Down
1 change: 0 additions & 1 deletion spec/lib/quickbooks/model/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

account.name = "Regular"
account.valid?
pp account.errors
expect(account.errors.map(&:attribute).include?(:name)).to be false
end

Expand Down

0 comments on commit 32e892b

Please sign in to comment.