Created
January 27, 2015 21:59
-
-
Save Fivell/5d230d5ec648f6a3c7ab to your computer and use it in GitHub Desktop.
check if gravatar exists
This file contains hidden or 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
| 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