Created
February 26, 2016 23:31
-
-
Save bloudermilk/017dfb51ea624825207c to your computer and use it in GitHub Desktop.
Test whether or not a user has Gravatar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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