-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhackernews.js
More file actions
60 lines (48 loc) · 1.54 KB
/
hackernews.js
File metadata and controls
60 lines (48 loc) · 1.54 KB
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
57
58
59
var hn = function() {
if (typeof require == 'function') {
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var exports = module.exports = {};
var httpGet = function(url)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", url, false);
xmlHttp.send(null);
return JSON.parse(xmlHttp.responseText);
}
} else {
var exports = {};
var httpGet = $.get;
}
exports.getItem = function(item_id) {
item_id = item_id.toString();
var url = 'https://hacker-news.firebaseio.com/v0/item/' + item_id + '.json';
return httpGet(url);
}
exports.getUser = function(username) {
var url = 'https://hacker-news.firebaseio.com/v0/user/' + username +
'.json';
return httpGet(url);
}
exports.getMaxItem = function() {
return httpGet('https://hacker-news.firebaseio.com/v0/maxitem.json');
}
exports.getTopStories = function() {
return httpGet('https://hacker-news.firebaseio.com/v0/topstories.json');
}
exports.getNewStories = function() {
return httpGet('https://hacker-news.firebaseio.com/v0/newstories.json');
}
exports.getAskStories = function () {
return httpGet('https://hacker-news.firebaseio.com/v0/askstories.json');
}
exports.getShowStories = function () {
return httpGet('https://hacker-news.firebaseio.com/v0/showstories.json');
}
exports.getJobStories = function () {
return httpGet('https://hacker-news.firebaseio.com/v0/jobstories.json');
}
exports.getUpdates = function() {
return httpGet('https://hacker-news.firebaseio.com/v0/updates.json');
}
return exports
}();