Module: Download
Overview
Module for handling inbound requests
Constant Summary collapse
- HTTP_REDIRECT_PERMANENT =
Array with http redirect & http permanent code Used to determine if the GET request should start downloading or follow redirect
[301, 302].freeze
Instance Method Summary collapse
-
#download_file(file_name, skylink, override_options = {}, stream: true) ⇒ Object
Download file from the skynet portal file_name & skylink is required, the rest is optional since they come with default values.
Methods included from Helper::Download
Instance Method Details
#download_file(file_name, skylink, override_options = {}, stream: true) ⇒ Object
Download file from the skynet portal file_name & skylink is required, the rest is optional since they come with default values
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/skynet/download.rb', line 14 def download_file(file_name, skylink, = {}, stream: true) = Helper::Download. = Helper::Download..merge() unless .empty? portal = [:portal_url] skylink = Helper::Download.strip_prefix(skylink) url = "#{portal}#{skylink}?attachment=#{[:download]}" File.open(file_name, 'w') do |file| HTTParty.get(url, follow_redirects: true, stream_body: stream) do |chunk| file << chunk unless HTTP_REDIRECT_PERMANENT.include? chunk.code end end 'Download successful!' end |