From 90e170b57749979069236cf994f237f3c7737c1e Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Mon, 15 Apr 2024 15:46:53 -0400 Subject: [PATCH] Add HttpMethod enum --- JS-SDK/src/index.ts | 1 + JS-SDK/src/lib/restfulmc.ts | 18 ++++++++++++++---- JS-SDK/src/lib/web-request.ts | 9 ++++++++- JS-SDK/src/types/http-method.ts | 6 ++++++ 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 JS-SDK/src/types/http-method.ts diff --git a/JS-SDK/src/index.ts b/JS-SDK/src/index.ts index d0d0b01..14cc270 100644 --- a/JS-SDK/src/index.ts +++ b/JS-SDK/src/index.ts @@ -3,6 +3,7 @@ export * from "@/lib/restfulmc"; // Types export * from "@/types/dns/record-type"; export * from "@/types/error"; +export * from "@/types/http-method"; export * from "@/types/mojang/server-status"; export * from "@/types/player/profile-action"; export * from "@/types/player/skin-model"; diff --git a/JS-SDK/src/lib/restfulmc.ts b/JS-SDK/src/lib/restfulmc.ts index c7e968d..37adcac 100644 --- a/JS-SDK/src/lib/restfulmc.ts +++ b/JS-SDK/src/lib/restfulmc.ts @@ -1,4 +1,5 @@ import { WebRequest } from "@/lib/web-request"; +import { HttpMethod } from "@/types/http-method"; import { MojangServerStatusResponse } from "@/types/mojang/server-status-response"; import { CachedPlayer } from "@/types/player/player"; import { SkinPart } from "@/types/player/skin-part"; @@ -13,7 +14,7 @@ import { ServerPlatform } from "@/types/server/platform"; * @returns the promised player */ export const getPlayer = (query: string): Promise => - new WebRequest(`/player/${query}`).execute(); + new WebRequest(HttpMethod.GET, `/player/${query}`).execute(); /** * Get the part of a skin texture for @@ -32,6 +33,7 @@ export const getSkinPart = ( size: number = 128 ): Promise => new WebRequest( + HttpMethod.GET, `/player/${part}/${query}.${extension}?size=${size}` ).execute(); @@ -48,9 +50,11 @@ export const getMinecraftServer = ( ): Promise => platform === ServerPlatform.JAVA ? new WebRequest( + HttpMethod.GET, `/server/${platform}/${hostname}` ).execute() : new WebRequest( + HttpMethod.GET, `/server/${platform}/${hostname}` ).execute(); @@ -62,7 +66,7 @@ export const getMinecraftServer = ( * @returns the promised blocked status */ export const isMojangBlocked = (hostname: string): Promise => - new WebRequest(`/server/blocked/${hostname}`) + new WebRequest(HttpMethod.GET, `/server/blocked/${hostname}`) .execute<{ blocked: boolean; }>() @@ -76,7 +80,10 @@ export const isMojangBlocked = (hostname: string): Promise => * @returns the primised server icon */ export const getJavaServerFavicon = (hostname: string): Promise => - new WebRequest(`/server/icon/${hostname}`).execute(); + new WebRequest( + HttpMethod.GET, + `/server/icon/${hostname}` + ).execute(); /** * Get the status of Mojang servers. @@ -84,4 +91,7 @@ export const getJavaServerFavicon = (hostname: string): Promise => * @returns the promised status */ export const getMojangServerStatus = (): Promise => - new WebRequest("/mojang/status").execute(); + new WebRequest( + HttpMethod.GET, + "/mojang/status" + ).execute(); diff --git a/JS-SDK/src/lib/web-request.ts b/JS-SDK/src/lib/web-request.ts index 02b64b4..aa9a6ec 100644 --- a/JS-SDK/src/lib/web-request.ts +++ b/JS-SDK/src/lib/web-request.ts @@ -1,4 +1,5 @@ import { RestfulMCAPIError } from "@/types/error"; +import { HttpMethod } from "@/types/http-method"; const API_ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use @@ -6,12 +7,18 @@ const API_ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use * Make a web request to the API. */ export class WebRequest { + /** + * The HTTP method to use. + */ + method: HttpMethod; + /** * The endpoint to make the request to. */ endpoint: string; - constructor(endpoint: string) { + constructor(method: HttpMethod, endpoint: string) { + this.method = method; this.endpoint = endpoint; } diff --git a/JS-SDK/src/types/http-method.ts b/JS-SDK/src/types/http-method.ts new file mode 100644 index 0000000..3cd8d41 --- /dev/null +++ b/JS-SDK/src/types/http-method.ts @@ -0,0 +1,6 @@ +/** + * Enum for HTTP methods. + */ +export enum HttpMethod { + GET = "GET", +}