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

docs: improve code documentation

This commit is contained in:
James Cook 2024-05-28 14:07:34 +01:00
parent cb8e252a89
commit 6d0942afe4
3 changed files with 30 additions and 13 deletions

View file

@ -24,26 +24,27 @@ import { PING_INTERVAL } from "../utils/consts.ts";
*/ */
export abstract class BaseClient { export abstract class BaseClient {
/** /**
* @property studentId Currently selected student ID * Currently selected student ID
*/ */
public studentId = 0; 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[]; public authCookies: string[];
/** /**
* @property sessionId Session ID used for authentication * Session ID used for authentication
*/ */
public sessionId = ""; public sessionId = "";
/** /**
* @property lastPing Last time the sessionId was updated * Last time the sessionId was updated
*/ */
public lastPing = 0; 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 = ""; 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 * @param API_BASE Base API URL, this is different depending on if its called as a parent or student
*/ */
constructor(API_BASE: string) { constructor(API_BASE: string) {
@ -55,7 +56,7 @@ export abstract class BaseClient {
/** /**
* Revalidates the session ID. * 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() { public async getNewSessionId() {
const pingFormData = new URLSearchParams(); const pingFormData = new URLSearchParams();

View file

@ -4,12 +4,19 @@ import { BaseClient } from "../core/baseClient.ts";
import { API_BASE_PARENT, BASE_URL } from "../utils/consts.ts"; import { API_BASE_PARENT, BASE_URL } from "../utils/consts.ts";
import { parseCookies } from "../utils/utils.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 { export class ParentClient extends BaseClient {
private password = ""; private password = "";
private email = ""; private email = "";
// @ts-expect-error Init in .login
public pupils: GetPupilsResponse; public pupils: GetPupilsResponse;
/** /**
* @param email Parent's email address * @param email Parent's email address
@ -19,6 +26,7 @@ export class ParentClient extends BaseClient {
super(API_BASE_PARENT); super(API_BASE_PARENT);
this.email = String(email); this.email = String(email);
this.password = String(password); this.password = String(password);
this.pupils = [];
} }
/** /**

View file

@ -1,23 +1,31 @@
import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts"; import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts";
import { BaseClient } from "../core/baseClient.ts"; import { BaseClient } from "../core/baseClient.ts";
import { parseCookies } from "../utils/utils.ts"; import { parseCookies } from "../utils/utils.ts";
import { import type {
GetStudentCodeOptions, GetStudentCodeOptions,
GetStudentCodeResponse, GetStudentCodeResponse,
RewardPurchaseResponse, RewardPurchaseResponse,
RewardsResponse, RewardsResponse,
} from "../types.ts"; } 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 { export class StudentClient extends BaseClient {
/** /**
* @property studentCode ClassCharts student code * ClassCharts student code
*/ */
private studentCode = ""; private studentCode = "";
/** /**
* @property dateOfBirth Student's date of birth * Student's date of birth
*/ */
private dateOfBirth = ""; private dateOfBirth = "";