Skip to content

Commit 7ab5175

Browse files
Change calls to return just the data unless overwritten by the settings. Closes #1
1 parent 2307b1f commit 7ab5175

File tree

5 files changed

+13
-20
lines changed

5 files changed

+13
-20
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ To get started simply require the package and optionally provide an optional obj
88

99
```
1010
var api = require('atlauncher-api')({
11-
api_key: 'my-api-key,
12-
force_run: false
11+
api_key: 'my-api-key
1312
});
1413
```
1514

1615
The api_key argument is your API-KEY used for admin or PSP api calls.
1716

18-
The force_run argument is a boolean (true/false) if we should ignore breaking api calls. For instance when you're about to reach your request limit and get IP banned the force option will allow you to bypass the exception which gets thrown halting execution.
19-
2017
For instance for running public api calls such as getting a list of all packs you can use the following:
2118

2219
```
@@ -27,7 +24,7 @@ api.packs.full.all(function(err, res) {
2724
return console.error(err);
2825
}
2926
30-
console.log(res.data);
27+
console.log(res);
3128
});
3229
```
3330

index.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = function (obj) {
2525
base_url: 'https://api.atlauncher.com/',
2626
api_version: 'v1',
2727
api_key: false,
28-
force_run: false
28+
return_full: false
2929
};
3030

3131
if (obj !== undefined) {
@@ -56,10 +56,8 @@ module.exports = function (obj) {
5656
if (e) {
5757
return callback(e, res);
5858
} else {
59-
res = 'Saved to ' + saveTo + '!';
59+
return callback(err, 'Saved to ' + saveTo + '!');
6060
}
61-
62-
return callback(err, res);
6361
});
6462
};
6563

@@ -91,16 +89,11 @@ module.exports = function (obj) {
9189
}
9290

9391
request(options, function (err, req, body) {
94-
if (!err && body.error && body.code == 401 && body.message == 'API key missing or invalid!') {
95-
console.error('The API key provided was not valid!');
96-
}
97-
98-
if (!err && body && body.code == 429 && !settings.force_run) {
99-
// Exceeded API request limit, we must stop now
100-
throw new Error(body.message);
92+
if (body.error) {
93+
return callback(new Error(body.message))
10194
}
10295

103-
return callback(err, body);
96+
return callback(err, (settings.return_full ? body : body.data));
10497
});
10598
};
10699

tests/admin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
'use strict';
2020

2121
var atlauncher = require('../index')({
22-
api_key: process.env.API_KEY
22+
api_key: process.env.API_KEY,
23+
return_full: true
2324
}),
2425
assert = require('assert');
2526

tests/psp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
'use strict';
2020

2121
var atlauncher = require('../index')({
22-
api_key: process.env.PSP_API_KEY
22+
api_key: process.env.PSP_API_KEY,
23+
return_full: true
2324
}),
2425
assert = require('assert');
2526

tests/public.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
'use strict';
2020

2121
var atlauncher = require('../index')({
22-
api_key: process.env.API_KEY
22+
api_key: process.env.API_KEY,
23+
return_full: true
2324
}),
2425
assert = require('assert');
2526

0 commit comments

Comments
 (0)