Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
UCDFiddes committed Mar 27, 2024
1 parent 8b60be8 commit d38946c
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 7 additions & 10 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions src/helpers/fetchEndpoint.ts
Original file line number Diff line number Diff line change
@@ -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<T extends string>(
endpoint: T,
Expand All @@ -13,7 +12,7 @@ export default async function fetchEndpoint<T extends string>(
): Promise<APIResponse<Routes<T>>> {
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);

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/toPoint.ts
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,4 +19,6 @@ export {
getPlayerInfomation,
};

export type { AllStatistics, AllLeaderboards };

export { Game } from "hive-bedrock-data";
10 changes: 5 additions & 5 deletions src/methods/getAllTimeStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export default async function getAllTimeStatistics<G extends Game>(
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,
Expand All @@ -38,11 +43,6 @@ export default async function getAllTimeStatistics<G extends Game>(
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
Expand Down
10 changes: 5 additions & 5 deletions src/methods/getMonthlyStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export default async function getMonthlyStatistics<G extends Game>(
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,
Expand All @@ -45,11 +50,6 @@ export default async function getMonthlyStatistics<G extends Game>(
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()
Expand Down
8 changes: 1 addition & 7 deletions src/types/output.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down

0 comments on commit d38946c

Please sign in to comment.