Class: Nauvisian::Downloader
- Inherits:
-
Object
- Object
- Nauvisian::Downloader
- Defined in:
- lib/nauvisian/downloader.rb
Instance Method Summary collapse
- #download(release, output_path) ⇒ Object
-
#initialize(credential:, progress: Nauvisian::Progress::Null) ⇒ Downloader
constructor
A new instance of Downloader.
Constructor Details
#initialize(credential:, progress: Nauvisian::Progress::Null) ⇒ Downloader
Returns a new instance of Downloader.
10 11 12 13 14 |
# File 'lib/nauvisian/downloader.rb', line 10 def initialize(credential:, progress: Nauvisian::Progress::Null) @credential = credential @progress_class = progress @cache = Nauvisian::Cache::FileSystem.new(name: "download", ttl: Float::INFINITY) end |
Instance Method Details
#download(release, output_path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/nauvisian/downloader.rb', line 16 def download(release, output_path) with_error_handling(release) do @progress = @progress_class.new(release) url = release.download_url.dup url.query = Rack::Utils.build_nested_query(@credential.to_h) data = @cache.fetch(url) { get(url) } File.binwrite(output_path, data) raise Nauvisian::DigestMismatch unless Digest::SHA1.file(output_path) == release.sha1 end end |