lib/plaid/api_client.rb
# Save response body into a file in (the defined) temporary folder, using the filename
# from the "Content-Disposition" header if provided, otherwise a random filename.
# The response body is written to the file in chunks in order to handle files which
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
# process can use.
#
# @see Configuration#temp_folder_path
Save response body into a file in (the defined) temporary folder, using the filename
from the "Content-Disposition" header if provided, otherwise a random filename.
The response body is written to the file in chunks in order to handle files which
size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
process can use.
Save response body into a file in ( the defined ) temporary folder using the filename from the " Content - Disposition " header if provided otherwise a random filename . The response body is written to the file in chunks in order to handle files which size is larger than maximum Ruby String or even larger than the maximum memory a Ruby process can use .
def prepare_file(response)
      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 = response.body.encoding
      tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
      @tempfile = tempfile
      tempfile.write(response.body)
      tempfile.close if tempfile
      @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`"
    end
def prepare_file ( response ) 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 = response . body . encoding tempfile = Tempfile . open ( prefix , @config . temp_folder_path , encoding : encoding ) @tempfile = tempfile tempfile . write ( response . body ) tempfile . close if tempfile @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`" end
Save response body into a file in (the defined) temporary folder, using the filename
from the "Content-Disposition" header if provided, otherwise a random filename.
Save response body into a file in ( the defined ) temporary folder using the filename from the " Content - Disposition " header if provided otherwise a random filename .
response
see
None