mirror of
https://github.com/tribufu/sdk-js
synced 2025-06-15 18:24:19 +00:00
Add more functions
This commit is contained in:
94
src/api.ts
94
src/api.ts
@ -234,7 +234,7 @@ export class TribufuApi {
|
||||
* @param id
|
||||
* @returns Game | null
|
||||
*/
|
||||
public async getGameyId(id: string): Promise<any | null> {
|
||||
public async getGameById(id: string): Promise<any | null> {
|
||||
const headers = this.getHeaders();
|
||||
const responseBody = await this.http.get<any>(`/v1/packages/${id}`, headers);
|
||||
|
||||
@ -305,4 +305,96 @@ export class TribufuApi {
|
||||
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user by id from the Tribufu API.
|
||||
* @param id
|
||||
* @returns User | null
|
||||
*/
|
||||
public async getUserById(id: string): Promise<any> {
|
||||
const headers = this.getHeaders();
|
||||
const responseBody = await this.http.get(`/v1/users/${id}`, headers);
|
||||
|
||||
if (!responseBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user by uuid from the Tribufu API.
|
||||
* @param uuid
|
||||
* @returns User[]
|
||||
*/
|
||||
public async getUserByUuid(uuid: string): Promise<any[]> {
|
||||
return await this.getUserByKey("uuid", uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user by name from the Tribufu API.
|
||||
* @param uuid
|
||||
* @returns User[]
|
||||
*/
|
||||
public async getUserByName(name: string): Promise<any[]> {
|
||||
return await this.getUserByKey("name", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user by email from the Tribufu API.
|
||||
* @param uuid
|
||||
* @returns User[]
|
||||
*/
|
||||
public async getUserByEmail(email: string): Promise<any[]> {
|
||||
return await this.getUserByKey("email", email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user by custom key from the Tribufu API.
|
||||
* @param key
|
||||
* @param value
|
||||
* @returns User[]
|
||||
*/
|
||||
private async getUserByKey(key: string, value: string): Promise<any[]> {
|
||||
const headers = this.getHeaders();
|
||||
const responseBody = await this.http.get<any[]>(`/v1/users/?${key}=${value}`, headers);
|
||||
|
||||
if (!responseBody) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all servers for a user from the Tribufu API.
|
||||
* @param userId
|
||||
* @returns Server[]
|
||||
*/
|
||||
public async getUserServers(userId: string): Promise<any[]> {
|
||||
const headers = this.getHeaders();
|
||||
const responseBody = await this.http.get<any[]>(`/v1/users/${userId}/servers`, headers);
|
||||
|
||||
if (!responseBody) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a oauth2 client by id from the Tribufu API.
|
||||
* @param id
|
||||
* @returns Client | null
|
||||
*/
|
||||
protected async getClientById(id: string): Promise<any> {
|
||||
const headers = this.getHeaders();
|
||||
const responseBody = await this.http.get(`/v1/oauth2/clients/${id}`, headers);
|
||||
|
||||
if (!responseBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return responseBody;
|
||||
}
|
||||
}
|
||||
|
@ -333,6 +333,14 @@ export class TribufuClient extends TribufuApi {
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about the current client.
|
||||
* @returns Client | null
|
||||
*/
|
||||
public async getClientInfo(): Promise<User | null> {
|
||||
return this.getClientById(this.clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about the current user.
|
||||
* @returns User | null
|
||||
|
Reference in New Issue
Block a user