Skip to content

Instantly share code, notes, and snippets.

@bloudermilk
Created February 26, 2016 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bloudermilk/017dfb51ea624825207c to your computer and use it in GitHub Desktop.
Save bloudermilk/017dfb51ea624825207c to your computer and use it in GitHub Desktop.
Test whether or not a user has Gravatar
require "net/http"
class GravatarGenerator
URL_FORMAT = "http://www.gravatar.com/avatar/%s"
LAST_MODIFIED_TEST_STRING = "Wed, 11 Jan 1984 08:00:00 GMT"
def self.test(email)
url = URI(URL_FORMAT % generate(email))
Net::HTTP.start(url.host, url.port) do |http|
http.head(url.path)["Last-Modified"] != LAST_MODIFIED_TEST_STRING
end
end
def self.generate(string)
Digest::MD5.hexdigest(string.strip.downcase)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment