From 6631a81f453d2c67263c8deb8993c198e5652b2f Mon Sep 17 00:00:00 2001 From: Jacob Date: Tue, 3 Sep 2024 20:19:10 +0800 Subject: [PATCH] Requests -> RequestHandler --- src/API/API.d.ts | 2 +- src/API/getAchievements.ts | 4 ++-- src/API/getActiveHouses.ts | 4 ++-- src/API/getBoosters.ts | 4 ++-- src/API/getChallenges.ts | 4 ++-- src/API/getGameCounts.ts | 4 ++-- src/API/getGuild.ts | 6 +++--- src/API/getGuildAchievements.ts | 4 ++-- src/API/getHouse.ts | 4 ++-- src/API/getLeaderboards.ts | 4 ++-- src/API/getPlayer.ts | 4 ++-- src/API/getPlayerHouses.ts | 6 +++--- src/API/getQuests.ts | 4 ++-- src/API/getRecentGames.ts | 6 +++--- src/API/getSkyblockAuction.ts | 4 ++-- src/API/getSkyblockAuctions.ts | 2 +- src/API/getSkyblockAuctionsByPlayer.ts | 4 ++-- src/API/getSkyblockBazaar.ts | 4 ++-- src/API/getSkyblockBingo.ts | 4 ++-- src/API/getSkyblockFireSales.ts | 4 ++-- src/API/getSkyblockGarden.ts | 4 ++-- src/API/getSkyblockGovernment.ts | 4 ++-- src/API/getSkyblockMember.ts | 4 ++-- src/API/getSkyblockMuseum.ts | 9 ++++++--- src/API/getSkyblockNews.ts | 4 ++-- src/API/getSkyblockProfiles.ts | 4 ++-- src/API/getStatus.ts | 6 +++--- src/API/getWatchdogStats.ts | 4 ++-- src/Client.test.ts | 14 +++++++------- src/Client.ts | 6 +++--- src/Private/RateLimit.ts | 2 +- src/Private/{Requests.ts => RequestHandler.ts} | 0 src/index.ts | 3 ++- 33 files changed, 75 insertions(+), 71 deletions(-) rename src/Private/{Requests.ts => RequestHandler.ts} (100%) diff --git a/src/API/API.d.ts b/src/API/API.d.ts index fea39602..68e8ac70 100644 --- a/src/API/API.d.ts +++ b/src/API/API.d.ts @@ -1,4 +1,4 @@ -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; export interface PlayerRequestOptions extends RequestOptions { guild?: boolean; diff --git a/src/API/getAchievements.ts b/src/API/getAchievements.ts index 3b832b82..308faf3a 100644 --- a/src/API/getAchievements.ts +++ b/src/API/getAchievements.ts @@ -1,7 +1,7 @@ import Achievements from '../structures/Static/Achievements'; import Client from '../Client'; import Endpoint from '../Private/Endpoint'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getAchievements extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getAchievements extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/resources/achievements', options); + const res = await this.client.requestHandler.request('/resources/achievements', options); if (res.options.raw) return res.data; return new Achievements(res.data); } diff --git a/src/API/getActiveHouses.ts b/src/API/getActiveHouses.ts index 1b0d1822..8552e349 100644 --- a/src/API/getActiveHouses.ts +++ b/src/API/getActiveHouses.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import House from '../structures/House'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getActiveHouses extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getActiveHouses extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/housing/active', options); + const res = await this.client.requestHandler.request('/housing/active', options); if (res.options.raw) return res.data; return res.data.map((b: any) => new House(b)); } diff --git a/src/API/getBoosters.ts b/src/API/getBoosters.ts index 85bb3a55..385a50d2 100644 --- a/src/API/getBoosters.ts +++ b/src/API/getBoosters.ts @@ -1,7 +1,7 @@ import Booster from '../structures/Boosters/Booster'; import Client from '../Client'; import Endpoint from '../Private/Endpoint'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getBoosters extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getBoosters extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/boosters', options); + const res = await this.client.requestHandler.request('/boosters', options); if (res.options.raw) return res.data; return res.data.boosters.map((b: any) => new Booster(b)).reverse(); } diff --git a/src/API/getChallenges.ts b/src/API/getChallenges.ts index b9632b5a..a1677fb6 100644 --- a/src/API/getChallenges.ts +++ b/src/API/getChallenges.ts @@ -1,7 +1,7 @@ import Challenges from '../structures/Static/Challenges'; import Client from '../Client'; import Endpoint from '../Private/Endpoint'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getChallenges extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getChallenges extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/resources/challenges', options); + const res = await this.client.requestHandler.request('/resources/challenges', options); if (res.options.raw) return res.data; return new Challenges(res.data); } diff --git a/src/API/getGameCounts.ts b/src/API/getGameCounts.ts index 1a158984..682b0741 100644 --- a/src/API/getGameCounts.ts +++ b/src/API/getGameCounts.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import GameCounts from '../structures/GameCounts'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getGameCounts extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getGameCounts extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/counts', options); + const res = await this.client.requestHandler.request('/counts', options); if (res.options.raw) return res.data; return new GameCounts(res.data); } diff --git a/src/API/getGuild.ts b/src/API/getGuild.ts index be2f31c5..bb298274 100644 --- a/src/API/getGuild.ts +++ b/src/API/getGuild.ts @@ -2,7 +2,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import Guild from '../structures/Guild/Guild'; import isGuildID from '../utils/isGuildID'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getGuild extends Endpoint { readonly client: Client; @@ -19,11 +19,11 @@ class getGuild extends Endpoint { if (!query) throw new Error(this.client.errors.NO_GUILD_QUERY); if ('id' === searchParameter && !isGuildID(query)) throw new Error(this.client.errors.INVALID_GUILD_ID); const isPlayerQuery = 'player' === searchParameter; - if (isPlayerQuery) query = await this.client.requests.toUUID(query); + if (isPlayerQuery) query = await this.client.requestHandler.toUUID(query); if (!['id', 'name', 'player'].includes(searchParameter)) { throw new Error(this.client.errors.INVALID_GUILD_SEARCH_PARAMETER); } - const res = await this.client.requests.request(`/guild?${searchParameter}=${encodeURI(query)}`, options); + const res = await this.client.requestHandler.request(`/guild?${searchParameter}=${encodeURI(query)}`, options); if (res.options.raw) return res.data; if (!res.data.guild && 'player' !== searchParameter) { throw new Error(this.client.errors.GUILD_DOES_NOT_EXIST); diff --git a/src/API/getGuildAchievements.ts b/src/API/getGuildAchievements.ts index 4f1e824e..8beaf29a 100644 --- a/src/API/getGuildAchievements.ts +++ b/src/API/getGuildAchievements.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import GuildAchievements from '../structures/Static/GuildAchievements'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getGuildAchievements extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getGuildAchievements extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/resources/guilds/achievements', options); + const res = await this.client.requestHandler.request('/resources/guilds/achievements', options); if (res.options.raw) return res.data; return new GuildAchievements(res.data); } diff --git a/src/API/getHouse.ts b/src/API/getHouse.ts index 431df1b1..227cb0d0 100644 --- a/src/API/getHouse.ts +++ b/src/API/getHouse.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import House from '../structures/House'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getHouse extends Endpoint { readonly client: Client; @@ -12,7 +12,7 @@ class getHouse extends Endpoint { async execute(query: string, options?: RequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_UUID); - const res = await this.client.requests.request(`/housing/house?house=${query}`, options); + const res = await this.client.requestHandler.request(`/housing/house?house=${query}`, options); if (res.options.raw) return res.data; return new House(res.data); } diff --git a/src/API/getLeaderboards.ts b/src/API/getLeaderboards.ts index c3a75592..8810da50 100644 --- a/src/API/getLeaderboards.ts +++ b/src/API/getLeaderboards.ts @@ -2,7 +2,7 @@ import Client from '../Client'; import Constants from '../utils/Constants'; import Endpoint from '../Private/Endpoint'; import Leaderboard from '../structures/Leaderboard'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getLeaderboards extends Endpoint { readonly client: Client; @@ -12,7 +12,7 @@ class getLeaderboards extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/leaderboards', options); + const res = await this.client.requestHandler.request('/leaderboards', options); if (res.options.raw) return res.data; if (!res.data.leaderboards) { throw new Error(this.client.errors.SOMETHING_WENT_WRONG.replace(/{cause}/, 'Try again.')); diff --git a/src/API/getPlayer.ts b/src/API/getPlayer.ts index d1745340..c54cd973 100644 --- a/src/API/getPlayer.ts +++ b/src/API/getPlayer.ts @@ -12,8 +12,8 @@ class getPlayer extends Endpoint { async execute(query: string, options?: PlayerRequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); - query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/player?uuid=${query}`, options); + query = await this.client.requestHandler.toUUID(query); + const res = await this.client.requestHandler.request(`/player?uuid=${query}`, options); if (res.options.raw) return res.data; if (query && !res.data.player) throw new Error(this.client.errors.PLAYER_HAS_NEVER_LOGGED); return new Player(res.data.player, { diff --git a/src/API/getPlayerHouses.ts b/src/API/getPlayerHouses.ts index 855c8bfa..1d31fd24 100644 --- a/src/API/getPlayerHouses.ts +++ b/src/API/getPlayerHouses.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import House from '../structures/House'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getPlayerHouses extends Endpoint { readonly client: Client; @@ -12,8 +12,8 @@ class getPlayerHouses extends Endpoint { async execute(query: string, options?: RequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); - query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/housing/houses?player=${query}`, options); + query = await this.client.requestHandler.toUUID(query); + const res = await this.client.requestHandler.request(`/housing/houses?player=${query}`, options); if (res.options.raw) return res.data; return res.data.map((h: any) => new House(h)); } diff --git a/src/API/getQuests.ts b/src/API/getQuests.ts index 07d772e9..2ffdca11 100644 --- a/src/API/getQuests.ts +++ b/src/API/getQuests.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import Quests from '../structures/Static/Quests'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getQuests extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getQuests extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/resources/quests', options); + const res = await this.client.requestHandler.request('/resources/quests', options); if (res.options.raw) return res.data; return new Quests(res.data); } diff --git a/src/API/getRecentGames.ts b/src/API/getRecentGames.ts index c4dac6db..54ce2820 100644 --- a/src/API/getRecentGames.ts +++ b/src/API/getRecentGames.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import RecentGame from '../structures/RecentGame'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getRecentGames extends Endpoint { readonly client: Client; @@ -12,8 +12,8 @@ class getRecentGames extends Endpoint { async execute(query: string, options?: RequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); - query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/recentgames?uuid=${query}`, options); + query = await this.client.requestHandler.toUUID(query); + const res = await this.client.requestHandler.request(`/recentgames?uuid=${query}`, options); if (res.options.raw) return res.data; return res.data.games.map((x: any) => new RecentGame(x)); } diff --git a/src/API/getSkyblockAuction.ts b/src/API/getSkyblockAuction.ts index 17658334..a797f173 100644 --- a/src/API/getSkyblockAuction.ts +++ b/src/API/getSkyblockAuction.ts @@ -19,7 +19,7 @@ class getSkyblockAction extends Endpoint { if ('profile' === type) { filter = 'profile'; } else if ('player' === type) { - query = await this.client.requests.toUUID(query); + query = await this.client.requestHandler.toUUID(query); filter = 'player'; } else if ('auction' === type) { filter = 'uuid'; @@ -27,7 +27,7 @@ class getSkyblockAction extends Endpoint { throw new Error(this.client.errors.BAD_AUCTION_FILTER); } if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); - const res = await this.client.requests.request(`/skyblock/auction?${filter}=${query}`, options); + const res = await this.client.requestHandler.request(`/skyblock/auction?${filter}=${query}`, options); if (res.options.raw) return res.data; return res.data.auctions.map((a: any) => new Auction(a, options?.includeItemBytes ?? false)); } diff --git a/src/API/getSkyblockAuctions.ts b/src/API/getSkyblockAuctions.ts index 1a44ff74..846ad825 100644 --- a/src/API/getSkyblockAuctions.ts +++ b/src/API/getSkyblockAuctions.ts @@ -40,7 +40,7 @@ class getSkyblockAuctions extends Endpoint { } async getPage(page: number): Promise<{ info: AuctionInfo; auctions: Auction[] }> { - const res = await this.client.requests.request(`/skyblock/auctions?page=${page}`, this.options); + const res = await this.client.requestHandler.request(`/skyblock/auctions?page=${page}`, this.options); return { info: new AuctionInfo(res.data), auctions: res.data.auctions.map((a: any) => new Auction(a)) diff --git a/src/API/getSkyblockAuctionsByPlayer.ts b/src/API/getSkyblockAuctionsByPlayer.ts index e6a3823d..7aa9611f 100644 --- a/src/API/getSkyblockAuctionsByPlayer.ts +++ b/src/API/getSkyblockAuctionsByPlayer.ts @@ -12,8 +12,8 @@ class getSkyblockActionsByPlayer extends Endpoint { async execute(query: string, options?: AuctionRequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); - query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/skyblock/auction?player=${query}`); + query = await this.client.requestHandler.toUUID(query); + const res = await this.client.requestHandler.request(`/skyblock/auction?player=${query}`); if (res.options.raw) return res.data; return res.data.auctions.map((a: any) => new Auction(a, options?.includeItemBytes ?? false)); } diff --git a/src/API/getSkyblockBazaar.ts b/src/API/getSkyblockBazaar.ts index 41452f5e..2747b1ba 100644 --- a/src/API/getSkyblockBazaar.ts +++ b/src/API/getSkyblockBazaar.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import Product from '../structures/SkyBlock/Bazzar/Product'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getSkyblockBazaar extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getSkyblockBazaar extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/skyblock/bazaar', options); + const res = await this.client.requestHandler.request('/skyblock/bazaar', options); if (res.options.raw) return res.data; return Object.keys(res.data.products).map((x) => new Product(res.data.products[x])); } diff --git a/src/API/getSkyblockBingo.ts b/src/API/getSkyblockBingo.ts index 137618a3..60317674 100644 --- a/src/API/getSkyblockBingo.ts +++ b/src/API/getSkyblockBingo.ts @@ -1,7 +1,7 @@ import BingoData from '../structures/SkyBlock/Static/BingoData'; import Client from '../Client'; import Endpoint from '../Private/Endpoint'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getSkyblockBingo extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getSkyblockBingo extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/resources/skyblock/bingo', options); + const res = await this.client.requestHandler.request('/resources/skyblock/bingo', options); if (res.options.raw) return res.data; return new BingoData(res.data); } diff --git a/src/API/getSkyblockFireSales.ts b/src/API/getSkyblockFireSales.ts index fa4a1e73..788e8ae0 100644 --- a/src/API/getSkyblockFireSales.ts +++ b/src/API/getSkyblockFireSales.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import FireSale from '../structures/SkyBlock/Static/FireSale'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getSkyblockFireSales extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getSkyblockFireSales extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/skyblock/firesales', options); + const res = await this.client.requestHandler.request('/skyblock/firesales', options); if (res.options.raw) return res.data; return res.data.sales.map((a: any) => new FireSale(a)); } diff --git a/src/API/getSkyblockGarden.ts b/src/API/getSkyblockGarden.ts index 05b7ad9c..0a32f60b 100644 --- a/src/API/getSkyblockGarden.ts +++ b/src/API/getSkyblockGarden.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import SkyblockGarden from '../structures/SkyBlock/SkyblockGarden'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getSkyblockGarden extends Endpoint { readonly client: Client; @@ -12,7 +12,7 @@ class getSkyblockGarden extends Endpoint { async execute(profileId: string, options?: RequestOptions): Promise { if (!profileId) throw new Error(this.client.errors.NO_UUID); - const res = await this.client.requests.request(`/skyblock/garden?profile=${profileId}`, options); + const res = await this.client.requestHandler.request(`/skyblock/garden?profile=${profileId}`, options); if (res.options.raw) return res.data; return new SkyblockGarden(res.data); } diff --git a/src/API/getSkyblockGovernment.ts b/src/API/getSkyblockGovernment.ts index f9093623..8f89caf7 100644 --- a/src/API/getSkyblockGovernment.ts +++ b/src/API/getSkyblockGovernment.ts @@ -1,7 +1,7 @@ import Client from '../Client.js'; import Endpoint from '../Private/Endpoint.js'; import GovernmentData from '../structures/SkyBlock/Static/Government.js'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler.js'; class getSkyblockGovernment extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getSkyblockGovernment extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/resources/skyblock/election', options); + const res = await this.client.requestHandler.request('/resources/skyblock/election', options); if (res.options.raw) return res.data; return new GovernmentData(res.data); } diff --git a/src/API/getSkyblockMember.ts b/src/API/getSkyblockMember.ts index dee02463..8b174288 100644 --- a/src/API/getSkyblockMember.ts +++ b/src/API/getSkyblockMember.ts @@ -12,8 +12,8 @@ class getSkyblockMember extends Endpoint { async execute(query: string, options?: SkyblockRequestOptions): Promise> { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); - query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/skyblock/profiles?uuid=${query}`, options); + query = await this.client.requestHandler.toUUID(query); + const res = await this.client.requestHandler.request(`/skyblock/profiles?uuid=${query}`, options); if (res.options.raw) return res.data; if (!res.data.profiles || !res.data.profiles.length) throw new Error(this.client.errors.NO_SKYBLOCK_PROFILES); const memberByProfileName = new Map(); diff --git a/src/API/getSkyblockMuseum.ts b/src/API/getSkyblockMuseum.ts index d2802041..58d8bfc1 100644 --- a/src/API/getSkyblockMuseum.ts +++ b/src/API/getSkyblockMuseum.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import SkyblockMuseum from '../structures/SkyBlock/SkyblockMuseum'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getSkyblockMuseum extends Endpoint { readonly client: Client; @@ -12,8 +12,11 @@ class getSkyblockMuseum extends Endpoint { async execute(query: string, profileId: string, options?: RequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); - query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/skyblock/museum?uuid=${query}&profile=${profileId}`, options); + query = await this.client.requestHandler.toUUID(query); + const res = await this.client.requestHandler.request( + `/skyblock/museum?uuid=${query}&profile=${profileId}`, + options + ); if (res.options.raw) return res.data; return new SkyblockMuseum({ uuid: query, m: res.data, profileId: profileId }); } diff --git a/src/API/getSkyblockNews.ts b/src/API/getSkyblockNews.ts index 681bc209..5aa298f7 100644 --- a/src/API/getSkyblockNews.ts +++ b/src/API/getSkyblockNews.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import SkyblockNews from '../structures/SkyBlock/News/SkyblockNews'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getSkyblockNews extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getSkyblockNews extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/skyblock/news', options); + const res = await this.client.requestHandler.request('/skyblock/news', options); if (res.options.raw) return res.data; return res.data.items.map((i: any) => new SkyblockNews(i)); } diff --git a/src/API/getSkyblockProfiles.ts b/src/API/getSkyblockProfiles.ts index 887c676d..e10d384f 100644 --- a/src/API/getSkyblockProfiles.ts +++ b/src/API/getSkyblockProfiles.ts @@ -12,8 +12,8 @@ class getSkyblockProfiles extends Endpoint { async execute(query: string, options?: SkyblockRequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); - query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/skyblock/profiles?uuid=${query}`, options); + query = await this.client.requestHandler.toUUID(query); + const res = await this.client.requestHandler.request(`/skyblock/profiles?uuid=${query}`, options); if (res.options.raw) return res.data; if (!res.data.profiles || !res.data.profiles.length) throw new Error(this.client.errors.NO_SKYBLOCK_PROFILES); const profiles = []; diff --git a/src/API/getStatus.ts b/src/API/getStatus.ts index ef24f4df..12d179d9 100644 --- a/src/API/getStatus.ts +++ b/src/API/getStatus.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import Status from '../structures/Status'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getStatus extends Endpoint { readonly client: Client; @@ -11,8 +11,8 @@ class getStatus extends Endpoint { } async execute(query: string, options?: RequestOptions): Promise { - query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/status?uuid=${query}`, options); + query = await this.client.requestHandler.toUUID(query); + const res = await this.client.requestHandler.request(`/status?uuid=${query}`, options); if (res.options.raw) return res.data; return new Status(res.data.session); } diff --git a/src/API/getWatchdogStats.ts b/src/API/getWatchdogStats.ts index 237156d6..ba734934 100644 --- a/src/API/getWatchdogStats.ts +++ b/src/API/getWatchdogStats.ts @@ -1,7 +1,7 @@ import Client from '../Client'; import Endpoint from '../Private/Endpoint'; import WatchdogStats from '../structures/Watchdog/Stats'; -import { RequestOptions } from '../Private/Requests'; +import { RequestOptions } from '../Private/RequestHandler'; class getWatchdogStats extends Endpoint { readonly client: Client; @@ -11,7 +11,7 @@ class getWatchdogStats extends Endpoint { } async execute(options?: RequestOptions): Promise { - const res = await this.client.requests.request('/punishmentstats', options); + const res = await this.client.requestHandler.request('/punishmentstats', options); if (res.options.raw) return res.data; return new WatchdogStats(res.data); } diff --git a/src/Client.test.ts b/src/Client.test.ts index dd824daa..c0d3921c 100644 --- a/src/Client.test.ts +++ b/src/Client.test.ts @@ -1,7 +1,7 @@ import CacheHandler from './Private/CacheHandler'; import Client, { ClientOptions } from './Client'; import Errors from './Errors'; -import Requests from './Private/Requests'; +import RequestHandler from './Private/RequestHandler'; import Updater from './Private/Updater'; import { expect, expectTypeOf, test } from 'vitest'; const errors = new Errors(); @@ -55,9 +55,9 @@ test('Client (No Options)', () => { expectTypeOf(client.options.checkForUpdatesInterval).toEqualTypeOf(); expect(client.options.checkForUpdatesInterval).toBe(60); - expect(client.requests).toBeDefined(); - expect(client.requests).toBeInstanceOf(Requests); - expectTypeOf(client.requests).toEqualTypeOf(); + expect(client.requestHandler).toBeDefined(); + expect(client.requestHandler).toBeInstanceOf(RequestHandler); + expectTypeOf(client.requestHandler).toEqualTypeOf(); expect(client.cacheHandler).toBeDefined(); expect(client.cacheHandler).toBeInstanceOf(CacheHandler); @@ -128,9 +128,9 @@ test('Client (Options)', () => { expectTypeOf(client.options.checkForUpdatesInterval).toEqualTypeOf(); expect(client.options.checkForUpdatesInterval).toBe(120); - expect(client.requests).toBeDefined(); - expect(client.requests).toBeInstanceOf(Requests); - expectTypeOf(client.requests).toEqualTypeOf(); + expect(client.requestHandler).toBeDefined(); + expect(client.requestHandler).toBeInstanceOf(RequestHandler); + expectTypeOf(client.requestHandler).toEqualTypeOf(); expect(client.cacheHandler).toBeDefined(); expect(client.cacheHandler).toBeInstanceOf(CacheHandler); diff --git a/src/Client.ts b/src/Client.ts index 33365fb0..068dd6d4 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -2,7 +2,7 @@ import API from './API'; import CacheHandler from './Private/CacheHandler'; import Errors from './Errors'; import RateLimit from './Private/RateLimit'; -import Requests from './Private/Requests'; +import RequestHandler from './Private/RequestHandler'; import Updater from './Private/Updater'; export interface ClientOptions { @@ -20,7 +20,7 @@ const clients: Client[] = []; class Client { declare options: ClientOptions; - declare requests: Requests; + declare requestHandler: RequestHandler; declare cacheHandler: CacheHandler; declare updater: Updater; declare errors: Errors; @@ -32,7 +32,7 @@ class Client { this.errors = new Errors(); if (!this.key.length) throw new Error(this.errors.NO_API_KEY); this.options = this.parasOptions(options); - this.requests = new Requests(this); + this.requestHandler = new RequestHandler(this); this.cacheHandler = new CacheHandler(this); this.updater = new Updater(this); this.rateLimit = new RateLimit(this); diff --git a/src/Private/RateLimit.ts b/src/Private/RateLimit.ts index 3faaa164..8344f603 100644 --- a/src/Private/RateLimit.ts +++ b/src/Private/RateLimit.ts @@ -15,7 +15,7 @@ class RateLimit { } async sync() { - const { headers } = await this.client.requests.request('/boosters', { raw: true }); + const { headers } = await this.client.requestHandler.request('/boosters', { raw: true }); if (headers?.['ratelimit-limit'] === undefined || headers?.['ratelimit-remaining'] === undefined) { throw new Error(this.client.errors.RATE_LIMIT_INIT_ERROR); } diff --git a/src/Private/Requests.ts b/src/Private/RequestHandler.ts similarity index 100% rename from src/Private/Requests.ts rename to src/Private/RequestHandler.ts diff --git a/src/index.ts b/src/index.ts index 9f1214e7..3616402f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +/* v8 ignore next 200 */ export * from './API/getAchievements'; export * from './API/getActiveHouses'; export * from './API/getBoosters'; @@ -29,7 +30,7 @@ export * from './API/getWatchdogStats'; export * from './Private/CacheHandler'; export * from './Private/Endpoint'; export * from './Private/RateLimit'; -export * from './Private/Requests'; +export * from './Private/RequestHandler'; export * from './Private/Updater'; export * from './structures/Boosters/Booster';