fix(core): update

This commit is contained in:
2019-01-05 22:00:02 +01:00
parent c193fe9546
commit 0498c1d793
19 changed files with 1824 additions and 41 deletions

View 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;
}
}

View 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
View File

@ -0,0 +1,3 @@
import * as smartrequest from '@pushrocks/smartrequest';
export { smartrequest };

View File

@ -1 +0,0 @@
import 'typings-global'

View File

@ -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';

View File

@ -0,0 +1 @@
export type TDropletSizes = 's-1vcpu-1gb';

1
ts/interfaces/images.ts Normal file
View File

@ -0,0 +1 @@
export type TImages = 'ubuntu-18-04-x64';

3
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1,3 @@
export * from './droplets';
export * from './regions';
export * from './images';

4
ts/interfaces/regions.ts Normal file
View File

@ -0,0 +1,4 @@
/**
* An interface describing the available regions
*/
export type TRegions = 'ams1' | 'ams2' | 'ams3' | 'fra1' | 'nyc1' | 'nyc2' | 'nyc3';