lib/onfido/api_client.rb in onfido-3.4.0 vs lib/onfido/api_client.rb in onfido-4.0.0
- old
+ new
@@ -4,11 +4,11 @@
#The Onfido API (v3.6)
The version of the OpenAPI document: v3.6
Generated by: https://openapi-generator.tech
-Generator version: 7.6.0
+Generator version: 7.9.0
=end
require 'date'
require 'json'
@@ -32,11 +32,11 @@
# Initializes the ApiClient
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
def initialize(config = Configuration.default)
@config = config
- @user_agent = "onfido-ruby/3.4.0"
+ @user_agent = "onfido-ruby/4.0.0"
@default_headers = {
'Content-Type' => 'application/json',
'User-Agent' => @user_agent
}
end
@@ -162,38 +162,44 @@
# handle streaming Responses
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
stream << chunk
end
+
stream
end
def deserialize_file(response, stream)
- body = response.body
- if @config.return_binary_data == true
- # return byte stream
- encoding = body.encoding
- stream.join.force_encoding(encoding)
+ body = response.body
+ encoding = body.encoding
+
+ # reconstruct content
+ content = stream.join
+ content = content.unpack('m').join if response.headers['Content-Transfer-Encoding'] == 'binary'
+ content = content.force_encoding(encoding)
+
+ # return byte stream
+ return content if @config.return_binary_data == true
+
+ # return file instead of binary data
+ content_disposition = response.headers['Content-Disposition']
+ if content_disposition && content_disposition =~ /filename=/i
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
+ prefix = sanitize_filename(filename)
else
- # return file instead of binary data
- content_disposition = response.headers['Content-Disposition']
- if content_disposition && content_disposition =~ /filename=/i
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
- prefix = sanitize_filename(filename)
- else
- prefix = 'download-'
- end
- prefix = prefix + '-' unless prefix.end_with?('-')
- encoding = body.encoding
- tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
- tempfile.write(stream.join.force_encoding(encoding))
- tempfile.close
- config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
- "explicitly with `tempfile.delete`"
- tempfile
+ prefix = 'download-'
end
+ prefix = prefix + '-' unless prefix.end_with?('-')
+
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
+ tempfile.write(content)
+ tempfile.close
+
+ config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
+ "explicitly with `tempfile.delete`"
+ tempfile
end
def connection(opts)
opts[:header_params]['Content-Type'] == 'multipart/form-data' ? connection_multipart : connection_regular
end