Sha256: 3852408b110dc3965c48716d0d780a99fe27bce13e53e5f7d22ea287203e6c94
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
module Dl def self.download(url, raw = false) session = Patron::Session.new output "Downloading #{url}..." begin response = session.get url rescue Patron::HostResolutionError puts "Error resolving remote host." exit 1 rescue Patron::PartialFileError puts "File size mismatch. (Host reported a file size, but the actual file is of different size)" exit 1 rescue Patron::TimeoutError puts "Operation timed out." exit 1 rescue Patron::TooManyRedirects puts "Tried redirecting too many times." exit 1 rescue Patron::URLFormatError puts "Error with the URL format" exit 1 rescue Patron::UnsupportedProtocol puts "This URL is using a protocol that we cannot handle." exit 1 rescue Patron::ConnectionFailed puts "Error connecting to host. Check your internet connection." exit 1 end if raw == true puts response.body else if Dl::file != nil filename = Dl::file else filename = response.url.split('/').pop end output "Downloaded to file #{filename}!" File.new(filename, 'w').write(response.body) end end private def self.output(string) puts string unless Dl::be_quiet == true end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dl-1.2.1 | lib/dl/dl.rb |