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

feat: custom user agent

This commit is contained in:
James Cook 2022-07-21 15:46:08 +01:00
parent aebdbf819a
commit e33210e452

View file

@ -24,8 +24,8 @@ import type {
export class ClasschartsClient { export class ClasschartsClient {
protected studentId = 0; protected studentId = 0;
protected studentName = ""; protected studentName = "";
protected authCookies: Array<string> | undefined; public authCookies: Array<string> | undefined;
protected sessionId = ""; public sessionId = "";
protected API_BASE = ""; protected API_BASE = "";
protected axios: AxiosInstance; protected axios: AxiosInstance;
/** /**
@ -34,7 +34,14 @@ export class ClasschartsClient {
*/ */
constructor(API_BASE: string, axiosConfig?: AxiosRequestConfig) { constructor(API_BASE: string, axiosConfig?: AxiosRequestConfig) {
this.API_BASE = API_BASE; this.API_BASE = API_BASE;
this.axios = axios.create(axiosConfig); this.axios = axios.create({
...axiosConfig,
headers: {
"User-Agent": "classcharts-api.js",
...axiosConfig?.headers,
},
validateStatus: () => true,
});
} }
public async makeAuthedRequest( public async makeAuthedRequest(
path: string, path: string,
@ -45,11 +52,10 @@ export class ClasschartsClient {
...options, ...options,
url: path, url: path,
headers: { headers: {
...options.headers,
Cookie: this.authCookies.join(";"), Cookie: this.authCookies.join(";"),
authorization: "Basic " + this.sessionId, authorization: "Basic " + this.sessionId,
...options.headers,
}, },
validateStatus: () => true,
}; };
const request = await this.axios.request(requestOptions); const request = await this.axios.request(requestOptions);
const responseJSON = request.data; const responseJSON = request.data;