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

feat: i know how to use optional arguments

This commit is contained in:
James Cook 2021-11-23 22:23:23 +00:00
parent d0ed8b1cd7
commit 0f8f0a5027
23 changed files with 110 additions and 82 deletions

View file

@ -1 +0,0 @@
release.js

View file

@ -1,22 +1,71 @@
:root {
--light-hl-0: #AF00DB;
--dark-hl-0: #C586C0;
--light-hl-1: #000000;
--dark-hl-1: #D4D4D4;
--light-hl-2: #001080;
--dark-hl-2: #9CDCFE;
--light-hl-3: #A31515;
--dark-hl-3: #CE9178;
--light-hl-4: #0000FF;
--dark-hl-4: #569CD6;
--light-hl-5: #795E26;
--dark-hl-5: #DCDCAA;
--light-hl-6: #0070C1;
--dark-hl-6: #4FC1FF;
--light-code-background: #FFFFFF;
--dark-code-background: #1E1E1E;
}
@media (prefers-color-scheme: light) { :root {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--code-background: var(--light-code-background);
} }
@media (prefers-color-scheme: dark) { :root {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--code-background: var(--dark-code-background);
} }
body.light {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--code-background: var(--light-code-background);
}
body.dark {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--code-background: var(--dark-code-background);
}
.hl-0 { color: var(--hl-0); }
.hl-1 { color: var(--hl-1); }
.hl-2 { color: var(--hl-2); }
.hl-3 { color: var(--hl-3); }
.hl-4 { color: var(--hl-4); }
.hl-5 { color: var(--hl-5); }
.hl-6 { color: var(--hl-6); }
pre, code { background: var(--code-background); }

File diff suppressed because one or more lines are too long

View file

@ -3,4 +3,11 @@
<h1>Classcharts API</h1>
</a>
<p>A very WIP client for the classcharts API</p>
<p><a href="https://jamesatjaminit.github.io/classcharts-api/index.html">Documentation</a></p>
<a href="#examples" id="examples" style="color: inherit; text-decoration: none;">
<h1>Examples</h1>
</a>
<pre><code class="language-typescript"><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">ClasschartsClient</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&#39;classcharts-api&#39;</span><br/><span class="hl-4">async</span><span class="hl-1"> </span><span class="hl-4">function</span><span class="hl-1"> </span><span class="hl-5">main</span><span class="hl-1">() {</span><br/><span class="hl-1"> </span><span class="hl-4">const</span><span class="hl-1"> </span><span class="hl-6">client</span><span class="hl-1"> = </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-5">ClasschartsClient</span><span class="hl-1">(</span><span class="hl-3">&#39;classchartsCode&#39;</span><span class="hl-1">, </span><span class="hl-3">&#39;01/1/2000&#39;</span><span class="hl-1">)</span><br/><span class="hl-1"> </span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">client</span><span class="hl-1">.</span><span class="hl-5">init</span><span class="hl-1">()</span><br/><span class="hl-1"> </span><span class="hl-2">console</span><span class="hl-1">.</span><span class="hl-5">log</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">client</span><span class="hl-1">.</span><span class="hl-5">getBehaviour</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">displayDate:</span><span class="hl-1"> </span><span class="hl-3">&#39;due_date&#39;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">fromDate:</span><span class="hl-1"> </span><span class="hl-3">&#39;20/01/2000&#39;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">toDate:</span><span class="hl-1"> </span><span class="hl-3">&#39;01/02/2000&#39;</span><span class="hl-1">,</span><br/><span class="hl-1"> })</span><br/><span class="hl-1"> )</span><br/><span class="hl-1"> </span><span class="hl-2">console</span><span class="hl-1">.</span><span class="hl-5">log</span><span class="hl-1">(</span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">client</span><span class="hl-1">.</span><span class="hl-5">getActivity</span><span class="hl-1">(</span><span class="hl-4">null</span><span class="hl-1">))</span><br/><span class="hl-1"> </span><span class="hl-2">console</span><span class="hl-1">.</span><span class="hl-5">log</span><span class="hl-1">(</span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">client</span><span class="hl-1">.</span><span class="hl-5">getStudentInfo</span><span class="hl-1">())</span><br/><span class="hl-1"> </span><span class="hl-2">console</span><span class="hl-1">.</span><span class="hl-5">log</span><span class="hl-1">(</span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">client</span><span class="hl-1">.</span><span class="hl-5">getActivity</span><span class="hl-1">(</span><span class="hl-4">null</span><span class="hl-1">))</span><br/><span class="hl-1"> </span><span class="hl-2">console</span><span class="hl-1">.</span><span class="hl-5">log</span><span class="hl-1">(</span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">client</span><span class="hl-1">.</span><span class="hl-5">getActivity</span><span class="hl-1">(</span><span class="hl-4">null</span><span class="hl-1">))</span><br/><span class="hl-1">}</span><br/><br/><span class="hl-5">main</span><span class="hl-1">()</span>
</code></pre>
</div></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class="current"><a href="modules.html">Modules</a></li><li class=" tsd-kind-module"><a href="modules/api.html">api</a></li><li class=" tsd-kind-module"><a href="modules/client.html">client</a></li><li class=" tsd-kind-module"><a href="modules/consts.html">consts</a></li><li class=" tsd-kind-module"><a href="modules/index.html">index</a></li><li class=" tsd-kind-module"><a href="modules/types.html">types</a></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li><li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li><li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="assets/main.js"></script></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -5,9 +5,8 @@
"repository": {
"url": "https://github.com/jamesatjaminit/classcharts-api"
},
"main": "./index.js",
"main": "./dist/index.js",
"scripts": {
"buildReady": "pnpm tsc && node dist/release.js",
"generateDocs": "pnpm typedoc --entryPointStrategy expand ./src"
},
"author": "",
@ -15,10 +14,13 @@
"dependencies": {
"undici": "^4.9.2"
},
"files": [
"dist/**"
],
"devDependencies": {
"@types/node": "^16.11.6",
"typedoc": "^0.22.7",
"typescript": "^4.4.4"
},
"types": "./types.d.ts"
"types": "./dist/index.d.ts"
}

View file

@ -16,39 +16,39 @@ import {
} from './types'
export async function getStudentInfo(
studentCode: string,
dateOfBirth: string | null
dateOfBirth?: string
): Promise<Student> {
const client = new ClasschartsClient(studentCode, dateOfBirth)
return await client.getStudentInfo()
}
export async function getActivity(
studentCode: string,
dateOfBirth: string | null,
options: GetActivityOptions | null
dateOfBirth?: string,
options?: GetActivityOptions
): Promise<ActivityResponse> {
const client = new ClasschartsClient(studentCode, dateOfBirth)
return await client.getActivity(options)
}
export async function getBehaviour(
studentCode: string,
dateOfBirth: string | null,
options: GetBehaviourOptions | null
dateOfBirth?: string,
options?: GetBehaviourOptions
): Promise<BehaviourResponse> {
const client = new ClasschartsClient(studentCode, dateOfBirth)
return await client.getBehaviour(options)
}
export async function listHomeworks(
studentCode: string,
dateOfBirth: string | null,
options: GetHomeworkOptions | null
dateOfBirth?: string,
options?: GetHomeworkOptions
): Promise<HomeworksResponse> {
const client = new ClasschartsClient(studentCode, dateOfBirth)
return await client.listHomeworks(options)
}
export async function getLessons(
studentCode: string,
dateOfBirth: string | null,
options: GetLessonsOptions
dateOfBirth?: string,
options?: GetLessonsOptions
): Promise<LessonsResponse> {
const client = new ClasschartsClient(studentCode, dateOfBirth)
return await client.getLessons(options)

View file

@ -28,7 +28,7 @@ export class ClasschartsClient {
* @param studentCode Classcharts student code
* @param dateOfBirth Student's date of birth
*/
constructor(studentCode: string, dateOfBirth: string) {
constructor(studentCode: string, dateOfBirth?: string) {
this.studentCode = String(studentCode)
this.dateOfBirth = String(dateOfBirth)
}
@ -110,7 +110,7 @@ export class ClasschartsClient {
* @returns Activity data
*/
async getActivity(
options: GetActivityOptions | null
options?: GetActivityOptions
): Promise<ActivityResponse> {
const params = new URLSearchParams()
options?.from && params.append('form', options?.from)
@ -128,7 +128,7 @@ export class ClasschartsClient {
* @returns Array of behaviour points
*/
async getBehaviour(
options: GetBehaviourOptions | null
options?: GetBehaviourOptions
): Promise<BehaviourResponse> {
const params = new URLSearchParams()
options?.from && params.append('form', options?.from)
@ -147,7 +147,7 @@ export class ClasschartsClient {
* @returns Array of homeworks
*/
async listHomeworks(
options: GetHomeworkOptions | null
options?: GetHomeworkOptions
): Promise<HomeworksResponse> {
if (!this.authCookies) throw new Error('Not authenticated')
const params = new URLSearchParams()
@ -176,7 +176,7 @@ export class ClasschartsClient {
* @param options GetLessonsOptions
* @returns Array of lessons
*/
async getLessons(options: GetLessonsOptions): Promise<LessonsResponse> {
async getLessons(options?: GetLessonsOptions): Promise<LessonsResponse> {
if (!this.authCookies) throw new Error('Not authenticated')
if (!options?.date) throw new Error('No date specified')
const params = new URLSearchParams()

View file

@ -1,29 +0,0 @@
import fs from 'fs'
// DO NOT DELETE THIS FILE
// This file is used by build system to build a clean npm package with the compiled js files in the root of the package.
// It will not be included in the npm package.
function main() {
const source = fs
.readFileSync(__dirname + '/../package.json')
.toString('utf-8')
const sourceObj = JSON.parse(source)
sourceObj.scripts = {}
sourceObj.devDependencies = {}
if (sourceObj.main.startsWith('dist/')) {
sourceObj.main = sourceObj.main.slice(5)
}
fs.writeFileSync(
__dirname + '/package.json',
Buffer.from(JSON.stringify(sourceObj, null, 2), 'utf-8')
)
fs.writeFileSync(
__dirname + '/version.txt',
Buffer.from(sourceObj.version, 'utf-8')
)
fs.copyFileSync(__dirname + '/../.npmignore', __dirname + '/.npmignore')
fs.copyFileSync(__dirname + '/../README.MD', __dirname + '/README.MD')
}
main()

View file

@ -1,10 +1,10 @@
import { ClasschartsClient } from '../client'
const { code, dob } = require('../../src/tests/config.json')
async function main() {
const client = new ClasschartsClient(code, dob)
await client.init()
console.log(await client.getBehaviour(null))
console.log(await client.getActivity(null))
const client = new ClasschartsClient(code, dob)
await client.init()
console.log(await client.getBehaviour())
console.log(await client.getActivity())
}
main()

10
src/types.d.ts vendored
View file

@ -37,8 +37,8 @@ export interface Student {
detention_alias_plural_uc: string
}
export interface GetActivityOptions {
from: string | undefined
to: string | undefined
from?: string
to?: string
}
export interface ActivityTimelinePoint {
positive: number
@ -57,9 +57,9 @@ export interface ActivityResponse {
other_negative_count: Array<any>
}
export interface GetBehaviourOptions {
from: string | undefined
to: string | undefined
last_id: string | undefined
from?: string
to?: string
last_id?: string
}
export interface BehaviourPoint {
id: number