Skip to content

Commit

Permalink
Allow for more than 100 IDs in allianceNames endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacksmoke16 authored Sep 18, 2017
1 parent cb947d7 commit b4b0128
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions GESI.gs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// /u/blacksmoke16 @ Reddit
// @Blacksmoke16#1684 @ Discord
app_version = '2.3.0';
app_version = '2.3.1';

// Setup variables used throughout script
CLIENT_ID = '7c382c66a6c8487d8b64e50daad86f9b';
Expand Down Expand Up @@ -295,7 +295,15 @@ function allianceIds(opt_headers) {
*/
function allianceNames(alliance_ids, opt_headers) {
if (!alliance_ids) throw 'A range of alliance ids is required';
return getArrayObjectResponse_(arguments.callee.name, '', opt_headers, {alliance_ids: alliance_ids});
var names = [];
var data = chunkArray_(alliance_ids, 100);
for(var d = 0; d < data.length; d++) {
var result = getArrayObjectResponse_(arguments.callee.name, '', opt_headers, {alliance_ids: data[d]});
if(d >= 1 && (opt_headers === true || opt_headers === undefined)) result.shift();
for(var n = 0; n < result.length; n++) names.push(result[n]);
}

return names;
}

/**
Expand Down Expand Up @@ -954,6 +962,14 @@ function flatten_(ob) {
return toReturn;
};

function chunkArray_(a, c) {
var g = [], i;
for (i = 0; i < a.length; i += c) {
g.push(a.slice(i, i + c));
}
return g;
}

// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// OAth2 Functions
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit b4b0128

Please sign in to comment.