Search code examples
ruby-on-railsgravatar

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


Solution

  • Looking at that gem's documentation, it sounds like you need an API key before you can run the exists method:

    Fine, but how about the rest of the API as advertised at en.gravatar.com/site/implement/xmlrpc? Well, for that you need either the user’s Gravatar password, or their API key:

    api = Gravatar.new("[email protected]", :api_key => "AbCdEfG1234")

    api.exists?("[email protected]") #=> true or false, depending on whether the specified email exists.

    If the user doesn't have a gravatar, an image will be generated for them based on the email (at least that has been my experience). I've used the gem gravatar_image_tag - http://rubygems.org/gems/gravatar_image_tag which lets you change the default gravatar image.