Class: FileDownloader::Service
- Inherits:
-
Object
- Object
- FileDownloader::Service
- Defined in:
- lib/file_downloader/service.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(url, filepath, logger: nil) ⇒ Service
constructor
A new instance of Service.
Constructor Details
#initialize(url, filepath, logger: nil) ⇒ Service
Returns a new instance of Service.
9 10 11 12 13 14 |
# File 'lib/file_downloader/service.rb', line 9 def initialize(url, filepath, logger: nil) @url = url @filepath = filepath @retry_count = 0 @logger = logger || Logger.new($stdout) end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/file_downloader/service.rb', line 16 def execute uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) content_length = fetch_content_length(http, uri) raise NoResponseBodyError if content_length.to_i.zero? download_file(http, uri, content_length) filepath end |