Last active
November 11, 2015 17:40
-
-
Save gausby/ae9c1f868dea03941ed7 to your computer and use it in GitHub Desktop.
An Elixir port of the node.js module 'gravatar-url'. People often ask «where are the packages for Elixir?» Often the answer is «they are baked in; for anything else try out Hex.pm»
This file contains 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
defmodule Gravatar do | |
@base_url "https://secure.gravatar.com/avatar/" | |
@doc """ | |
Will get the corresponding gravatar url for a given email address. Options | |
can be passed in using a keyword list or a map. | |
iex> Gravatar.url("martin@gausby.dk", size: 200) | |
https://secure.gravatar.com/avatar/0e6a9f19e77fa18bf6f185258f2507d6?size=200 | |
Read this site for a list of options: | |
https://secure.gravatar.com/site/implement/images/ | |
""" | |
@spec url(String.t, Map) :: String.t | |
def url(email, opts \\ []) do | |
email = String.downcase(email) | |
hash = :crypto.hash(:md5, email) |> Base.encode16(case: :lower) | |
"#{@base_url}#{hash}?#{URI.encode_query(opts)}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are looking for a gravatar module for your own Elixir project you should check out https://github.com/scrogson/exgravatar