Skip to content

Commit 1f2efbe

Browse files
That's all the public API routes done and with tests of a small nature
1 parent 173eb65 commit 1f2efbe

File tree

3 files changed

+206
-0
lines changed

3 files changed

+206
-0
lines changed

index.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,88 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
module.exports = function (apiKey) {
20+
var request = require('request'),
21+
baseUrl = 'https://api.atlauncher.com/',
22+
version = 'v1';
23+
24+
var makeUrl = function (path) {
25+
return baseUrl + version + '/' + (path ? path : '');
26+
};
27+
28+
var makeRequest = function (path, method, data, callback) {
29+
if (data && !callback) {
30+
callback = data;
31+
data = false;
32+
}
33+
34+
var options = {
35+
url: path,
36+
json: true,
37+
method: method,
38+
headers: {
39+
'User-Agent': 'node/atlauncher-api'
40+
}
41+
};
42+
43+
if (method == 'POST' && data) {
44+
options.form = data;
45+
}
46+
47+
if (apiKey) {
48+
options.headers.set('API-KEY', apiKey);
49+
}
50+
51+
request(options, function (err, req, body) {
52+
return callback(err, body);
53+
});
54+
};
55+
56+
return {
57+
heartbeat: function (callback) {
58+
makeRequest(baseUrl, 'GET', callback);
59+
},
60+
packs: {
61+
simple: function (callback) {
62+
makeRequest(makeUrl('packs/simple'), 'GET', callback);
63+
},
64+
full: {
65+
all: function (callback) {
66+
makeRequest(makeUrl('packs/full/all'), 'GET', callback);
67+
},
68+
public: function (callback) {
69+
makeRequest(makeUrl('packs/full/public'), 'GET', callback);
70+
},
71+
semipublic: function (callback) {
72+
makeRequest(makeUrl('packs/full/semipublic'), 'GET', callback);
73+
},
74+
private: function (callback) {
75+
makeRequest(makeUrl('packs/full/private'), 'GET', callback);
76+
}
77+
}
78+
},
79+
stats: {
80+
downloads: {
81+
all: function (callback) {
82+
makeRequest(makeUrl('stats/downloads/all'), 'GET', callback);
83+
},
84+
exe: function (callback) {
85+
makeRequest(makeUrl('stats/downloads/exe'), 'GET', callback);
86+
},
87+
jar: function (callback) {
88+
makeRequest(makeUrl('stats/downloads/jar'), 'GET', callback);
89+
},
90+
zip: function (callback) {
91+
makeRequest(makeUrl('stats/downloads/zip'), 'GET', callback);
92+
}
93+
}
94+
},
95+
pack: function (name, version, callback) {
96+
if (version && !callback) {
97+
makeRequest(makeUrl('pack/' + name), 'GET', version);
98+
} else {
99+
makeRequest(makeUrl('pack/' + name + '/' + version), 'GET', callback);
100+
}
101+
}
102+
};
103+
};

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"version": "1.0.0",
44
"description": "Node.js module for interacting with the ATLauncher API",
55
"main": "index.js",
6+
"scripts": {
7+
"test": "node tests/test.js"
8+
},
69
"repository": {
710
"type": "git",
811
"url": "https://github.com/ATLauncher/ATLauncher-API---NodeJS.git"

tests/test.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* ATLauncher API - NodeJS - https://github.com/ATLauncher/ATLauncher-API---NodeJS
3+
* Copyright (C) 2015 ATLauncher
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
'use strict';
20+
21+
var atlauncher = require('../index')(),
22+
assert = require('assert');
23+
24+
atlauncher.heartbeat(function (err, res) {
25+
if (err) {
26+
return console.log(err);
27+
}
28+
29+
assert.equal(false, res.error);
30+
});
31+
32+
atlauncher.packs.simple(function (err, res) {
33+
if (err) {
34+
return console.log(err);
35+
}
36+
37+
assert.equal(false, res.error);
38+
});
39+
40+
atlauncher.packs.full.all(function (err, res) {
41+
if (err) {
42+
return console.log(err);
43+
}
44+
45+
assert.equal(false, res.error);
46+
});
47+
48+
atlauncher.packs.full.public(function (err, res) {
49+
if (err) {
50+
return console.log(err);
51+
}
52+
53+
assert.equal(false, res.error);
54+
});
55+
56+
atlauncher.packs.full.semipublic(function (err, res) {
57+
if (err) {
58+
return console.log(err);
59+
}
60+
61+
assert.equal(false, res.error);
62+
});
63+
64+
atlauncher.packs.full.private(function (err, res) {
65+
if (err) {
66+
return console.log(err);
67+
}
68+
69+
assert.equal(false, res.error);
70+
});
71+
72+
atlauncher.stats.downloads.all(function (err, res) {
73+
if (err) {
74+
return console.log(err);
75+
}
76+
77+
assert.equal(false, res.error);
78+
});
79+
80+
atlauncher.stats.downloads.exe(function (err, res) {
81+
if (err) {
82+
return console.log(err);
83+
}
84+
85+
assert.equal(false, res.error);
86+
});
87+
88+
atlauncher.stats.downloads.jar(function (err, res) {
89+
if (err) {
90+
return console.log(err);
91+
}
92+
93+
assert.equal(false, res.error);
94+
});
95+
96+
atlauncher.stats.downloads.zip(function (err, res) {
97+
if (err) {
98+
return console.log(err);
99+
}
100+
101+
assert.equal(false, res.error);
102+
});
103+
104+
atlauncher.pack('VanillaMinecraft', function (err, res) {
105+
if (err) {
106+
return console.log(err);
107+
}
108+
109+
assert.equal(false, res.error);
110+
});
111+
112+
atlauncher.pack('VanillaMinecraft', '1.7.10', function (err, res) {
113+
if (err) {
114+
return console.log(err);
115+
}
116+
117+
assert.equal(false, res.error);
118+
});

0 commit comments

Comments
 (0)