class FlickrOfflineGallery::PhotosetDownloader
Public Class Methods
new(photoset, size)
click to toggle source
# File lib/flickr_offline_gallery/photoset_downloader.rb, line 7 def initialize(photoset, size) @photoset = photoset @size = size end
Public Instance Methods
download()
click to toggle source
# File lib/flickr_offline_gallery/photoset_downloader.rb, line 12 def download photos.each do |photo| url = photo.sizes[@size].url local_path = photo.full_jpg_path FileUtils.mkdir_p(File.dirname(local_path)) unless File.exist?(local_path) download_file(url, local_path) verbose_puts "Downloaded #{local_path}" end end end
Private Instance Methods
download_file(url, destination)
click to toggle source
# File lib/flickr_offline_gallery/photoset_downloader.rb, line 31 def download_file(url, destination) resp = http_get(url) File.open(destination, "wb") do |file| file.write(resp.body) end end
http_get(url)
click to toggle source
# File lib/flickr_offline_gallery/photoset_downloader.rb, line 38 def http_get(url) response = HTTParty.get(url) raise "unhandled response code: #{response.code}" unless response.code == 200 response end
photos()
click to toggle source
# File lib/flickr_offline_gallery/photoset_downloader.rb, line 27 def photos @photoset.photos end