fix(core): update
This commit is contained in:
parent
0ac4c6d9a1
commit
8322e8defd
12
readme.md
12
readme.md
@ -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)
|
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@apiclient.xyz/hetznercloud)](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
Use TypeScript for best in class intellisense
|
A modern approach to talking to the hetzner API.
|
||||||
For further information read the linked docs at the top of this readme.
|
|
||||||
|
```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
|
## Legal
|
||||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/hetznercloud',
|
name: '@apiclient.xyz/hetznercloud',
|
||||||
version: '1.0.2',
|
version: '1.0.3',
|
||||||
description: 'an unofficial api client for the hetzner cloud api'
|
description: 'an unofficial api client for the hetzner cloud api'
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { HetznerServer } from './classes.server.js';
|
||||||
import * as plugins from './hetznercloud.plugins.js';
|
import * as plugins from './hetznercloud.plugins.js';
|
||||||
|
|
||||||
export class HetznerAccount {
|
export class HetznerAccount {
|
||||||
@ -6,8 +7,8 @@ export class HetznerAccount {
|
|||||||
this.token = tokenArg;
|
this.token = tokenArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
getServers() {
|
public async getServers() {
|
||||||
|
return HetznerServer.getServers(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,7 +4,7 @@ import * as types from './types.js';
|
|||||||
|
|
||||||
export class HetznerServer {
|
export class HetznerServer {
|
||||||
// STATIC
|
// STATIC
|
||||||
static async create(hetznerAccountRefArg: HetznerAccount, optionsArg: {
|
public static async create(hetznerAccountRefArg: HetznerAccount, optionsArg: {
|
||||||
name: string,
|
name: string,
|
||||||
datacenter: 'nbg1-dc3',
|
datacenter: 'nbg1-dc3',
|
||||||
}) {
|
}) {
|
||||||
@ -26,6 +26,19 @@ export class HetznerServer {
|
|||||||
return server;
|
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
|
// INSTANCE
|
||||||
public hetznerAccountRef: HetznerAccount;
|
public hetznerAccountRef: HetznerAccount;
|
||||||
public data: types.IServer;
|
public data: types.IServer;
|
||||||
|
Loading…
Reference in New Issue
Block a user