Class: Teems::Services::FileDownloader

Inherits:
Object
  • Object
show all
Defined in:
lib/teems/services/file_downloader.rb

Overview

Downloads files from pre-authenticated URLs with redirect following

Constant Summary collapse

MAX_REDIRECTS =
5

Instance Method Summary collapse

Constructor Details

#initialize(http_client: nil) ⇒ FileDownloader

Returns a new instance of FileDownloader.



9
10
11
# File 'lib/teems/services/file_downloader.rb', line 9

def initialize(http_client: nil)
  @http_client = http_client
end

Instance Method Details

#download(url, output_path) ⇒ Object



13
14
15
16
# File 'lib/teems/services/file_downloader.rb', line 13

def download(url, output_path)
  response = follow_redirects(URI(url))
  File.binwrite(output_path, response.body)
end