Skip to content

Instantly share code, notes, and snippets.

@maccman
Created January 14, 2009 12:14
Show Gist options
  • Save maccman/46875 to your computer and use it in GitHub Desktop.
Save maccman/46875 to your computer and use it in GitHub Desktop.
require 'digest/sha1'
require 'net/http'
class GravatarFetcher
# Gravatar is a bit stupid, in that there's
# no way to tell if they're returning the default
# avatar - here's a hack to do that.
class << self
def fetch(email, size=60)
email_hash = Digest::MD5.hexdigest(email)
http = Net::HTTP.new("www.gravatar.com", 80)
res = http.start {
req = Net::HTTP::Get.new("/avatar.php?gravatar_id=#{email_hash}&s=#{size}&d=foo")
http.request(req)
}
res.is_a?(Net::HTTPSuccess) ? res.body : nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment