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

Commit

Permalink
Requests -> RequestHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Sep 3, 2024
1 parent 12f57b1 commit 6631a81
Show file tree
Hide file tree
Showing 33 changed files with 75 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/API/API.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RequestOptions } from '../Private/Requests';
import { RequestOptions } from '../Private/RequestHandler';

export interface PlayerRequestOptions extends RequestOptions {
guild?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/API/getAchievements.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getAchievements extends Endpoint {
}

async execute(options?: RequestOptions): Promise<Achievements> {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getActiveHouses.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getActiveHouses extends Endpoint {
}

async execute(options?: RequestOptions): Promise<House[]> {
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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getBoosters.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getBoosters extends Endpoint {
}

async execute(options?: RequestOptions): Promise<Booster[]> {
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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getChallenges.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getChallenges extends Endpoint {
}

async execute(options?: RequestOptions): Promise<Challenges> {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getGameCounts.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getGameCounts extends Endpoint {
}

async execute(options?: RequestOptions): Promise<GameCounts> {
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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/API/getGuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/API/getGuildAchievements.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getGuildAchievements extends Endpoint {
}

async execute(options?: RequestOptions): Promise<GuildAchievements> {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getHouse.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +12,7 @@ class getHouse extends Endpoint {

async execute(query: string, options?: RequestOptions): Promise<House> {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getLeaderboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,7 +12,7 @@ class getLeaderboards extends Endpoint {
}

async execute(options?: RequestOptions): Promise<any> {
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.'));
Expand Down
4 changes: 2 additions & 2 deletions src/API/getPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class getPlayer extends Endpoint {

async execute(query: string, options?: PlayerRequestOptions): Promise<Player> {
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, {
Expand Down
6 changes: 3 additions & 3 deletions src/API/getPlayerHouses.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,8 +12,8 @@ class getPlayerHouses extends Endpoint {

async execute(query: string, options?: RequestOptions): Promise<House[]> {
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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getQuests.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getQuests extends Endpoint {
}

async execute(options?: RequestOptions): Promise<Quests> {
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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/API/getRecentGames.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,8 +12,8 @@ class getRecentGames extends Endpoint {

async execute(query: string, options?: RequestOptions): Promise<RecentGame[]> {
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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getSkyblockAuction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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';
} else {
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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockAuctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/API/getSkyblockAuctionsByPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class getSkyblockActionsByPlayer extends Endpoint {

async execute(query: string, options?: AuctionRequestOptions): Promise<Auction[]> {
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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getSkyblockBazaar.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getSkyblockBazaar extends Endpoint {
}

async execute(options?: RequestOptions): Promise<Product[]> {
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]));
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getSkyblockBingo.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getSkyblockBingo extends Endpoint {
}

async execute(options?: RequestOptions): Promise<BingoData> {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getSkyblockFireSales.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getSkyblockFireSales extends Endpoint {
}

async execute(options?: RequestOptions): Promise<FireSale[]> {
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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getSkyblockGarden.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +12,7 @@ class getSkyblockGarden extends Endpoint {

async execute(profileId: string, options?: RequestOptions): Promise<SkyblockGarden> {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getSkyblockGovernment.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@ class getSkyblockGovernment extends Endpoint {
}

async execute(options?: RequestOptions): Promise<GovernmentData> {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/API/getSkyblockMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class getSkyblockMember extends Endpoint {

async execute(query: string, options?: SkyblockRequestOptions): Promise<Map<string, SkyblockMember>> {
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();
Expand Down
Loading

0 comments on commit 6631a81

Please sign in to comment.