Determines appropriate URLs for avatars using assorted avatar services.
1What it IsClavatar is a Common Lisp library to find an avatar URL using some sort ofidentifier.
(clavatar:get-avatar-url "email@example.com" :size 120) ; => #<URI ...> (clavatar:get-avatar-url "http://example.com/user/avatars") ; => #<URI ...>
3.1get-avatar-url (identifier &key size default services)Returns an avatar URL for a given identifier.
First, checks if the domain of identifier provides some clue as to how to get avatars. If so, uses the federated behavior of the domain. Otherwise, tries SERVICES in order and uses the first service which does not return a 404. Will use DEFAULT on the last service if no service knows about the identifier.
Note that because this involves DNS and HTTP queries, it is slow and you should cache the results.
SERVICES is a list which may contain any of 'LIBRAVATAR, 'GRAVATAR, or 'UNICORNIFY by default. Additional services may also be used, if support is added for them. See "Adding a New Service Type", below.
- Libravatar (both hosted and federated)
5Supported Identifier Types
- E-mail addresses (as strings)
- URLs (as strings, and as PURI:URI objects)
6Adding a New Identifier TypeIn some cases, it may be desirable to extend Clavatar's identifier support to anobject type it does not know about; for instance, the e-mail address type of anSMTP library. This can be accomplished by adding methods onCANONICAL-IDENTIFIER and IDENTIFIER-DOMAIN.
The return value from CANONICAL-IDENTIFIER should be a string, representing the canonical form of the identifier (hostnames in lowercase, etc.).
The return value of IDENTIFIER-DOMAIN should be a string, representing the domain name which has authority for the given identifier. E.g., the host portion of an URL, or the domain of an e-mail address.
identifiers.lisp for examples.
7Adding a New Service TypeAt minimum, adding a service requires adding a class for the service, and twomethods on AVATAR-URL.
The first method should be of the form:
SERVICE-NAME and SERVICE-OBJECT should probably be the same symbol, but this isnot required. This method is what enables GET-AVATAR-URL's list of services towork with bare symbols.
(defmethod avatar-url ((service (eql 'service-name)) identifier &rest rest) (apply #'avatar-url (make-instance 'service-object) identifier rest))
The second method should be of the form:
This is the workhorse method whose job is to produce the URL of an avatar.
(defmethod avatar-url ((service service-type) identifier &key size default &allow-other-keys) (determine-identifiers-avatar-uri))
clavatar.lisp for examples.
- Essentially the same thing, but Gravatar-specific