mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 19:59:37 +00:00
feat: badges support
This commit is contained in:
parent
5fe9686a51
commit
b35dc528a6
3 changed files with 47 additions and 3 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
src/types.ts
30
src/types.ts
|
|
@ -150,3 +150,33 @@ export interface Lesson {
|
|||
pupil_note_raw: string;
|
||||
}
|
||||
export type LessonsResponse = Array<Lesson>;
|
||||
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<PupilEvent>;
|
||||
icon_url: string;
|
||||
}
|
||||
export type BadgesResponse = Array<Badge>;
|
||||
Loading…
Add table
Add a link
Reference in a new issue