Module: Imagemaster3000::Entities::Downloadable

Included in:
Image
Defined in:
lib/imagemaster3000/entities/downloadable.rb

Instance Method Summary collapse

Instance Method Details

#downloadObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/imagemaster3000/entities/downloadable.rb', line 6

def download
  logger.debug "Downloading image from #{url.inspect}"

  uri = URI.parse url
  filename = generate_filename
  @local_filename = filename
  @remote_filename = File.basename(uri.path)
  retrieve_image(uri, filename)

  logger.debug "Image from #{url.inspect} was saved as #{filename.inspect}"
  @size = File.size filename
rescue ::URI::InvalidURIError, ::IOError => ex
  raise Imagemaster3000::Errors::DownloadError, ex
end