fix(core): update

This commit is contained in:
Philipp Kunz 2024-01-29 21:14:05 +01:00
parent 0ac4c6d9a1
commit 8322e8defd
4 changed files with 28 additions and 6 deletions

View File

@ -23,8 +23,16 @@ PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@apiclient.xyz/hetznercloud)](https://lossless.cloud)
## Usage
Use TypeScript for best in class intellisense
For further information read the linked docs at the top of this readme.
A modern approach to talking to the hetzner API.
```typescript
import hetznerCloud from '@apiclient.xyz/hetznercloud'
const myhetznerAccount = new hetznerCloud.HetznerAccount('myToken');
const servers = const myhetznerAccount.getServers();
for (const server of servers) {
await server.delete();
}
```
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@apiclient.xyz/hetznercloud',
version: '1.0.2',
version: '1.0.3',
description: 'an unofficial api client for the hetzner cloud api'
}

View File

@ -1,3 +1,4 @@
import { HetznerServer } from './classes.server.js';
import * as plugins from './hetznercloud.plugins.js';
export class HetznerAccount {
@ -6,8 +7,8 @@ export class HetznerAccount {
this.token = tokenArg;
}
getServers() {
public async getServers() {
return HetznerServer.getServers(this);
}
/**

View File

@ -4,7 +4,7 @@ import * as types from './types.js';
export class HetznerServer {
// STATIC
static async create(hetznerAccountRefArg: HetznerAccount, optionsArg: {
public static async create(hetznerAccountRefArg: HetznerAccount, optionsArg: {
name: string,
datacenter: 'nbg1-dc3',
}) {
@ -26,6 +26,19 @@ export class HetznerServer {
return server;
}
public static async getServers(hetznerAccountRefArg: HetznerAccount) {
const serversGetUrl = '/servers';
const response = await hetznerAccountRefArg.request('GET', serversGetUrl, {});
const serversDataArray = (response.body as types.TServersGetResponseBody).servers;
const servers: HetznerServer[] = [];
for (const serverData of serversDataArray) {
const server = new HetznerServer(hetznerAccountRefArg);
server.data = serverData;
servers.push(server);
}
return servers;
}
// INSTANCE
public hetznerAccountRef: HetznerAccount;
public data: types.IServer;