1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 11:58:13 +00:00

chore: deno badge & formatting

This commit is contained in:
James Cook 2023-08-30 13:43:25 +01:00
parent 55d91a52b7
commit 70c9d623fc
6 changed files with 26 additions and 25 deletions

View file

@ -1,10 +1,11 @@
<h1 align="center">Classcharts API JS</h1>
<div align="center">
<img alt="Discord" src="https://img.shields.io/discord/918103752068726855">
<img alt="npm" src="https://img.shields.io/npm/dm/classcharts-api">
<img alt="NPM" src="https://img.shields.io/npm/l/classcharts-api">
<img alt="license" src="https://img.shields.io/npm/l/classcharts-api">
<img alt="npm" src="https://img.shields.io/npm/v/classcharts-api">
<img alt="deno" src="https://shield.deno.dev/x/classcharts_api">
<img alt="node-current" src="https://img.shields.io/node/v/classcharts-api">
</div>
<p align="center">A Node.js and Deno wrapper for getting information from the Classcharts API.</p>

View file

@ -67,7 +67,7 @@ export class BaseClient {
method: "POST",
body: pingFormData,
},
{ revalidateToken: false }
{ revalidateToken: false },
);
this.sessionId = pingData.meta.session_id;
this.lastPing = Date.now();
@ -86,7 +86,7 @@ export class BaseClient {
public async makeAuthedRequest(
path: string,
fetchOptions: RequestInit,
options?: { revalidateToken?: boolean }
options?: { revalidateToken?: boolean },
) {
if (!this.sessionId) throw new Error("No session ID");
if (!options) {
@ -114,7 +114,7 @@ export class BaseClient {
responseJSON = await request.json();
} catch {
throw new Error(
"Error parsing JSON. Returned response: " + (await request.text())
"Error parsing JSON. Returned response: " + (await request.text()),
);
}
if (responseJSON.success == 0) {
@ -153,7 +153,7 @@ export class BaseClient {
this.API_BASE + "/activity/" + this.studentId + "?" + params.toString(),
{
method: "GET",
}
},
);
}
/**
@ -165,7 +165,7 @@ export class BaseClient {
* @see getActivity
*/
async getFullActivity(
options: GetFullActivityOptions
options: GetFullActivityOptions,
): Promise<ActivityResponse["data"]> {
let data: ActivityResponse["data"] = [];
let prevLast: number | undefined;
@ -194,7 +194,7 @@ export class BaseClient {
* @returns Array of behaviour points
*/
async getBehaviour(
options?: GetBehaviourOptions
options?: GetBehaviourOptions,
): Promise<BehaviourResponse> {
const params = new URLSearchParams();
options?.from && params.append("from", options?.from);
@ -203,7 +203,7 @@ export class BaseClient {
this.API_BASE + "/behaviour/" + this.studentId + "?" + params.toString(),
{
method: "GET",
}
},
);
}
/**
@ -223,7 +223,7 @@ export class BaseClient {
this.API_BASE + "/homeworks/" + this.studentId + "?" + params.toString(),
{
method: "GET",
}
},
);
for (let i = 0; i < data.data.length; i++) {
@ -231,11 +231,11 @@ export class BaseClient {
// homework.lesson.replace(/\\/g, '')
data.data[i].description = data.data[i].description.replace(
/(<([^>]+)>)/gi,
""
"",
);
data.data[i].description = data.data[i].description.replace(
/&nbsp;/g,
""
"",
);
data.data[i].description = data.data[i].description.trim();
}
@ -254,7 +254,7 @@ export class BaseClient {
this.API_BASE + "/timetable/" + this.studentId + "?" + params.toString(),
{
method: "GET",
}
},
);
}
/**
@ -266,7 +266,7 @@ export class BaseClient {
this.API_BASE + "/eventbadges/" + this.studentId,
{
method: "GET",
}
},
);
}
/**
@ -279,7 +279,7 @@ export class BaseClient {
this.API_BASE + "/announcements/" + this.studentId,
{
method: "GET",
}
},
)
).data;
}
@ -293,7 +293,7 @@ export class BaseClient {
this.API_BASE + "/detentions/" + this.studentId,
{
method: "GET",
}
},
)
).data;
}
@ -303,7 +303,7 @@ export class BaseClient {
* @returns Array of dates of attendance
*/
async getAttendance(
options?: GetAttendanceOptions
options?: GetAttendanceOptions,
): Promise<AttendanceResponse> {
const params = new URLSearchParams();
options?.from && params.append("from", options?.from);
@ -317,7 +317,7 @@ export class BaseClient {
params.toString(),
{
method: "GET",
}
},
)
).data;
}

View file

@ -46,7 +46,7 @@ export class ParentClient extends BaseClient {
"Unauthenticated: ClassCharts returned an error: " +
response.status +
" " +
response.statusText
response.statusText,
);
}
@ -54,7 +54,7 @@ export class ParentClient extends BaseClient {
// this.authCookies = cookies.split(";");
const sessionCookies = parseCookies(cookies);
const sessionID = JSON.parse(
String(sessionCookies["parent_session_credentials"])
String(sessionCookies["parent_session_credentials"]),
);
super.sessionId = sessionID.session_id;
this.pupils = await this.getPupils();

View file

@ -46,14 +46,14 @@ export class StudentClient extends BaseClient {
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 didn't return authentication cookies"
"Unauthenticated: ClassCharts didn't return authentication cookies",
);
}
const cookies = String(request.headers.get("set-cookie"));
this.authCookies = cookies.split(",");
const sessionCookies = parseCookies(cookies);
const sessionID = JSON.parse(
String(sessionCookies["student_session_credentials"])
String(sessionCookies["student_session_credentials"]),
);
this.sessionId = sessionID.session_id;
await this.getNewSessionId();

View file

@ -9,7 +9,7 @@ Deno.test("Throws when no student code is provided", async () => {
await client.login();
},
Error,
"Student Code not provided"
"Student Code not provided",
);
});
@ -20,6 +20,6 @@ Deno.test("Throws with invalid student code", async () => {
await client.login();
},
Error,
"Unauthenticated: ClassCharts didn't return authentication cookies"
"Unauthenticated: ClassCharts didn't return authentication cookies",
);
});

View file

@ -10,7 +10,7 @@ export function parseCookies(input: string) {
for (const cookie of cookies) {
const cookieSplit = cookie.split(";")[0].split("=");
output[leftTrim(decodeURIComponent(cookieSplit[0]))] = decodeURIComponent(
cookieSplit[1]
cookieSplit[1],
);
}
return output;