1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 03:56:59 +00:00

feat: denoify (#33)

This commit is contained in:
James Cook 2023-08-30 12:28:49 +01:00 committed by GitHub
parent f2981dd167
commit f86ded2ae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 331 additions and 4940 deletions

View file

@ -1,6 +1,6 @@
import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.js";
import { BaseClient } from "./baseClient.js";
import { parseCookies } from "../utils/utils.js";
import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts";
import { BaseClient } from "./baseClient.ts";
import { parseCookies } from "../utils/utils.ts";
/**
* Student Client
@ -18,7 +18,6 @@ export class StudentClient extends BaseClient {
private dateOfBirth = "";
/**
*
* @param studentCode ClassCharts student code
* @param dateOfBirth Student's date of birth
*/
@ -32,7 +31,7 @@ export class StudentClient extends BaseClient {
* Authenticates with ClassCharts
*/
async login(): Promise<void> {
if (!this.studentCode) throw new Error("Student Code not inputted");
if (!this.studentCode) throw new Error("Student Code not provided");
const formData = new URLSearchParams();
formData.append("_method", "POST");
formData.append("code", this.studentCode.toUpperCase());
@ -43,14 +42,11 @@ export class StudentClient extends BaseClient {
method: "POST",
body: formData,
redirect: "manual",
credentials: undefined,
});
if (request.status != 302 || !request.headers.get("set-cookie")) {
await request.body?.cancel(); // Make deno tests happy by closing the body, unsure whether this is needed for the actual library
throw new Error(
"Unauthenticated: ClassCharts returned an error: " +
request.status +
" " +
request.statusText
"Unauthenticated: ClassCharts didn't return authentication cookies"
);
}
const cookies = String(request.headers.get("set-cookie"));