mirror of
https://github.com/tribufu/tribufu-js
synced 2026-05-06 06:47:27 +00:00
Add more methods and singleton
This commit is contained in:
parent
962a3de36a
commit
009dfc04ab
4 changed files with 885 additions and 74 deletions
|
|
@ -7,8 +7,10 @@ import { TribufuApi } from "../build/index.mjs";
|
|||
dotenv.config();
|
||||
|
||||
async function main() {
|
||||
const api = TribufuApi.fromEnv();
|
||||
console.log(await api.getUserInfo());
|
||||
const tribufu = TribufuApi.fromEnv();
|
||||
console.log(
|
||||
await tribufu.getServerByAddressAndQueryPort("mine.tribufu.com", 25565),
|
||||
);
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ export abstract class TribufuApiBase {
|
|||
*/
|
||||
protected static defaultHeaders(): HttpHeaders {
|
||||
const headers = {};
|
||||
headers["X-Tribufu-Language"] = "javascript";
|
||||
headers["X-Tribufu-Library"] = "javascript";
|
||||
headers["X-Tribufu-Version"] = TRIBUFU_VERSION;
|
||||
return headers;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
23
src/api/singletion.ts
Normal file
23
src/api/singletion.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { TribufuApi } from "./index";
|
||||
|
||||
/**
|
||||
* **Tribufu API**
|
||||
*
|
||||
* Helper class to get a singleton instance of the Tribufu API.
|
||||
*/
|
||||
export class TribufuApiSingleton {
|
||||
private static INSTANCE: TribufuApi | null = null;
|
||||
|
||||
private constructor() {}
|
||||
|
||||
public static getInstance(): TribufuApi {
|
||||
if (!TribufuApiSingleton.INSTANCE) {
|
||||
TribufuApiSingleton.INSTANCE = TribufuApi.fromEnvOrDefault();
|
||||
}
|
||||
|
||||
return TribufuApiSingleton.INSTANCE;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue