diff --git a/package.json b/package.json index 9c0ef5f..9f8ef5d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "main": "./dist/index.js", "scripts": { "build": "tsc", - "generateDocs": "pnpm typedoc --entryPointStrategy expand ./src" + "generateDocs": "pnpm typedoc --entryPointStrategy expand ./src", + "test": "echo do tests" }, "author": "", "license": "ISC", diff --git a/src/client.ts b/src/client.ts index 54ca268..1e0f6af 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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 { + async login(): Promise { 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 { + return await this.makeAuthedRequest( + API_BASE + "/eventbadges/" + this.studentId, + { + method: "GET", + } + ); + } } diff --git a/src/types.ts b/src/types.ts index be77578..44343a0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -150,3 +150,33 @@ export interface Lesson { pupil_note_raw: string; } export type LessonsResponse = Array; +export interface LessonPupilBehaviour { + // Not sure what to call this + reason: string; + score: number; + icon: string; + polarity: string; + timestamp: string; + teacher: { + title: string; + first_name: string; + last_name: string; + }; +} +export interface PupilEvent { + timestamp: string; + lesson_pupil_behaviour: LessonPupilBehaviour; + event: { + label: string; + }; +} +export interface Badge { + id: number; + name: string; + icon: string; + colour: string; + created_date: string; + pupil_badges: Array; + icon_url: string; +} +export type BadgesResponse = Array; \ No newline at end of file