Skip to content

Commit 32e892b

Browse files
committed
* Use Faraday 2 gem
* 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)
1 parent d295923 commit 32e892b

File tree

6 files changed

+11
-87
lines changed

6 files changed

+11
-87
lines changed

lib/quickbooks-ruby.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
require 'forwardable'
99
require 'oauth2'
1010
require 'net/http/post/multipart'
11+
require 'faraday/multipart'
12+
require 'faraday/gzip'
1113
require 'quickbooks/util/collection'
1214
require 'quickbooks/util/logging'
1315
require 'quickbooks/util/http_encoding_helper'
1416
require 'quickbooks/util/name_entity'
1517
require 'quickbooks/util/query_builder'
16-
require 'quickbooks/faraday/middleware/gzip'
1718

1819
#== OAuth Responses
1920
require 'quickbooks/service/responses/oauth_http_response'
@@ -187,9 +188,6 @@
187188
require 'quickbooks/service/change_data_capture'
188189
require 'quickbooks/service/refund_receipt_change'
189190

190-
# Register Faraday Middleware
191-
Faraday::Middleware.register_middleware :gzip => lambda { Gzip }
192-
193191
module Quickbooks
194192
@@sandbox_mode = false
195193
@@logger = nil

lib/quickbooks/faraday/middleware/gzip.rb

Lines changed: 0 additions & 74 deletions
This file was deleted.

lib/quickbooks/service/access_token.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def renew
2222
def disconnect
2323
connection = Faraday.new(headers: { 'Content-Type' => 'application/json' }) do |f|
2424
f.adapter(::Quickbooks.http_adapter)
25-
f.basic_auth(oauth.client.id, oauth.client.secret)
25+
f.request(:authorization, :basic, oauth.client.id, oauth.client.secret)
2626
end
2727

2828
url = "#{DISCONNECT_URL}?minorversion=#{Quickbooks.minorversion}"

lib/quickbooks/service/base_service.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ def realm_id=(company_id)
4949
# [OAuth2] The default Faraday connection does not have gzip or multipart support.
5050
# We need to reset the existing connection and build a new one.
5151
def rebuild_connection!
52-
@oauth.client.connection = nil
53-
@oauth.client.connection.build do |builder|
54-
builder.use :gzip
55-
builder.request :multipart
56-
builder.request :url_encoded
57-
builder.adapter ::Quickbooks.http_adapter
52+
@oauth.client.connection = Faraday.new do |f|
53+
f.request :multipart
54+
f.request :gzip
55+
f.request :url_encoded
56+
f.adapter ::Quickbooks.http_adapter
5857
end
5958
end
6059

quickbooks-ruby.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ Gem::Specification.new do |gem|
2222
gem.add_dependency 'net-http-persistent'
2323
gem.add_dependency 'nokogiri' # promiscuous mode
2424
gem.add_dependency 'multipart-post' # promiscuous mode
25-
gem.add_dependency 'faraday', '< 2.0'
25+
gem.add_dependency 'faraday', '< 3.0'
26+
gem.add_dependency 'faraday-multipart', '~> 1.0'
27+
gem.add_dependency 'faraday-gzip', '~> 0.1'
2628

2729
gem.add_development_dependency 'rake'
2830
gem.add_development_dependency 'simplecov'

spec/lib/quickbooks/model/account_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
account.name = "Regular"
2020
account.valid?
21-
pp account.errors
2221
expect(account.errors.map(&:attribute).include?(:name)).to be false
2322
end
2423

0 commit comments

Comments
 (0)