Sha256: 683e8a54f363cf9223b977f230a5440d7e4dc81731ba2ad72f67a8d58ae677fa

Contents?: true

Size: 783 Bytes

Versions: 2

Compression:

Stored size: 783 Bytes

Contents

module Downer
  class DownloadWorker
    
    attr_reader :items
    
    def initialize(urls, target_directory, output)
      @urls, @target_directory, @output = urls, target_directory, output
      @items = []
      @urls.each { |url| @items << DownloadItem.new(url, target_directory) }
    end
    
    def start
      if @urls.empty?
        @output.puts "No URLs specified, exiting." 
        return
      end
      
      @items.each { |item| try_download_item(item) }
    end
    
    private

      def try_download_item(item)
        begin
          item.download
          @output.puts "Downloaded #{item.url}"
        rescue Downer::FailedDownload => e
          @output.puts "Could not download #{e.url}, received http code #{e.http_code}"
        end
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
downer-0.2.2 lib/downer/download_worker.rb
downer-0.1.1 lib/downer/download_worker.rb