Class AutomateIt::DownloadManager::OpenURI
In: lib/automateit/download_manager.rb
Parent: BaseDriver

DownloadManager::OpenURI

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

Methods

download  

Public Instance methods

See DownloadManager#download

[Source]

# File lib/automateit/download_manager.rb, line 32
      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)
        force  = opts[:force]

        if File.exist?(target) and not force
          return false
        end

        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

[Validate]