class Slipsquare::Middleware::DownloadFile

Public Instance Methods

call(env) click to toggle source
# File lib/slipsquare/middleware/download_file.rb, line 4
def call(env)
  say "Download file..."

  begin
    contents = env['dropbox-client'].download env['download_file_name']
  rescue Dropbox::API::Error::NotFound => e
    say "File Not Found! Could not download", :red
    exit 1
  rescue Dropbox::API::Error => e
    say "Connection to Dropbox failed (#{e})", :red
    exit 1
  end

  File.open(env['download_file_name'], 'w') {|f| f.write(contents) }

  say "File '#{env['download_file_name']}' downloaded successfully!"

  @app.call(env)
end