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
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.
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.
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 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.
Gravatar is free for everyone—forever.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With