-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjoke.js
More file actions
24 lines (22 loc) · 667 Bytes
/
joke.js
File metadata and controls
24 lines (22 loc) · 667 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
var http = require('http');
var Future = require('futures').future;
var get_joke = function(cat) {
var future = Future.create();
var url = "http://api.icndb.com/jokes/random";
if (cat) {
url += "?limitTo=[" + cat + "]";
}
http.get(url, function(res) {
var response = '';
res.on('data', function (chunk) {
response += chunk;
});
res.on('end', function () {
future.fulfill(undefined, JSON.parse(response).value.joke);
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
return future;
}
module.exports.get_joke = get_joke;