class ThisPersonDoesNotExist::Client

Constants

HEADERS
URL

Public Instance Methods

save_as(path) click to toggle source
# File lib/this_person_does_not_exist.rb, line 21
def save_as(path)
  File.open(path, "w") do |file|
    file.binmode

    HTTParty.get(bust_cache_url, headers: HEADERS, stream_body: true) do |fragment|
      file.write(fragment)
    end
  end
  path
end

Private Instance Methods

bust_cache_url() click to toggle source
# File lib/this_person_does_not_exist.rb, line 33
def bust_cache_url
  URL + "?#{SecureRandom.hex}"
end
image_format_for(path) click to toggle source
# File lib/this_person_does_not_exist.rb, line 37
def image_format_for(path)
  case path.split('.').last.downcase
    when 'jpeg', 'jpg'; 'jpg'
    when 'webp'; 'webp'
    else; 'jpg'
  end
end