class CatGenerator::Photo
Constants
- CAT_PHOTOS_API
Public Class Methods
open_in_browser()
click to toggle source
opens the photo in the default browser
# File lib/cat_generator/photo.rb, line 29 def self.open_in_browser photo_url = url `open #{photo_url}` if photo_url end
url()
click to toggle source
returns the next photo url from thecatapi.com
# File lib/cat_generator/photo.rb, line 6 def self.url response = Excon.get(CAT_PHOTOS_API) if response.status == 302 response.headers["location"] end end
write_to_desktop()
click to toggle source
downloads the next photo and saves to Desktop
# File lib/cat_generator/photo.rb, line 15 def self.write_to_desktop photo_url = url if photo_url filename = photo_url.split('/').last target = File.expand_path("~/Desktop/#{filename}") File.open(target, 'w') do |file| file.write(Excon.get(photo_url).body) end end end