Sha256: 1c865f64537c20856db08333f3ebbc2314afd3d2c0ac1a22e3c149d5635e2e85
Contents?: true
Size: 878 Bytes
Versions: 12
Compression:
Stored size: 878 Bytes
Contents
module Nutkins::Download def self.download_file url, output orig_url = url tries = 10 while (tries -= 1) >= 0 response = Net::HTTP.get_response(URI(url)) case response when Net::HTTPRedirection url = response["location"] else open(output, "wb") do |file| file.write(response.body) end return end end raise "could not download #{orig_url}" end def self.download_resources img_dir, resources resources.each do |resource| source = resource["source"] dest = File.join(img_dir, resource["dest"]) unless File.exists? dest FileUtils.mkdir_p File.dirname(dest) print "downloading #{source}" download_file source, dest puts " - done" mode = resource["mode"] File.chmod(mode, dest) if mode end end end end
Version data entries
12 entries across 12 versions & 1 rubygems