Skip to content

Commit

Permalink
Use Faraday::UploadIO instead of UploadIO (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngan authored Jul 19, 2023
1 parent 62f7d1f commit d597278
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/quickbooks/service/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def do_http_file_upload(uploadIO, url, metadata = nil)
if metadata
standalone_prefix = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
meta_data_xml = "#{standalone_prefix}\n#{metadata.to_xml_ns.to_s}"
param_part = UploadIO.new(StringIO.new(meta_data_xml), "application/xml")
param_part = Faraday::UploadIO.new(StringIO.new(meta_data_xml), "application/xml")
body['file_metadata_0'] = param_part
end

Expand Down Expand Up @@ -369,7 +369,7 @@ def request_body_messages(body)
body.each do |k,v|
messages << 'BODY PART:'
val_content = v.inspect
if v.is_a?(UploadIO)
if v.is_a?(Faraday::UploadIO)
if v.content_type == 'application/xml'
if v.io.is_a?(StringIO)
val_content = log_xml(v.io.string)
Expand Down
6 changes: 1 addition & 5 deletions lib/quickbooks/service/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Upload < BaseService
# attachable: Quickbooks::Model::Attachable meta-data details, can be null
def upload(path_to_file, mime_type, attachable = nil)
url = url_for_resource("upload")
uploadIO = class_for_io.new(path_to_file, mime_type)
uploadIO = Faraday::UploadIO.new(path_to_file, mime_type)
response = do_http_file_upload(uploadIO, url, attachable)
prefix = "AttachableResponse/xmlns:Attachable"
if response.code.to_i == 200
Expand All @@ -19,10 +19,6 @@ def upload(path_to_file, mime_type, attachable = nil)
end
end

def class_for_io
oauth.is_a?(OAuth2::AccessToken) ? Faraday::UploadIO : UploadIO
end

def download(uploadId)
url = url_for_resource("download/#{uploadId}")
do_http_get(url, {}, headers)
Expand Down
2 changes: 1 addition & 1 deletion quickbooks-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
gem.add_dependency 'nokogiri' # promiscuous mode
gem.add_dependency 'multipart-post' # promiscuous mode
gem.add_dependency 'faraday', '< 3.0'
gem.add_dependency 'faraday-multipart', '~> 1.0'
gem.add_dependency 'faraday-multipart', '~> 1.0', '>= 1.0.4'
gem.add_dependency 'faraday-gzip', '~> 1.0'

gem.add_development_dependency 'rake'
Expand Down

0 comments on commit d597278

Please sign in to comment.