class SimpleImagesDownloader::Downloader

Constants

REQUEST_OPTIONS

Public Class Methods

new(uri) click to toggle source
# File lib/simple_images_downloader/downloader.rb, line 12
def initialize(uri)
  @uri = uri
end

Public Instance Methods

download() click to toggle source
# File lib/simple_images_downloader/downloader.rb, line 16
def download
  puts "Downloading #{@uri}"

  @downloaded_file = StringioToTempfile.convert(downloaded_file) if downloaded_file.is_a?(StringIO)

  Dispenser.new(downloaded_file, @uri.path).place

  puts 'Downloading is finished'
ensure
  downloaded_file.close
end

Private Instance Methods

downloaded_file() click to toggle source
# File lib/simple_images_downloader/downloader.rb, line 30
def downloaded_file
  @downloaded_file ||= @uri.open(REQUEST_OPTIONS)
rescue OpenURI::HTTPRedirect
  raise Errors::RedirectError, @uri
rescue OpenURI::HTTPError
  raise Errors::ConnectionError, @uri
end