From 6d0942afe4c675a0bf92f8c6dcfd6ba2ba493482 Mon Sep 17 00:00:00 2001 From: James Cook Date: Tue, 28 May 2024 14:07:34 +0100 Subject: [PATCH] docs: improve code documentation --- src/core/baseClient.ts | 13 +++++++------ src/core/parentClient.ts | 12 ++++++++++-- src/core/studentClient.ts | 18 +++++++++++++----- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/core/baseClient.ts b/src/core/baseClient.ts index e6034a3..0904128 100644 --- a/src/core/baseClient.ts +++ b/src/core/baseClient.ts @@ -24,26 +24,27 @@ import { PING_INTERVAL } from "../utils/consts.ts"; */ export abstract class BaseClient { /** - * @property studentId Currently selected student ID + * Currently selected student ID */ public studentId = 0; /** - * @property authCookies Cookies used for authentication (set during login and can be empty) + * Cookies used for authentication (set during login and can be empty) */ public authCookies: string[]; /** - * @property sessionId Session ID used for authentication + * Session ID used for authentication */ public sessionId = ""; /** - * @property lastPing Last time the sessionId was updated + * Last time the sessionId was updated */ public lastPing = 0; /** - * @property API_BASE Base API URL, this is different depending on if its called as a parent or student + * Base API URL, this is different depending on if its called as a parent or student */ protected API_BASE = ""; /** + * Create a new client with the given API url * @param API_BASE Base API URL, this is different depending on if its called as a parent or student */ constructor(API_BASE: string) { @@ -55,7 +56,7 @@ export abstract class BaseClient { /** * Revalidates the session ID. * - * This is called automatically when the session ID is older than 3 minutes or when initially using the .login() method + * This is called automatically when the session ID is older than 3 minutes and initially using the .login() method */ public async getNewSessionId() { const pingFormData = new URLSearchParams(); diff --git a/src/core/parentClient.ts b/src/core/parentClient.ts index b0a874b..7cc30a3 100644 --- a/src/core/parentClient.ts +++ b/src/core/parentClient.ts @@ -4,12 +4,19 @@ import { BaseClient } from "../core/baseClient.ts"; import { API_BASE_PARENT, BASE_URL } from "../utils/consts.ts"; import { parseCookies } from "../utils/utils.ts"; /** - * Parent Client + * Parent Client. + * See {@link BaseClient} for all shared methods. + * + * @example + * ```ts + * import { ParentClient } from "classcharts-api"; + * const client = new ParentClient("username", "password"); + * await client.login(); + * ``` */ export class ParentClient extends BaseClient { private password = ""; private email = ""; - // @ts-expect-error Init in .login public pupils: GetPupilsResponse; /** * @param email Parent's email address @@ -19,6 +26,7 @@ export class ParentClient extends BaseClient { super(API_BASE_PARENT); this.email = String(email); this.password = String(password); + this.pupils = []; } /** diff --git a/src/core/studentClient.ts b/src/core/studentClient.ts index db02a1c..9e61c43 100644 --- a/src/core/studentClient.ts +++ b/src/core/studentClient.ts @@ -1,23 +1,31 @@ import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts"; import { BaseClient } from "../core/baseClient.ts"; import { parseCookies } from "../utils/utils.ts"; -import { +import type { GetStudentCodeOptions, GetStudentCodeResponse, RewardPurchaseResponse, RewardsResponse, } from "../types.ts"; - /** - * Student Client + * Student Client. + * See {@link BaseClient} for all shared methods. + * + * @example + * ```ts + * import { StudentClient } from "classcharts-api"; + * // Date of birth MUST in the format DD/MM/YYYY + * const client = new StudentClient("classchartsCode", "01/01/2000"); + * await client.login(); + * ``` */ export class StudentClient extends BaseClient { /** - * @property studentCode ClassCharts student code + * ClassCharts student code */ private studentCode = ""; /** - * @property dateOfBirth Student's date of birth + * Student's date of birth */ private dateOfBirth = "";