Class: Suvii::Http
- Inherits:
-
Object
- Object
- Suvii::Http
- Defined in:
- lib/suvii/http.rb
Overview
Thin wrapper around OpenURI, therefore proxy can be configured via standard env variables.
Class Method Summary collapse
-
.save(url, destination, options = {}) ⇒ true
Saves a content of the url to a file.
Class Method Details
.save(url, destination, options = {}) ⇒ true
Saves a content of the url to a file.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/suvii/http.rb', line 15 def self.save(url, destination, = {}) attempts ||= 1 uri = URI.parse(url) Suvii.logger.info("downloading '#{url}'") IO.copy_stream(uri.open, destination) true rescue OpenURI::HTTPError => e if attempts < ([:max_attempts_for_200_response] || 1) Suvii.logger.warn("failed to download '#{url}': #{e.}") attempts += 1 retry else raise end end |