Skip to content

Commit

Permalink
Support passing 1D arrays as params that expect arrays (#83)
Browse files Browse the repository at this point in the history
* Bump deps/version
  • Loading branch information
Blacksmoke16 authored Aug 25, 2021
1 parent cf881e0 commit 7df069f
Show file tree
Hide file tree
Showing 4 changed files with 418 additions and 367 deletions.
2 changes: 1 addition & 1 deletion src/parser/shard.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: GESI

version: 8.4.0
version: 8.4.1

crystal: '>=0.34.0'

Expand Down
10 changes: 6 additions & 4 deletions src/script/esi_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ESIClient {
result = result.concat(
data.map((obj) => {
return endpoint.headers.map((header: IHeader) => typeof (obj[header.name]) === 'object' ? JSON.stringify(obj[header.name]) : obj[header.name]);
})
}),
);
} else if (data instanceof Object) {
result.push(endpoint.headers.map((header: IHeader) => typeof (data[header.name]) === 'object' ? JSON.stringify(data[header.name]) : data[header.name]));
Expand Down Expand Up @@ -144,7 +144,9 @@ class ESIClient {
if (param.type.includes('[]')) {
payload = !Array.isArray(paramValue) ?
[paramValue] :
paramValue.filter((item: any) => item[0]).map((item: any) => item[0]);
Array.isArray(paramValue[0]) ?
paramValue.filter((item: any) => item[0]).map((item: any) => item[0]) :
paramValue;
} else {
throw param.type + ' is an unexpected body type.';
}
Expand All @@ -166,10 +168,10 @@ class ESIClient {
method: endpoint.method,
url: `${ESIClient.BASE_URL}${path.replace('{version}', params.version || endpoint.version)}`,
headers: {
'user-agent': `GESI User ${this.characterData.character_id}`
'user-agent': `GESI User ${this.characterData.character_id}`,
},
contentType: 'application/json',
muteHttpExceptions: true
muteHttpExceptions: true,
};

if (payload) request.payload = JSON.stringify(payload);
Expand Down
Loading

0 comments on commit 7df069f

Please sign in to comment.