lib/geoblacklight/download.rb
def create_download_file
      download = initiate_download

      File.open("#{file_path_and_name}.tmp", 'wb') do |file|
        fail Geoblacklight::Exceptions::WrongDownloadFormat unless matches_mimetype?(download)
        file.write download.body
      end
      File.rename("#{file_path_and_name}.tmp", file_path_and_name)
      file_name
    rescue Geoblacklight::Exceptions::WrongDownloadFormat => error
      Geoblacklight.logger.error "#{error} expected #{@options[:content_type]} "\
                                 "received #{download.headers['content-type']}"
      File.delete("#{file_path_and_name}.tmp")
      raise Geoblacklight::Exceptions::ExternalDownloadFailed, message: 'Wrong download type'
    end
##
# Creates temporary file on file system and renames it if download completes
# successfully. Will raise and rescue if the wrong file format is downloaded
# @return [String] filename of the completed download
Creates temporary file on file system and renames it if download completes
successfully. Will raise and rescue if the wrong file format is downloaded
Creates temporary file on file system and renames it if download completes successfully . Will raise and rescue if the wrong file format is downloaded
def create_download_file
      download = initiate_download
      File.open("#{file_path_and_name}.tmp", 'wb') do |file|
        fail Geoblacklight::Exceptions::WrongDownloadFormat unless matches_mimetype?(download)
        file.write download.body
      end
      File.rename("#{file_path_and_name}.tmp", file_path_and_name)
      file_name
    rescue Geoblacklight::Exceptions::WrongDownloadFormat => error
      Geoblacklight.logger.error "#{error} expected #{@options[:content_type]} "\
                                 "received #{download.headers['content-type']}"
      File.delete("#{file_path_and_name}.tmp")
      raise Geoblacklight::Exceptions::ExternalDownloadFailed, message: 'Wrong download type'
    end
def create_download_file download = initiate_download File . open ( "#{file_path_and_name}.tmp" , 'wb' ) do | file | fail Geoblacklight :: Exceptions :: WrongDownloadFormat unless matches_mimetype? ( download ) file . write download . body end File . rename ( "#{file_path_and_name}.tmp" , file_path_and_name ) file_name rescue Geoblacklight :: Exceptions :: WrongDownloadFormat => error Geoblacklight . logger . error "#{error} expected #{@options[:content_type]} " "received #{download.headers['content-type']}" File . delete ( "#{file_path_and_name}.tmp" ) raise Geoblacklight :: Exceptions :: ExternalDownloadFailed , message : 'Wrong download type' end
Creates temporary file on file system and renames it if download completes
successfully.
Creates temporary file on file system and renames it if download completes successfully .
filename of the completed download
filename of the completed download
String