-
Notifications
You must be signed in to change notification settings - Fork 0
@das‐dui api‐client
Florian edited this page Mar 29, 2024
·
4 revisions
The @das-dui/api-client
package provides a convenient way to interact with the Sdui API. It abstracts away the complexities of making HTTP requests and handling authentication, allowing you to focus on building your application.
Below is the API reference for the AxiosApiClient
class:
constructor(params: AxiosApiClientParams)
- Creates an instance of the AxiosApiClient class.
- Parameters:
-
params
: Parameters for initializing the AxiosApiClient instance. It can be either for internal or external authentication logic.-
authLogic
: Authentication logic, can be"internal"
or"external"
. -
token?
: (Optional) Token for internal authentication logic. -
instance?
: (Optional) AxiosInstance for custom configurations.
-
-
public getInstance(): AxiosInstance
- Returns the AxiosInstance associated with the AxiosApiClient instance.
public setToken(token: string): void
- Sets the authentication token for internal authentication logic.
- Parameters:
-
token
: Authentication token.
-
public getToken(): string
- Returns the current authentication token.
public login({
slink,
identifier,
password,
showErrors
}: {
slink: string,
identifier: string,
password: string,
showErrors?: boolean
}): Promise<AxiosResponse<BaseResponse<LoginResponse.LoginToken>>>
- Logs in a user and retrieves an access token.
- Parameters:
-
slink
: School link. -
identifier
: User identifier. -
password
: User password. -
showErrors
: (Optional) Boolean to indicate whether to show errors in the response.
-
- Returns: A Promise resolving to the AxiosResponse containing the login token.
public getLeadsByName({
searchQuery
}: {
searchQuery: string
}): Promise<AxiosResponse<BaseResponse<LeadsResponse.Lead[]>>>
- Retrieves leads by name.
- Parameters:
-
searchQuery
: Search query for leads.
-
- Returns: A Promise resolving to the AxiosResponse containing the leads.
public getNewsByPage({
page
}: {
page: number
}, userId?: number | string): Promise<AxiosResponse<BaseResponse<NewsResponse.News[]>>>
- Retrieves news by page.
- Parameters:
-
page
: Page number. -
userId
: (Optional) User ID.
-
- Returns: A Promise resolving to the AxiosResponse containing the news.
public getNewsById({
newsId
}: {
newsId: number
}): Promise<AxiosResponse<BaseResponse<NewsResponse.News>>>
- Retrieves news post by id.
- Parameters:
-
newsId
: News Id.
-
- Returns: A Promise resolving to the AxiosResponse containing the news.
public getTimes(): Promise<TimetableTimeResponse.TimetableTime[]>
- Retrieves timetable times.
- Returns: A Promise resolving to an array of timetable times.
public getTimesCleanedUp(): Promise<TimetableTimeResponse.TimetableTime[]>
- Retrieves cleaned up timetable times (removes hidden times and the first break if present).
- Returns: A Promise resolving to an array of cleaned up timetable times.
public getTimetableByDate({
from,
to
}: {
from: Date | string,
to: Date | string
}, userId?: number | string): Promise<AxiosResponse<BaseResponse<TimetableResponse.Timetable>>>
- Retrieves timetable for a specific date range.
- Parameters:
-
from
: Start date. -
to
: End date. -
userId
: (Optional) User ID.
-
- Returns: A Promise resolving to the AxiosResponse containing the timetable.
public getUser(userId?: number | string): Promise<AxiosResponse<BaseResponse<UserResponse.User>>>
- Retrieves user information.
- Parameters:
-
userId
: (Optional) User ID.
-
- Returns: A Promise resolving to the AxiosResponse containing the user information.
public getUserActivitySummary(userId?: number | string): Promise<AxiosResponse<BaseResponse<UserActivitySummaryResponse.ActivitySummary>>>
- Retrieves user activity summary.
- Parameters:
-
userId
: (Optional) User ID.
-
- Returns: A Promise resolving to the AxiosResponse containing the user activity summary.
public getClassbookEntry({
lessonId,
date
}: {
lessonId: number,
date: Date | string
}): Promise<AxiosResponse<BaseResponse<ClassbookEntryResponse.ClassbookEntry>>>
- Retrieves classbook entry for a lesson on a specific date.
- Parameters:
-
lessonId
: Lesson ID. -
date
: Date of the classbook entry.
-
- Returns: A Promise resolving to the classbook entry.
public getSurveyById({
surveyId
}: {
surveyId: string
}): Promise<AxiosResponse<BaseResponse<SurveyResponse.Survey>>>
- Retrieves survey by id.
- Parameters:
-
surveyId
: Survey Id.
-
- Returns: A Promise resolving to the AxiosResponse containing the survey.
public postSurveyVote(
{ surveyId }: { surveyId: string },
vote: SurveyVoteRequest.Vote
): Promise<AxiosResponse<BaseResponse<SurveyResponse.Survey>>>
- Posts a vote to a survey.
- Parameters:
-
surveyId
: Survey Id. -
vote
: Vote object.
-
- Returns: A Promise resolving to the AxiosResponse containing the updated survey.
/**
* Represents a response from an Axios request.
* @template T The type of data contained in the response.
* @template D The type of data associated with the request.
*/
export interface AxiosResponse<T = any, D = any> {
/** The data returned by the server. */
data: T;
/** The HTTP status code of the response. */
status: number;
/** The status message corresponding to the status code. */
statusText: string;
/** The headers sent by the server. */
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
/** The Axios request config. */
config: InternalAxiosRequestConfig<D>;
/** The XMLHttpRequest instance or a browser-specific equivalent (optional). */
request?: any;
}
/**
* Represents metadata associated with a base response.
*/
interface BaseResponseMeta {
/** An array of warning messages. */
warnings: string[];
/** An array of error messages. */
errors: string[];
/** An array of success messages. */
success: string[];
}
/**
* Represents a base response from an API request.
* @template T The type of data contained in the response.
*/
export interface BaseResponse<T> {
/** The data contained in the response. */
data: T;
/** The status of the response. */
status: string;
/** The metadata associated with the response. */
meta: BaseResponseMeta;
}