In case people would like to know how to do this without any gems:
The trick is to get the gravity image with the default false image, and then check the response of the header. This was achieved using the Ruby Net :: HTTP library.
require 'net/http' def gravatar?(user) gravatar_check = "http://gravatar.com/avatar/#{Digest::MD5.hexdigest(user.gravatar_email.downcase)}.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
NoΓ©mien kocher
source share