Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should i check if gravatar exist?

using this gem https://github.com/sinisterchipmunk/gravatar how do i check if gravatar for specified email exist or not? I think i am missing some force default option? Because this

url = Gravatar.new("[email protected]").image_url

always return a picture

like image 412
Jakub Kuchar Avatar asked Jul 20 '12 15:07

Jakub Kuchar


People also ask

Why do I have a Gravatar account?

Why Should You Use Gravatar? Gravatar saves you the trouble of uploading a new avatar for each blog you comment on. WordPress administrators can activate Gravatar on their sites to give commenters more brand visibility.

Does Gmail use Gravatar?

Gravatar does not get displayed in Gmail. So, the next best thing one can do is implement BIMI that promises to get you your avatar displayed, soon.

How did Gravatar get my photo?

Gravatar uses your email address to provide your image to other sites. If we don't have any record of your email address, Gravatar won't be able to display your image. Your selected Gravatar must use a rating that's permitted by the other site. Lots of sites restrict Gravatar images to G or PG ratings only.

What is a Gravatar ID?

What is Gravatar? Gravatar is a free service used to manage one's avatars on the web and allows Internet users to have “an effortless and verified way to establish their identity online”, as stated on its official website. Websites and other services can use these avatars to “humanize” their platforms a little more.

How much does a Gravatar cost?

Gravatar is free for everyone—forever.


1 Answers

In case people would like to know how to do it without any gems :

The trick is to get gravatar image with a false default image and then check header response. It's achieved with the Net::HTTP ruby 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 # from d=404 parameter
end
like image 164
Noémien Kocher Avatar answered Nov 15 '22 22:11

Noémien Kocher