Skip to content

Commit b699cc4

Browse files
author
soycode
committed
region constant, indent tweaks
1 parent a06dee4 commit b699cc4

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/cloud/digitalocean/provisioner.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ declare var forge: any;
77

88
const POLL_TIMEOUT: number = 5000; //milliseconds
99

10+
// To see available regions:
11+
// https://developers.digitalocean.com/documentation/v2/#list-all-regions
12+
const DEFAULT_REGION: string = "nyc3";
13+
1014
const STATUS_CODES: { [k: string]: string; } = {
1115
"START": "Starting provisioner",
1216
"OAUTH_INIT": "Initializing oauth flow",
@@ -48,7 +52,8 @@ class Provisioner {
4852
* @param {String} region to create VM in
4953
* @return {Promise.<Object>}
5054
*/
51-
public start = (name: string, region?: string) : Promise<Object> => {
55+
public start = (name: string, region: string = DEFAULT_REGION) :
56+
Promise<Object> => {
5257
this.sendStatus_("START");
5358
// Do oAuth
5459
return this.doOAuth_().then((oauthObj: any) => {
@@ -153,18 +158,18 @@ class Provisioner {
153158
this.sendStatus_("OAUTH_INIT");
154159
oauth.initiateOAuth(REDIRECT_URIS).then((obj: any) => {
155160
var url = "https://cloud.digitalocean.com/v1/oauth/authorize?" +
156-
"client_id=c16837b5448cd6cf2582d2c2f767cfb7d11844ec395a91b43f26ca72513416c8&" +
157-
"response_type=token&" +
158-
"redirect_uri=" + encodeURIComponent(obj.redirect) + "&" +
159-
"state=" + encodeURIComponent(obj.state) + "&" +
160-
"scope=read%20write";
161+
"client_id=c16837b5448cd6cf2582d2c2f767cfb7d11844ec395a91b43f26ca72513416c8&" +
162+
"response_type=token&" +
163+
"redirect_uri=" + encodeURIComponent(obj.redirect) + "&" +
164+
"state=" + encodeURIComponent(obj.state) + "&" +
165+
"scope=read%20write";
161166
return oauth.launchAuthFlow(url, obj);
162167
}).then((responseUrl: string) => {
163168
var query = responseUrl.substr(responseUrl.indexOf('#') + 1),
164-
param: string,
165-
params: { [k: string]: string } = {},
166-
keys = query.split('&'),
167-
i = 0;
169+
param: string,
170+
params: { [k: string]: string } = {},
171+
keys = query.split('&'),
172+
i = 0;
168173
for (i = 0; i < keys.length; i++) {
169174
param = keys[i].substr(0, keys[i].indexOf('='));
170175
params[param] = keys[i].substr(keys[i].indexOf('=') + 1);
@@ -224,7 +229,7 @@ class Provisioner {
224229
* @return {Promise.<Object>} - JSON object of response body
225230
*/
226231
private doRequest_ = (method: string, actionPath: string, body?: string) :
227-
Promise<Object> => {
232+
Promise<Object> => {
228233
return new Promise((F, R) => {
229234
var url = 'https://api.digitalocean.com/v2/' + actionPath;
230235
var xhr = freedom["core.xhr"]();

0 commit comments

Comments
 (0)