Skip to content

Instantly share code, notes, and snippets.

@acfatah
Created May 2, 2020 16:45
Show Gist options
  • Save acfatah/791de75f4f74e3fb4f5787f7f541f778 to your computer and use it in GitHub Desktop.
Save acfatah/791de75f4f74e3fb4f5787f7f541f778 to your computer and use it in GitHub Desktop.
Gravatar link generator. Please refer: https://en.gravatar.com/site/implement
# 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