Skip to content

Commit 9d45469

Browse files
add statistics endpoint
1 parent 61cd65e commit 9d45469

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcutils-js-api",
3-
"version": "2.0.28",
3+
"version": "2.0.29",
44
"module": "dist/index.js",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { Cape } from "./types/player/cape/cape";
88
import { ServerRegistryEntry } from "./types/server-registry/server-registry-entry";
99
import { Player } from "./types/player/player";
1010
import { CachedPlayerName } from "./types/cache/cached-player-name";
11+
import { StatisticsResponse } from "./types/response/statistics-response";
1112

1213
export class McUtilsAPI {
1314
private readonly endpoint: string;
@@ -327,6 +328,21 @@ export class McUtilsAPI {
327328
error: (await response.json()) as ErrorResponse,
328329
};
329330
}
331+
332+
/**
333+
* Fetch the statistics of the API.
334+
*
335+
* @returns the statistics or the error (if one occurred)
336+
*/
337+
async fetchStatistics(): Promise<{ statistics?: StatisticsResponse; error?: ErrorResponse }> {
338+
const response = await fetch(`${this.endpoint}/statistics`);
339+
if (response.ok) {
340+
return { statistics: (await response.json()) as StatisticsResponse };
341+
}
342+
return {
343+
error: (await response.json()) as ErrorResponse,
344+
};
345+
}
330346
}
331347

332348
export default McUtilsAPI;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type StatisticsResponse = {
2+
seenPlayers: number;
3+
seenSkins: number;
4+
seenCapes: number;
5+
};

0 commit comments

Comments
 (0)