Class: Fisherman::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/fisherman/downloader.rb

Constant Summary collapse

THUMBNAIL_API_URL =
'https://tnl.snapfish.com/assetrenderer/v2/thumbnail/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(asset) ⇒ Downloader

Returns a new instance of Downloader.



7
8
9
10
# File 'lib/fisherman/downloader.rb', line 7

def initialize(asset)
  @asset = asset
  @thumbnail = false
end

Instance Attribute Details

#assetObject (readonly)

Returns the value of attribute asset.



5
6
7
# File 'lib/fisherman/downloader.rb', line 5

def asset
  @asset
end

Instance Method Details

#downloadObject



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

def download
  response = Faraday.get(asset.hires_url)
  # The Snapfish main CDN sometimes doesn't have older photos. In that case,
  # the only way to get them is via their thumbnail API. We ask for the
  # largest thumbnail we can get. If you were to download this same asset from
  # the site, the large thumbnail is what it would return.
  if response.status == 404
    @thumbnail = true
    response = download_thumbnail(asset)
  end
  response && response.body
end

#thumbnail?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/fisherman/downloader.rb', line 12

def thumbnail?
  @thumbnail
end