Skip to content

Commit

Permalink
βœ¨πŸ”–
Browse files Browse the repository at this point in the history
✨ - You can now change your State and the app that will be set in the request headers
πŸ”– - 2.1.0
  • Loading branch information
47PADO47 committed Mar 30, 2022
1 parent d016bdb commit e8d5214
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -15,9 +15,10 @@ A lightweight Node.js module for Classeviva / Spaggiari electronic register πŸ“š
## Example

```javascript
const { Classeviva } = require('classeviva.js');
const { Classeviva, Enums } = require('classeviva.js');

const classeviva = new Classeviva('USERNAME / EMAIL', 'PASSWORD');
const classeviva = new Classeviva('USERNAME / EMAIL', 'PASSWORD', Enums.States.Italy, Enums.Apps.Students);
//State and App are optional, they will be defaulted to Enums.States.Italy and Enums.Apps.Students if not set

(async () => {
await classeviva.login();
Expand Down
4 changes: 3 additions & 1 deletion index.ts
@@ -1 +1,3 @@
export { default as Classeviva } from './src/Classeviva';
export { default as Classeviva } from './src/Classeviva';

export { default as Enums } from './src/Enums';
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "classeviva.js",
"version": "2.0.2",
"version": "2.1.0",
"description": "A lightweight Node.js module for Classeviva / Spaggiari electronic register πŸ“š",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -16,7 +16,7 @@
"homepage": "https://github.com/47PADO47/Classeviva.js#readme",
"repository": {
"type": "git",
"url": "https://github.com/47PADO47/Classeviva.js.git"
"url": "git://github.com/47PADO47/Classeviva.js.git"
},
"dependencies": {
"node-fetch": "^2.6.7"
Expand Down
14 changes: 10 additions & 4 deletions src/Classeviva.ts
Expand Up @@ -2,12 +2,14 @@ import fetch, { BodyInit, HeadersInit, RequestInit, Response } from 'node-fetch'
import * as path from 'path';
import { readFileSync, writeFileSync } from 'fs';
import { User, Headers, FetchType, FetchMethod, FetchResponse, LoginResponse, AgendaFilter, TalkOptions, Overview } from './struct';
import * as Enums from './Enums';

class Classeviva {
public username: string;
readonly #password: string;
#token: string;

readonly #state: string;
readonly #baseUrl: string;
readonly #directory: string;

Expand All @@ -17,13 +19,15 @@ class Classeviva {
public authorized: boolean;
public user: User;

readonly #app : string;
#headers: Headers;
constructor(username?: string, password?: string) {
constructor(username?: string, password?: string, state: string = Enums.States.Italy, app: string = Enums.Apps.Students) {
this.username = username || "";
this.#password = password || "";
this.#token = "";

this.#baseUrl = "https://web.spaggiari.eu/rest/v1";
this.#state = state;
this.#baseUrl = `https://${Enums.Urls[this.#state]}/rest/v1`;
this.#directory = path.parse(__dirname).dir;

this.login_timeout;
Expand All @@ -36,11 +40,13 @@ class Classeviva {
id: "",
};

this.#app = app;
this.#headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "zorro/1.0",
"Z-Dev-ApiKey": "+zorro+",
"User-Agent": `${this.#app} iOS/15.4`,
"Z-Dev-Apikey": "Tg1NWEwNGIgIC0K",
"Z-If-None-Match": "",
};
};

Expand Down
41 changes: 41 additions & 0 deletions src/Enums.ts
@@ -0,0 +1,41 @@
export interface IStates {
Italy: string;
SanMarino: string;
Argentina: string;
};

export const States: Readonly<IStates> = Object.freeze({
Italy: "IT",
SanMarino: "SM",
Argentina: "AR",
});

export interface IApps {
Students: string;
Family: string;
Aant: string;
Teachers: string;
};

export const Apps: Readonly<IApps> = Object.freeze({
Students: "CVVS/studente/4.1.5",
Family: "CVVS/famiglia/4.1.5",
Aant: "CVVS/aant/2.1.2",
Teachers: "CVVS/docente/2.1.4",
});

export interface IUrls {
[key: string]: string;
};

export const Urls: Readonly<IUrls> = Object.freeze({
IT: "web.spaggiari.eu",
SM: "web.spaggiari.sm",
AR: "ar.spaggiari.eu",
});

export default {
States,
Apps,
Urls,
};

0 comments on commit e8d5214

Please sign in to comment.