Created
March 7, 2014 13:07
-
-
Save emad-elsaid/9411128 to your computer and use it in GitHub Desktop.
Gravatar image url generator simple method
Gravatar image url generator simple method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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('[email protected]') | |
puts gravatar( | |
'[email protected]', | |
size: 200, | |
default: 'https://pbs.twimg.com/media/BheUcQMIAAA0Gns.jpg:large' | |
) |
#!/usr/bin/env ruby
require 'digest/md5'
def gravatar_url(email)
gravatar_id = Digest::MD5.hexdigest(email.downcase)
"http://gravatar.com/avatar/#{gravatar_id}.png"
end
puts gravatar_url("[email protected]")
I would prolly do this.
https://gist.github.com/dahal/9419572
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you're right, i was sure that
to_param
is defined in ruby core, sorry! hahaI made a research and found a standard lib in ruby (URI) that do this parsing.
Here is my version:
https://gist.github.com/brunojabs/9413351
Thanks! (: