mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
Add HTTP methods to RequestManager
This commit is contained in:
@@ -1,24 +1,38 @@
|
||||
import Client from "../module/Client.ts";
|
||||
import { RequestMethod } from "../types/fetch";
|
||||
|
||||
type RequestBody = string | Blob | ArrayBufferView | ArrayBuffer | FormData | URLSearchParams | null | undefined;
|
||||
|
||||
class RequestManager {
|
||||
client: Client;
|
||||
token: string;
|
||||
currentRatelimit
|
||||
|
||||
constructor(client: Client, token: string) {
|
||||
this.client = client
|
||||
this.token = token
|
||||
}
|
||||
|
||||
async get(url: string, payload?: unknown, shouldRatelimit = true) {
|
||||
if (shouldRatelimit) {
|
||||
|
||||
}
|
||||
async get(url: string) {
|
||||
const headers = this.getDiscordHeaders();
|
||||
console.log('payload', payload)
|
||||
|
||||
const data = await fetch(url, { headers }).then(res => res.json())
|
||||
return data
|
||||
return fetch(url, { headers }).then(res => res.json())
|
||||
}
|
||||
|
||||
async post (url: string, body: RequestBody) {
|
||||
const headers = this.getDiscordHeaders();
|
||||
return fetch(url, {
|
||||
method: RequestMethod.Post,
|
||||
headers,
|
||||
body
|
||||
});
|
||||
}
|
||||
|
||||
async delete (url: string, body: RequestBody) {
|
||||
const headers = this.getDiscordHeaders();
|
||||
return fetch(url, {
|
||||
method: RequestMethod.Delete,
|
||||
headers,
|
||||
body
|
||||
});
|
||||
}
|
||||
|
||||
// The Record type here plays nice with Deno's `fetch.headers` expected type.
|
||||
|
||||
Reference in New Issue
Block a user