From d38946c24b0febd34b7290082bb35c5b4d79215f Mon Sep 17 00:00:00 2001 From: UCDFiddes <66165184+UCDFiddes@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:47:14 +0000 Subject: [PATCH] Fix review --- README.md | 2 +- docs/API.md | 17 +++++++---------- package.json | 2 +- src/helpers/fetchEndpoint.ts | 5 ++--- src/helpers/toPoint.ts | 2 +- src/index.ts | 4 +++- src/methods/getAllTimeStatistics.ts | 10 +++++----- src/methods/getMonthlyStatistics.ts | 10 +++++----- src/types/output.ts | 8 +------- 9 files changed, 26 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 2f4cc25..7fdf12b 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ const { data, error } = await getMaps(Game.TreasureWars); ### Fetch Metadata ```ts -import { getMaps, Game } from "hive-bedrock-api"; +import { getMetadata, Game } from "hive-bedrock-api"; // Returns data for a specific game's currently active maps const { data, error } = await getMetadata(Game.TreasureWars); diff --git a/docs/API.md b/docs/API.md index 63614d8..152f1b7 100644 --- a/docs/API.md +++ b/docs/API.md @@ -27,9 +27,9 @@ Returns a Promise which resolves to the following object: ```ts import { getMonthlyStatsistics, Game } from "hive-bedrock-api"; -// Get GAMERTAG's Treasure Wars stats from June 2023 +// Get player's Treasure Wars stats from June 2023 const { data, error } = await getMonthlyStatsistics( - "GAMERTAG", + "player", Game.TreasureWars, { year: 2023, @@ -97,11 +97,8 @@ Returns a Promise which resolves to the following object: ```ts import { getAllTimeStatistics, Game } from "hive-bedrock-api"; -// Get GAMERTAG's all-time Hide and Seek stats -const { data, error } = await getAllTimeStatistics( - "GAMERTAG", - Game.HideAndSeek -); +// Get player's all-time Hide and Seek stats +const { data, error } = await getAllTimeStatistics("player", Game.HideAndSeek); ``` ## getAllTimeLeaderboard(game[, options]) @@ -219,7 +216,7 @@ Returns a Promise which resolves to the following object: | Field | Type | Description | | -------- | ------------------------------------------- | -------------------------------- | -| data | [Response](API.md#map-data) `\| null` | The response data | +| data | [Response](API.md#game-metadata) `\| null` | The response data | | error | `{ code: number, message: string } \| null` | Error data | | status | `number` | The http status returned | | duration | `number \| undefined` | The duration of the http request | @@ -257,8 +254,8 @@ Returns a Promise which resolves to the following object ```ts import { getPlayerInformation } from "hive-bedrock-api"; -// Get GAMERTAG's player info. -const { data, error } = await getPlayerInformation("GAMERTAG"); +// Get player's player info. +const { data, error } = await getPlayerInformation("player"); ``` ## PlayerInfo diff --git a/package.json b/package.json index 37d50c5..9e5d7f1 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "license": "MIT", "author": "Cubeedge Studios", "dependencies": { - "hive-bedrock-data": "^1.1.2" + "hive-bedrock-data": "^1.1.7" }, "scripts": { "prepack": "yarn build", diff --git a/src/helpers/fetchEndpoint.ts b/src/helpers/fetchEndpoint.ts index 6413b2a..7ae969f 100644 --- a/src/helpers/fetchEndpoint.ts +++ b/src/helpers/fetchEndpoint.ts @@ -1,6 +1,5 @@ -import { API_SERVER } from ".."; import { APIResponse } from "../types/types"; -import { Routes } from "hive-bedrock-data"; +import { API_BASE_ENDPOINT, Routes } from "hive-bedrock-data"; export default async function fetchEndpoint( endpoint: T, @@ -13,7 +12,7 @@ export default async function fetchEndpoint( ): Promise>> { try { let time_start = performance.now(); - let request = await fetch(API_SERVER + endpoint, init); + let request = await fetch(API_BASE_ENDPOINT + endpoint, init); let time_end = performance.now(); let duration = Math.round(time_end - time_start); diff --git a/src/helpers/toPoint.ts b/src/helpers/toPoint.ts index ed5b757..47d63fa 100644 --- a/src/helpers/toPoint.ts +++ b/src/helpers/toPoint.ts @@ -1,3 +1,3 @@ export default function toPoint(num: number, point: number): number { - return (Math.round((num * 10) ^ point) / 10) ^ point; + return Math.round(num * (10 ^ point)) / (10 ^ point); } diff --git a/src/index.ts b/src/index.ts index cda9b31..65faeba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,8 +6,8 @@ import getMetdata from "./methods/getMetadata"; import getMonthlyLeaderboard from "./methods/getMonthlyLeaderboard"; import getMonthlyStatistics from "./methods/getMonthlyStatistics"; import getPlayerInfomation from "./methods/getPlayerInfomation"; +import type { AllStatistics, AllLeaderboards } from "./types/output"; -export const API_SERVER = "https://api.playhive.com/v0"; export { getAllTimeLeaderboard, getMonthlyLeaderboard, @@ -19,4 +19,6 @@ export { getPlayerInfomation, }; +export type { AllStatistics, AllLeaderboards }; + export { Game } from "hive-bedrock-data"; diff --git a/src/methods/getAllTimeStatistics.ts b/src/methods/getAllTimeStatistics.ts index b250b41..04bb71f 100644 --- a/src/methods/getAllTimeStatistics.ts +++ b/src/methods/getAllTimeStatistics.ts @@ -28,6 +28,11 @@ export default async function getAllTimeStatistics( let game_id: G | "all" = "all"; let method_options: Options | undefined = game_or_options as Options; + if (typeof game_or_options === "string") { + game_id = game_or_options as G; + method_options = options; + } + if (!isGame(game_id as G) && game_id !== "all") return { status: 404, @@ -38,11 +43,6 @@ export default async function getAllTimeStatistics( data: null, }; - if (isGame(game_or_options as G)) { - game_id = game_or_options as G; - method_options = options; - } - let response = await fetchEndpoint( `/game/all/${game_id}/${identifier}`, method_options?.init diff --git a/src/methods/getMonthlyStatistics.ts b/src/methods/getMonthlyStatistics.ts index d1266ec..5dffb7e 100644 --- a/src/methods/getMonthlyStatistics.ts +++ b/src/methods/getMonthlyStatistics.ts @@ -35,6 +35,11 @@ export default async function getMonthlyStatistics( let method_options: MonthlyOptions | undefined = game_or_options as MonthlyOptions; + if (typeof game_or_options === "string") { + game_id = game_or_options as G; + method_options = options; + } + if (!isGame(game_id as G) && game_id !== "all") return { status: 404, @@ -45,11 +50,6 @@ export default async function getMonthlyStatistics( data: null, }; - if (isGame(game_or_options as G)) { - game_id = game_or_options as G; - method_options = options; - } - let current_date = new Date(); let endpoint = `/game/monthly/player/${game_id}/${identifier}/${ options?.year ?? current_date.getFullYear() diff --git a/src/types/output.ts b/src/types/output.ts index ec01cc5..160f53c 100644 --- a/src/types/output.ts +++ b/src/types/output.ts @@ -1,10 +1,4 @@ -import { - Game, - Leaderboards, - PlayerMetadata, - Statistics, - Timeframe, -} from "hive-bedrock-data"; +import { Game, Leaderboards, Statistics, Timeframe } from "hive-bedrock-data"; type Processor = (stats: any) => void; export type GameProcessors = {