fix(core): update
This commit is contained in:
27
ts/do.classes.doaccount.ts
Normal file
27
ts/do.classes.doaccount.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import * as plugins from './do.plugins';
|
||||
|
||||
export class DigitalOceanAccount {
|
||||
token: string;
|
||||
|
||||
constructor(tokenArg: string) {
|
||||
this.token = tokenArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* the main request method used
|
||||
*/
|
||||
async request(routeArg: string, methodArg: string, payloadArg?: any) {
|
||||
const response = await plugins.smartrequest.request(
|
||||
`https://api.digitalocean.com/v2${routeArg}`,
|
||||
{
|
||||
method: methodArg,
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.token}`,
|
||||
'Content-Type': `application/json`
|
||||
},
|
||||
requestBody: payloadArg
|
||||
}
|
||||
);
|
||||
return response.body;
|
||||
}
|
||||
}
|
32
ts/do.classes.dodroplet.ts
Normal file
32
ts/do.classes.dodroplet.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import * as plugins from './do.plugins';
|
||||
|
||||
import { TDropletSizes, TRegions, TImages } from './interfaces';
|
||||
import { DigitalOceanAccount } from './do.classes.doaccount';
|
||||
|
||||
export class DigitalOceanDroplet {
|
||||
public static async createDroplet(dropletCreateOptions: {
|
||||
account: DigitalOceanAccount;
|
||||
name: string;
|
||||
size: TDropletSizes;
|
||||
region: TRegions;
|
||||
image: string | TImages;
|
||||
}) {
|
||||
const response = await dropletCreateOptions.account.request('/droplets', 'POST', {
|
||||
name: dropletCreateOptions.name,
|
||||
region: dropletCreateOptions.region,
|
||||
size: dropletCreateOptions.size,
|
||||
image: dropletCreateOptions.image,
|
||||
ssh_keys: null,
|
||||
backups: false,
|
||||
ipv6: true,
|
||||
user_data: null,
|
||||
private_networking: null,
|
||||
volumes: null,
|
||||
tags: ['web']
|
||||
});
|
||||
|
||||
console.log(response);
|
||||
}
|
||||
|
||||
constructor() {}
|
||||
}
|
3
ts/do.plugins.ts
Normal file
3
ts/do.plugins.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
|
||||
export { smartrequest };
|
@ -1 +0,0 @@
|
||||
import 'typings-global'
|
@ -1,3 +1,2 @@
|
||||
import * as plugins from './docean.plugins'
|
||||
|
||||
export let standardExport = 'Hi there! :) This is a exported string'
|
||||
export * from './do.classes.doaccount';
|
||||
export * from './do.classes.dodroplet';
|
||||
|
1
ts/interfaces/droplets.ts
Normal file
1
ts/interfaces/droplets.ts
Normal file
@ -0,0 +1 @@
|
||||
export type TDropletSizes = 's-1vcpu-1gb';
|
1
ts/interfaces/images.ts
Normal file
1
ts/interfaces/images.ts
Normal file
@ -0,0 +1 @@
|
||||
export type TImages = 'ubuntu-18-04-x64';
|
3
ts/interfaces/index.ts
Normal file
3
ts/interfaces/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './droplets';
|
||||
export * from './regions';
|
||||
export * from './images';
|
4
ts/interfaces/regions.ts
Normal file
4
ts/interfaces/regions.ts
Normal file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* An interface describing the available regions
|
||||
*/
|
||||
export type TRegions = 'ams1' | 'ams2' | 'ams3' | 'fra1' | 'nyc1' | 'nyc2' | 'nyc3';
|
Reference in New Issue
Block a user