Skip to content

Instantly share code, notes, and snippets.

@mauriciomdea
Forked from emad-elsaid/gravatar.rb
Created March 7, 2014 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauriciomdea/9415239 to your computer and use it in GitHub Desktop.
Save mauriciomdea/9415239 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'digest/md5'
require "addressable/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
unless options.empty?
params = Addressable::URI.new
params.query_values = options.first
params_query = "?#{params.query}"
end
"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