-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_calls.js
56 lines (54 loc) · 1.39 KB
/
api_calls.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
45
46
47
48
49
50
51
52
53
54
55
56
var request = require('request');
var assert = require('assert');
var API_CALLS = {
//Grab all of the winners in a single category, returning an array of simplified objects.
get_winners_by_cat: function (tid, callback) {
//forming the API endpoint url
var winnersUrl = 'http://www.pulitzer.org/cms/api/1/winners/cat/' + tid + '/raw.json';
request({
url: winnersUrl,
json: true
}, function(error, response, body){
assert.equal(error, null);
if (body && body instanceof Array){
callback(tid, body);
}
else return null;
});
},
get_finalists_by_cat: function(tid, callback) {
var finalistsUrl = 'http://www.pulitzer.org/cms/api/1/finalist/' + tid + '/all/raw.json';
request({
url: finalistsUrl,
json: true
}, function(error, response, body){
assert.equal(error, null);
if (body && body instanceof Array){
callback(tid, body);
}
else return null;
});
},
//translate a tid into a category
get_cat_from_tid: function (tid, callback) {
//forming the API url
var catUrl = 'http://www.pulitzer.org/cms/api/1/term/' + tid + '/raw.json';
request({
url: catUrl,
json: true
}, function(error, response, body){
assert.equal(error, null);
if (body){
callback(tid, body);
}
else {
return null
}
});
},
get_year_from_tid: function (tid) {
var year = 2015 - (tid - 105);
return year;
}
};
exports = module.exports = API_CALLS;