Add HTTP methods to RequestManager

This commit is contained in:
Will Hoskings
2020-02-11 18:24:36 +00:00
parent 269142165e
commit fa1dfc24bd

View File

@@ -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.