Top Level Namespace
Defined Under Namespace
Modules: TreRegex
Instance Method Summary collapse
Instance Method Details
#download_file(url, limit = 10) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'ext/tre_regex/extconf.rb', line 52 def download_file(url, limit = 10) raise 'Too many redirects' if limit.zero? uri = URI(url) response = Net::HTTP.get_response(uri) case response when Net::HTTPSuccess response.body when Net::HTTPRedirection location = response['location'] puts "Following redirect to #{location}..." download_file(location, limit - 1) else raise "Download failed: #{response.code} #{response.}" end end |