class Suvii::Http
Thin wrapper around {github.com/ruby/ruby/blob/trunk/lib/open-uri.rb OpenURI}, therefore proxy can be configured via standard env variables.
Public Class Methods
save(url, destination, options = {})
click to toggle source
Saves a content of the url to a file.
@param url [String] URL to be fetched. @param destination [String] path to a file to be created with the URL content. @option options [Integer] :max_attempts_for_200_response (1, i.e. no retries) number of times
to fetch a remote resource until get a 200 response.
@raise [OpenURI::HTTPError] @return [true]
# File lib/suvii/http.rb, line 15 def self.save(url, destination, options = {}) attempts ||= 1 uri = URI.parse(url) Suvii.logger.info("downloading '#{url}'") IO.copy_stream(uri.open, destination) true rescue OpenURI::HTTPError => e if attempts < (options[:max_attempts_for_200_response] || 1) Suvii.logger.warn("failed to download '#{url}': #{e.message}") attempts += 1 retry else raise end end