Skip to content

Instantly share code, notes, and snippets.

@Fivell
Created January 27, 2015 21:59
Show Gist options
  • Select an option

  • Save Fivell/5d230d5ec648f6a3c7ab to your computer and use it in GitHub Desktop.

Select an option

Save Fivell/5d230d5ec648f6a3c7ab to your computer and use it in GitHub Desktop.
check if gravatar exists
def gravatar?(email)
puts "checking #{email}"
email_hash = Digest::MD5.hexdigest(email.to_s.downcase)
gravatar_check = "http://gravatar.com/avatar/#{email_hash}.png?d=404"
uri = URI.parse(gravatar_check)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
response.code.to_i != 404
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment