Class: Fisherman::Downloader
- Inherits:
-
Object
- Object
- Fisherman::Downloader
- Defined in:
- lib/fisherman/downloader.rb
Constant Summary collapse
- THUMBNAIL_API_URL =
'https://tnl.snapfish.com/assetrenderer/v2/thumbnail/'
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(asset) ⇒ Downloader
constructor
A new instance of Downloader.
- #thumbnail? ⇒ Boolean
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
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
5 6 7 |
# File 'lib/fisherman/downloader.rb', line 5 def asset @asset end |
Instance Method Details
#download ⇒ Object
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
12 13 14 |
# File 'lib/fisherman/downloader.rb', line 12 def thumbnail? @thumbnail end |