Skip to content

Instantly share code, notes, and snippets.

@brunojabs
Forked from emad-elsaid/gravatar.rb
Last active August 29, 2015 13:57
Show Gist options
  • Save brunojabs/9413351 to your computer and use it in GitHub Desktop.
Save brunojabs/9413351 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'digest/md5'
require 'uri'
# this is based on gravatar image API
# https://en.gravatar.com/site/implement/images/
# options :
# size : <integer> size of image
# default: <string> url of image if email not found or:
# * 404
# * mm
# * identicon
# * monsterid
# * wavatar
# * retro
# * blank
# forcedefault: "y" force default image to load
# rating: <string> one of the values : g, pg, r, x
def gravatar email, options={}
email_md5 = Digest::MD5.hexdigest email
params_query = URI.encode_www_form(options) unless options.empty?
"http://www.gravatar.com/avatar/#{email_md5}?#{params_query}"
end
puts gravatar('blazeeboy@gmail.com')
puts gravatar('blazeeboy@gmail.com',
size: 200,
default: 'https://pbs.twimg.com/media/BheUcQMIAAA0Gns.jpg:large'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment