Sha256: 44cb68a60c12599dd12be5decb9fb9d2badeaba714be5e8e0d8e3803ea5b0d57
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
module Downer class DownloadWorker attr_reader :items, :successful_downloads, :failed_downloads def initialize(urls, target_directory, output) @urls, @target_directory, @output = urls, target_directory, output @urls.delete_if { |url| url == nil } @items = [] @successful_downloads = [] @failed_downloads = [] @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) } @successful_downloads end private def try_download_item(item) begin item.download @successful_downloads << item.url @output.puts "Downloaded #{item.url}" rescue Downer::FailedDownload => e @output.puts "Could not download #{e.url}, received http code #{e.http_code}" @failed_downloads << item.url rescue SocketError => e @output.puts "SocketError encountered on url #{item.url}" @failed_downloads << item.url end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
downer-0.3.2 | lib/downer/download_worker.rb |