mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 11:58:13 +00:00
feat: badges support
This commit is contained in:
parent
5fe9686a51
commit
b35dc528a6
3 changed files with 47 additions and 3 deletions
|
|
@ -2,6 +2,7 @@ import Undici from "undici";
|
|||
import { RequestOptions } from "undici/types/dispatcher";
|
||||
import {
|
||||
ActivityResponse,
|
||||
BadgesResponse,
|
||||
BehaviourResponse,
|
||||
GetActivityOptions,
|
||||
GetBehaviourOptions,
|
||||
|
|
@ -59,7 +60,7 @@ export class ClasschartsClient {
|
|||
/**
|
||||
* Initialises the client and authenticates with classcharts
|
||||
*/
|
||||
async init(): Promise<void> {
|
||||
async login(): Promise<void> {
|
||||
if (!this.studentCode) throw new Error("Student Code not inputted");
|
||||
const formData = new URLSearchParams();
|
||||
formData.append("_method", "POST");
|
||||
|
|
@ -80,7 +81,7 @@ export class ClasschartsClient {
|
|||
for (let i = 0; i < cookies.length; i++) {
|
||||
cookies[i] = cookies[i].substring(0, cookies[i].indexOf(";"));
|
||||
}
|
||||
this.authCookies = cookies
|
||||
this.authCookies = cookies;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let sessionID: any = decodeURI(cookies[2])
|
||||
.replace(/%3A/g, ":")
|
||||
|
|
@ -182,4 +183,16 @@ export class ClasschartsClient {
|
|||
}
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Gets a list of the students badges
|
||||
* @returns Array of badges
|
||||
*/
|
||||
async getBadges(): Promise<BadgesResponse> {
|
||||
return await this.makeAuthedRequest(
|
||||
API_BASE + "/eventbadges/" + this.studentId,
|
||||
{
|
||||
method: "GET",
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue