Skip to content

Instantly share code, notes, and snippets.

@AngellusMortis
Created October 7, 2020 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngellusMortis/128727fc1e12dc06b6ebdb556fe93465 to your computer and use it in GitHub Desktop.
Save AngellusMortis/128727fc1e12dc06b6ebdb556fe93465 to your computer and use it in GitHub Desktop.
// Optional: You can use `msgpack` instead of JSON for some serious download size gains
// See https://gist.github.com/AngellusMortis/a6dec43a8614ac5ff5dc47b38da68750
// For how to automatically set it up with Axios
const mapMsgpack = (root: any, key_map: string[]) => {
const mappedData: any = root instanceof Array ? [] : {};
Reflect.ownKeys(root).forEach((index) => {
let value = root[index];
let finalKey: string | number;
if (typeof index == "symbol") {
return;
} else if (typeof index == "string") {
finalKey = parseInt(index);
} else {
finalKey = index;
}
if (value !== null && (value instanceof Array || typeof value == "object")) {
value = mapMsgpack(value, key_map);
}
if (key_map[finalKey] !== undefined && !Array.isArray(root)) {
finalKey = key_map[finalKey];
}
mappedData[finalKey] = value;
});
return mappedData;
};
const axiosConfig = {
params: {
format: "msgpack",
},
responseType: "arraybuffer",
transformResponse: [
(data: ArrayBuffer): any => {
const unmappedData = msgpack.decode(new Uint8Array(data));
mapMsgpack(unmappedData[0], unmappedData[1]);
},
],
};
// https://github.com/anttiviljami/openapi-client-axios
// OpenAPI Client generator for Axios
const OpenAPIClientAxios = require('openapi-client-axios').default;
// Optional: You can also use openapi-client-axios-typegen to make Typescript type bindings for client
// See openapi-client-axios github for examples
// Optional: You can use `msgpack` instead of JSON for some serious download size gains
// See `msgpack.ts` for how to automatically set it up with Axios
async function main() {
const api = new OpenAPIClientAxios({ definition: 'https://api.boundlexx.app/api/v1/schema/?format=openapi-json' });
// or Testing Universe
api.withServer("Live Universe");
const client = await api.getClient();
// list worlds with filters
let res = await client.listWorlds([{ "name": "limit", value: 1, in: "query" }]);
console.log(res.data);
// {
// count: 1043,
// next: 'https://api.boundlexx.app/api/v1/worlds/?limit=1&offset=1',
// previous: null,
// results: [
// {
// url: 'https://api.boundlexx.app/api/v1/worlds/1/',
// pollsUrl: 'https://api.boundlexx.app/api/v1/worlds/1/polls/',
// blockColorsUrl: 'https://api.boundlexx.app/api/v1/worlds/1/block-colors/',
// distancesUrl: 'https://api.boundlexx.app/api/v1/worlds/1/distances/',
// requestBasketsUrl: 'https://api.boundlexx.app/api/v1/worlds/1/request-baskets/',
// nextRequestBasketUpdate: null,
// shopStandsUrl: 'https://api.boundlexx.app/api/v1/worlds/id/shop-stands/',
// nextShopStandUpdate: null,
// id: 1,
// active: true,
// name: 'euc1_t0_0',
// displayName: 'Sochaltin I',
// textName: 'Sochaltin I',
// htmlName: 'Sochaltin I',
// address: 'gs-live-euc1.playboundless.com',
// imageUrl: 'https://cdn.boundlexx.app/worlds/sochaltin_i.png',
// forumUrl: 'https://forum.playboundless.com/t/42624',
// assignment: null,
// region: 'euc',
// tier: 0,
// size: 288,
// worldType: 'LUSH',
// specialType: 0,
// protectionPoints: null,
// protectionSkill: null,
// timeOffset: '2018-08-16T11:52:28.706624-04:00',
// isSovereign: false,
// isPerm: true,
// isExo: false,
// isCreative: false,
// isLocked: false,
// isPublic: true,
// isPublicEdit: null,
// isPublicClaim: null,
// isFinalized: null,
// numberOfRegions: 50,
// start: '2018-08-15T20:00:00-04:00',
// end: null,
// atmosphereColor: '#53f8ff',
// waterColor: '#4e9797',
// surfaceLiquid: 'Water',
// coreLiquid: 'Water',
// bows: null
// }
// ]
// }
// get world
res = await client.retrieveWorld(10);
console.log(res.data);
// {
// url: 'https://api.boundlexx.app/api/v1/worlds/10/',
// pollsUrl: 'https://api.boundlexx.app/api/v1/worlds/10/polls/',
// blockColorsUrl: 'https://api.boundlexx.app/api/v1/worlds/10/block-colors/',
// distancesUrl: 'https://api.boundlexx.app/api/v1/worlds/10/distances/',
// requestBasketsUrl: 'https://api.boundlexx.app/api/v1/worlds/10/request-baskets/',
// nextRequestBasketUpdate: null,
// shopStandsUrl: 'https://api.boundlexx.app/api/v1/worlds/id/shop-stands/',
// nextShopStandUpdate: null,
// id: 10,
// active: true,
// name: 'use1_t4_0',
// displayName: 'Serpensarindi',
// textName: 'Serpensarindi',
// htmlName: 'Serpensarindi',
// address: 'gs-live-use1.playboundless.com',
// imageUrl: 'https://cdn.boundlexx.app/worlds/serpensarindi.png',
// forumUrl: 'https://forum.playboundless.com/t/42645',
// assignment: null,
// region: 'use',
// tier: 4,
// size: 288,
// worldType: 'BLAST',
// specialType: 0,
// protectionPoints: 3,
// protectionSkill: {
// url: 'https://api.boundlexx.app/api/v1/skills/73/',
// name: 'Volatile Atmosphere Armour'
// },
// timeOffset: '2018-08-16T12:47:00.003152-04:00',
// isSovereign: false,
// isPerm: true,
// isExo: false,
// isCreative: false,
// isLocked: false,
// isPublic: true,
// isPublicEdit: null,
// isPublicClaim: null,
// isFinalized: null,
// numberOfRegions: 50,
// start: '2018-08-15T20:00:00-04:00',
// end: null,
// atmosphereColor: '#f3f3f3',
// waterColor: '#909090',
// surfaceLiquid: 'Water',
// coreLiquid: 'Lava',
// bows: {
// best: [ 'emerald' ],
// neutral: [ 'amethyst', 'sapphire' ],
// lucent: [ 'umbris' ]
// }
// }
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment