Module: PicFisher::Downloader

Defined in:
lib/picfisher/downloader.rb

Overview

Downloads an image from an URL

Class Method Summary collapse

Class Method Details

.download(url, output_path) ⇒ nil

Downloads an image from an URL

Examples:

PicFisher::Downloader.download("https://example.com/image_in_internet.png", "OUTPUT_PATH")
PicFisher::Downloader.download("https://example.com/not_existing.png", "OUTPUT_PATH")

Parameters:

  • url (String)
  • output_path (String)

Returns:

  • (nil)

Raises:



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/picfisher/downloader.rb', line 16

def self.download(url, output_path)
  PicFisher::Log.debug("Fishing #{url} to #{output_path}")

  begin
    _dowload(url, output_path)
  rescue OpenURI::HTTPError => e
    message = "Failed to fish #{url}: #{e}"
    PicFisher::Log.error(message)
    raise PicFisher::Error, message
  end
end