Aww (aww v1.0.0)

Summary

Functions

Generate URL for avatar using given service.

Types

Link to this type

avatar_opt()

@type avatar_opt() ::
  {:size, integer()}
  | {:default, String.t()}
  | {:robohash, String.t()}
  | {:forcedefault?, boolean()}
  | {:rating, String.t()}
@type host() ::
  :gravatar
  | :libravatar
  | (String.t(), opts() -> String.t() | {String.t(), integer()})
  | {module(), atom(), [term()]}
@type opts() :: [avatar_opt() | {:service_opts, [service_opt()]}]
Link to this type

service_opt()

@type service_opt() ::
  {:host, host()}
  | {:secure?, boolean()}
  | {:resolv_opts, [:inet_res.res_option()]}
  | {:timeout, pos_integer()}
  | {atom(), term()}

Functions

Link to this function

avatar_url(email, opts \\ [])

@spec avatar_url(
  String.t(),
  keyword()
) :: URI.t()

Generate URL for avatar using given service.

Options

Gravatar options supported are:

  • :size - pixel size of the resulting image. As returned avatars are always squares, only one side is needed.
  • :default - fallback image and/or implementation for image generation. Check out your implementation documentation for list of supported values.
  • :robohash - Libravatar and Gravatar support using additional option for default: :robohash.
  • :forcedefault? - force using default image (useful for testing)
  • :rating - require image of this rating or lower. Used for explicit image filtering. Ignored by Libravatar (that service requires all images to be PG rated).

Service options

It is possible to configure used service via options under :service_opts configuration key. Recognised options are:

  • :host - implementation that will be used for generating avatar. Possible options are:
    • :gravatar - Gravatar
    • :libravatar - Libravatar - federated and open source service providing Gravatar-compatible API
    • 2-ary function passed either as a capture or {m, f, a} tuple. In case of MFA tuple the arguments will be prepended to passed list. Arguments appended are: domain of the email and opts passed to this function. Defaults to Application.get_env(:aww, :default, :libravatar).
  • :secure? - whether to use secure (HTTPS) connection to the service. Defaults to true.
  • :resolv_opts - used by host: :libravatar - additional opts passed to DNS resolver. See :inet_res.res_option/0 for details.
  • :timeout - DNS query timeout in milliseconds. Defaults to 5000 (5 seconds).