class AutomateIt::DownloadManager::OpenURI

DownloadManager::OpenURI

A DownloadManager driver using the OpenURI module for handling HTTP and FTP transfers.

Public Instance Methods

download(*arguments) click to toggle source

See DownloadManager#download

# File lib/automateit/download_manager.rb, line 31
def download(*arguments)
  args, opts = args_and_opts(*arguments)
  source = args[0] or raise ArgumentError.new("No source specified")
  target = args[1] || opts[:to] || File.basename(source)
  target = File.join(target, File.basename(source)) if File.directory?(target)
  log.info(PNOTE+"Downloading #{target}")
  if writing?
    open(target, "w+") do |writer|
      open(source) do |reader|
        writer.write(reader.read)
      end
    end
  end
  return writing?
end