Module: FlickrbCollage::PhotoDownloader

Defined in:
lib/flickrb_collage/photo_downloader.rb

Constant Summary collapse

MAX_RETRIES =
3

Class Method Summary collapse

Class Method Details

.call(url) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/flickrb_collage/photo_downloader.rb', line 8

def self.call(url)
  tempfile = Tempfile.new('flickr_image')
  IO.copy_stream(open(url), tempfile)
  tempfile.rewind
  puts "Downloaded to #{tempfile.path}"
  tempfile
rescue Net::ReadTimeout, Net::OpenTimeout => e
  @retries ||= 0
  @retries += 1
  puts 'Retrying download'
  retry if @retries <= 3
  raise e
end