-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathid.js
More file actions
41 lines (33 loc) · 992 Bytes
/
id.js
File metadata and controls
41 lines (33 loc) · 992 Bytes
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
var authinfo_url = 'https://id.ripple.com';
var request = require('request');
var id_cache = {
//"rrrrrrrrrrrrrrrrrrrrBZbvji": "ONE",
};
exports.lookup = function(acct) {
if (id_cache.hasOwnProperty(acct)) {
// This acct is cached or pending lookup. Nothing to do.
return;
}
id_cache[acct] = -1; // pending
request(authinfo_url + '/v1/user/' + acct, function (error, response, body) {
if (!error && response.statusCode == 200) {
//console.log(body);
var json = JSON.parse(body);
//console.log(json);
//console.log("adding " + acct + " = " + json.username + " to cache.");
id_cache[acct] = json.username;
}
});
};
exports.getCache = function(acct, wait) {
wait = typeof wait !== 'undefined' ? wait : 1000; // default wait time
if (id_cache.hasOwnProperty(acct)) {
if (id_cache[acct] === -1 && wait) {
// lookup is pending. Wait?
}
else {
return id_cache[acct];
}
}
return false;
};