Skip to content

Commit

Permalink
feat(client): add homepage and partner URL constants and wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Mar 31, 2024
1 parent 9fb6a28 commit 495d970
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/client/Pronote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ import { PronoteApiResourceType } from "~/constants/resources";
import { callApiUserCreateDiscussion } from "~/api/user/createDiscussion";
import { callApiUserCreateDiscussionMessage } from "~/api/user/createDiscussionMessage";
import { getPronoteMessageButtonType } from "~/pronote/messages";
import { callApiUserHomepage } from "~/api/user/homepage";
import { Partner } from "~/parser/partner";
import { callApiUserPartnerURL } from "~/api/user/partnerURL";

export default class Pronote {
/**
Expand Down Expand Up @@ -95,6 +98,8 @@ export default class Pronote {
*/
public nextTimeToken: string;

public nextOpenDate: Date;

/**
* Root URL of the Pronote instance.
*/
Expand Down Expand Up @@ -158,6 +163,7 @@ export default class Pronote {

this.username = credentials.username;
this.nextTimeToken = credentials.token;
this.nextOpenDate = readPronoteApiDate(loginInformations.donnees.General.JourOuvre.V);
this.pronoteRootURL = session.instance.pronote_url;
this.accountTypeID = session.instance.account_type_id;
this.sessionID = session.instance.session_id;
Expand Down Expand Up @@ -696,4 +702,35 @@ export default class Pronote {
});
});
}

public async getHomePage (nextOpenDate = this.nextOpenDate) {
return this.queue.push(async () => {
const response = await callApiUserHomepage(this.fetcher, {
session: this.session,
nextDateOpened: nextOpenDate,
weekNumber: translateToPronoteWeekNumber(nextOpenDate, this.firstMonday)
});

const ardSSO = response.data.donnees.partenaireARD?.SSO;

return {
ard: ardSSO ? new Partner(this, ardSSO) : null
};
});
}

public async getPartnerURL (partner: Partner): Promise<string> {
return this.queue.push(async () => {
const response = await callApiUserPartnerURL(this.fetcher, {
session: this.session,
sso: {
code: partner.code,
linkLabel: partner.linkLabel,
description: partner.description
}
});

return response.url;
});
}
}
4 changes: 3 additions & 1 deletion src/constants/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ export enum PronoteApiFunctions {
MessageRecipients = "SaisiePublicMessage",
PatchNews = "SaisieActualites",
CreateDiscussionRecipients = "ListeRessourcesPourCommunication",
CreateMessage = "SaisieMessage"
CreateMessage = "SaisieMessage",
HomePage = "PageAccueil",
PartnerURL = "SaisieURLPartenaire"
}
5 changes: 5 additions & 0 deletions src/constants/partner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface PronoteSSO {
codePartenaire: string
intituleLien: string
description: string
}
32 changes: 32 additions & 0 deletions src/parser/partner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PronoteSSO } from "~/constants/partner";
import Pronote from "~/client/Pronote";

export class Partner {
readonly #client: Pronote;
readonly #code: string;
readonly #description: string;
readonly #linkLabel: string;

public constructor (client: Pronote, sso: PronoteSSO) {
this.#client = client;
this.#code = sso.codePartenaire;
this.#description = sso.description;
this.#linkLabel = sso.intituleLien;
}

public async fetchURL (): Promise<string> {
return this.#client.getPartnerURL(this);
}

public get code (): string {
return this.#code;
}

public get description (): string {
return this.#description;
}

public get linkLabel (): string {
return this.#linkLabel;
}
}

0 comments on commit 495d970

Please sign in to comment.