Created
May 2, 2020 16:45
-
-
Save acfatah/791de75f4f74e3fb4f5787f7f541f778 to your computer and use it in GitHub Desktop.
Gravatar link generator. Please refer: https://en.gravatar.com/site/implement
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
# require 'digest/md5' | |
def gravatar_link(email, size=80) | |
valid_email = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/ | |
raise 'Invalid email address' unless !!email.match(valid_email) | |
raise 'Invalid gravatar image size' unless size.positive? && size < 2048 | |
hash = Digest::MD5.hexdigest(email.downcase) | |
"https://www.gravatar.com/avatar/#{hash}?s=#{size}" | |
end | |
def gravatar_profile(email, json = false) | |
valid_email = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/ | |
raise 'Invalid email address' unless !!email.match(valid_email) | |
hash = Digest::MD5.hexdigest(email.downcase) | |
"https://www.gravatar.com/#{hash}#{json ? '.json' : ''}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment