1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 19:59:37 +00:00
classcharts-api-js/README.md

395 lines
7.2 KiB
Markdown
Raw Normal View History

2023-05-04 21:56:19 +01:00
<p align="center">
<h1 align="center">ClassCharts API JS</h1>
<p align="center">
2023-08-30 13:35:37 +01:00
A Node.js and Deno wrapper for getting information from the Classcharts API.
2023-05-04 21:56:19 +01:00
</p>
</p>
<p align="center">
<a href="https://github.com/classchartsapi/classcharts-api-js">Source</a>
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://github.com/classchartsapi/classcharts-api-js/issues">Issues</a>
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://www.npmjs.com/package/classcharts-api">NPM</a>
2023-08-30 13:09:14 +01:00
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://deno.land/x/classcharts_api">Deno</a>
2023-05-04 21:56:19 +01:00
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://discord.gg/DTcwugcgZ2">Discord</a>
2023-09-03 16:49:56 +01:00
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://classchartsapi.github.io/classcharts-api-js">Library Docs</a>
2023-05-04 21:56:19 +01:00
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://classchartsapi.github.io/api-docs/">API Docs</a>
</p>
# Introduction
2023-08-30 12:28:49 +01:00
The ClassCharts API is a typescript wrapper around the ClassCharts API. It
allows you to easily make requests to the ClassCharts API without having to
worry about the underlying implementation of making requests.
2023-05-04 21:56:19 +01:00
## Help
2023-08-30 12:28:49 +01:00
For any help with the library, please join the
[discord](https://discord.gg/DTcwugcgZ2) where you can ask questions and get
help from the community.
2023-05-04 21:56:19 +01:00
2023-08-30 16:00:24 +01:00
# Contributing
Contributions are welcome! There are lots of API endpoints which we simply do
not have access to to implement, so if you have access to them, please consider
contributing! If you have any questions, feel free to ask in the
[discord](https://discord.gg/DTcwugcgZ2).
2023-05-04 21:56:19 +01:00
# Installation
## Requirements
2024-03-27 22:23:21 +00:00
- Node.js 20 or newer\
2023-09-08 19:27:19 +01:00
OR
2023-08-30 13:09:14 +01:00
- Deno
2023-05-04 21:56:19 +01:00
## NPM
```bash
npm install classcharts-api
2023-05-04 22:39:55 +01:00
```
2023-08-30 13:09:14 +01:00
## Deno
2023-05-04 22:39:55 +01:00
2023-08-30 13:09:14 +01:00
The imports in the examples are for Node.js, but can easily be substituted for
Deno.
```typescript
import {
ParentClient,
StudentClient,
} from "https://deno.land/x/classcharts_api/mod.ts";
2023-05-04 21:56:19 +01:00
```
# Logging In
2023-08-30 12:28:49 +01:00
Before making any requests, you must login to the client. This will get you a
session ID which will be used for all requests.
2023-05-04 21:56:19 +01:00
## Student Client
```typescript
2023-08-30 13:35:37 +01:00
import { StudentClient } from "classcharts-api";
2023-05-04 21:56:19 +01:00
// Date of birth MUST in the format DD/MM/YYYY
const client = new StudentClient("classchartsCode", "01/01/2000");
2023-05-04 21:56:19 +01:00
await client.login();
```
## Parent Client
?> The parent client is not tested, as I do not have access to a parent account.
If you experience any issues, please open an issue or PR.
2023-05-04 21:56:19 +01:00
```typescript
import { ParentClient } from "classcharts-api";
const client = new ParentClient("username", "password");
await client.login();
```
# Universal Methods
2023-08-30 12:28:49 +01:00
All the following methods can be used on both the student and parent client.
Each example expects the client to be already logged in.
2023-05-04 21:56:19 +01:00
## `.getStudentInfo`
```typescript
const studentInfo = await client.getStudentInfo();
console.log(studentInfo);
/**
{
success: 1,
data: {
user: {
id: 2339528,
...
}
},
meta: {
session_id: '5vf2v7n5uk9jftrxaarrik39vk6yjm48',
...
}
}
*/
```
## `.getActivity`
```typescript
// Dates must be in format YYYY-MM-DD
const activity = await client.getActivity({
from: "2023-04-01",
to: "2023-05-10",
last_id: "12",
});
console.log(activity);
```
## `.getFullActivity`
```typescript
// Dates must be in format YYYY-MM-DD
const activity = await client.getFullActivity({
from: "2023-04-01",
to: "2023-05-10",
});
console.log(activity);
```
## `.getBehaviour`
Gets behaviour for a given date range.
```typescript
// Dates must be in format YYYY-MM-DD
const behaviour = await client.getBehaviour({
from: "2023-04-01",
to: "2023-05-10",
});
console.log(behaviour);
/**
{
"success": 1,
"data": {
"timeline": [
{
"positive": 426,
...
},
],
...
"meta": {
"start_date": "2023-04-01T00:00:00+00:00",
...
}
}
*/
```
## `.getHomeworks`
Gets homeworks for a given date range.
```typescript
// Dates must be in format YYYY-MM-DD
const homeworks = await client.getHomeworks({
from: "2023-04-01",
to: "2023-05-10",
displayDate: 'issue_date' // Can be 'due_date' or 'issue_date'
});
console.log(homeworks);
/**
{
success: 1,
data: [
{
lesson: '7A/Pe1',
...
},
],
meta: {
start_date: '2023-04-01T00:00:00+00:00',
...
}
}
```
## `.getLessons`
Gets lessons for a specific date.
```typescript
// Dates must be in format YYYY-MM-DD
const lessons = await client.getLessons({
date: "2023-04-01",
});
console.log(lessons);
/**
{
"success": 1,
"data": [
{
"teacher_name": "Mr J Doe",
...
}
...
],
"meta": {
"dates": [
"2023-05-04"
],
...
}
}
*/
```
## `.getBadges`
Gets all earned badges.
```typescript
const badges = await client.getBadges();
console.log(badges);
/**
{
success: 1,
data: [
{
id: 123,
name: 'Big Badge',
...
},
...
],
meta: []
}
*/
```
## `.getAnnouncements`
Gets all announcements.
```typescript
const announcements = await client.getAnnouncements();
console.log(announcements);
2023-09-14 19:54:48 +01:00
/**
{
success: 1,
data: [
{
id: 321453,
title: "A big announcement",
description: "<p>School will be closing early today!</p>",
...
}
],
meta: []
}
*/
2023-05-04 21:56:19 +01:00
```
## `.getDetentions`
2023-08-30 12:28:49 +01:00
?> This method does not include `meta` in the response, since I do not have
access to this endpoint to test it. If you have access to this endpoint, please
open a PR to add the `meta` response. Thanks!
2023-05-04 22:39:55 +01:00
2023-05-04 21:56:19 +01:00
Gets all detentions.
```typescript
const detentions = await client.getDetentions();
console.log(detentions);
/**
{
"success": 1,
"data": [
{
"id": 12345678,
"attended": "no",
"date": "2024-03-28T00:00:00+00:00",
...
}
],
"meta": {
"detention_alias_plural": "detentions"
}
}
*/
2023-05-04 21:56:19 +01:00
```
## `.getAttendance`
2023-08-30 12:28:49 +01:00
?> This method does not include `meta` in the response, since I do not have
access to this endpoint to test it. If you have access to this endpoint, please
open a PR to add the `meta` response. Thanks!
2023-05-04 22:39:55 +01:00
2023-05-04 21:56:19 +01:00
Gets attendance.
```typescript
const attendance = await client.getAttendance();
console.log(attendance);
```
# Parent Specific Methods
## `.getPupils`
Gets a list of all pupils the parent has access to.
```typescript
const pupils = await client.getPupils();
console.log(pupils);
/**
[
{
id: 123,
name: 'John Doe',
...
},
...
]
*/
```
## `.selectPupil`
Selects a pupil to make subsequent requests for.
```typescript
await client.selectPupil(123);
```
2026-05-06 21:04:16 +01:00
## `.getHomeworksForPupil`
Gets homework for a specific pupil ID without permanently changing the selected pupil.
```typescript
const homework = await client.getHomeworksForPupil(123, {
from: "2026-05-01",
to: "2026-05-31",
displayDate: "due_date",
});
console.log(homework);
```
## `.getHomeworksForEachPupil`
Gets homework for each pupil ID. If no IDs are passed, it fetches for all attached pupils.
```typescript
const allHomework = await client.getHomeworksForEachPupil({
from: "2026-05-01",
to: "2026-05-31",
});
const selectedHomework = await client.getHomeworksForEachPupil(
{ displayDate: "issue_date" },
[123, 456],
);
console.log(allHomework[123]);
console.log(selectedHomework[456]);
```
## `.changePassword`
Changes the parent's password.
```typescript
await client.changePassword("oldPassword", "newPassword");
```