-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
44 lines (39 loc) · 946 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Module dependencies.
*/
var md5 = require('md5');
var jsonp = require('jsonp');
var querystring = require('querystring');
/**
* Creates an avatar url
*
* @param {String} email
* @param {Number} size (20)
* @return {String} gravatar url
* @api public
*/
exports.url = function (email, config) {
config = config || {};
var qs = querystring.stringify(config);
var qs = qs === '' ? '' : '?' + qs;
var url = 'https://secure.gravatar.com/avatar/' + md5(email.trim().toLowerCase()) + qs;
return url;
};
/**
* Looks up a profile.
*
* @param {String} email
* @param {Function} callback
* @api public
*/
exports.profile = function (email, fn) {
var url = 'https://secure.gravatar.com/' + md5(email.trim().toLowerCase());
jsonp(url + '.json', function (err, obj) {
if (err) return fn(err);
if (obj && obj.entry) {
fn(null, obj.entry[0]);
} else {
fn(new Error('Bad response'));
}
});
};