forked from emerleite/node-gravatar
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
17 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
var crypto = require('crypto') | ||
, querystring = require('querystring') | ||
, baseURI = 'http://www.gravatar.com/avatar/'; | ||
|
||
var gravatar = module.exports = { | ||
url: function (email) { | ||
return baseURI + crypto.createHash('md5').update(email.toLowerCase()).digest('hex'); | ||
url: function (email, options) { | ||
var query = (options && "?" + querystring.stringify(options)) || ""; | ||
return baseURI + crypto.createHash('md5').update(email.toLowerCase()).digest('hex') + query; | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
var testCase = require('nodeunit').testCase | ||
, url = require('url') | ||
, gravatar = require('../lib/gravatar') | ||
, baseURI = 'http://www.gravatar.com/avatar/'; | ||
|
||
|
||
|
||
module.exports = testCase({ | ||
'it should gererate correct hash given an email': function(test) { | ||
test.ok(gravatar.url('emerleite@gmail.com') == baseURI + "93e9084aa289b7f1f5e4ab6716a56c3b"); | ||
test.ok(gravatar.url('emerleite@yahoo.com.br') == baseURI + "6c47672b0d58bd6aae4fa70920cb3ee4"); | ||
'it should gererate correct uri given an email': function(test) { | ||
test.equal(gravatar.url('emerleite@gmail.com'), baseURI + "93e9084aa289b7f1f5e4ab6716a56c3b"); | ||
test.equal(gravatar.url('emerleite@yahoo.com.br'), baseURI + "6c47672b0d58bd6aae4fa70920cb3ee4"); | ||
test.done(); | ||
}, | ||
'it should generate same uri ignoring case': function(test) { | ||
test.ok(gravatar.url('EMERLEITE@gmAil.com'), baseURI + "93e9084aa289b7f1f5e4ab6716a56c3b"); | ||
test.ok(gravatar.url('emerleite@YAHOO.com.BR'), baseURI + "6c47672b0d58bd6aae4fa70920cb3ee4"); | ||
test.done(); | ||
}, | ||
'it should generate same url ignoring case': function(test) { | ||
test.ok(gravatar.url('EMERLEITE@gmAil.com') == baseURI + "93e9084aa289b7f1f5e4ab6716a56c3b"); | ||
test.ok(gravatar.url('emerleite@YAHOO.com.BR') == baseURI + "6c47672b0d58bd6aae4fa70920cb3ee4"); | ||
'it should generate uri with size parameter': function(test) { | ||
var gravatarURI = gravatar.url('emerleite@gmail.com', { s: '200'}); | ||
var queryString = url.parse(gravatarURI, true).query; | ||
test.equal(queryString.s, '200'); | ||
test.done(); | ||
} | ||
}); |