@ovh-api/common
Advanced tools
Comparing version 0.0.5 to 0.1.0
@@ -11,12 +11,20 @@ export declare class ApiCommon { | ||
[key: string]: string | Number; | ||
}, queryParams?: any): Promise<any>; | ||
}, queryParams?: { | ||
[key: string]: string | Number; | ||
}): Promise<any>; | ||
protected put(path: string, pathParams?: { | ||
[key: string]: string | Number; | ||
}, bodyParams?: any): Promise<any>; | ||
}, bodyParams?: { | ||
[key: string]: string | Number; | ||
}): Promise<any>; | ||
protected post(path: string, pathParams?: { | ||
[key: string]: string | Number; | ||
}, bodyParams?: any): Promise<any>; | ||
}, bodyParams?: { | ||
[key: string]: string | Number; | ||
}): Promise<any>; | ||
protected delete(path: string, pathParams?: { | ||
[key: string]: string | Number; | ||
}, bodyParams?: any): Promise<any>; | ||
}, bodyParams?: { | ||
[key: string]: string | Number; | ||
}): Promise<any>; | ||
} |
@@ -21,15 +21,36 @@ "use strict"; | ||
get(path, pathParams, queryParams) { | ||
path = this.replacePath(path, pathParams); | ||
if (~path.indexOf('{')) { | ||
path = this.replacePath(path, pathParams); | ||
} | ||
else if (!queryParams) { | ||
queryParams = pathParams; | ||
} | ||
return this.ovh.requestPromised('GET', path, queryParams); | ||
} | ||
put(path, pathParams, bodyParams) { | ||
path = this.replacePath(path, pathParams); | ||
if (~path.indexOf('{')) { | ||
path = this.replacePath(path, pathParams); | ||
} | ||
else { | ||
if (!bodyParams) | ||
bodyParams = pathParams; | ||
} | ||
return this.ovh.requestPromised('PUT', path, bodyParams); | ||
} | ||
post(path, pathParams, bodyParams) { | ||
path = this.replacePath(path, pathParams); | ||
if (~path.indexOf('{')) { | ||
path = this.replacePath(path, pathParams); | ||
} | ||
else if (!bodyParams) { | ||
bodyParams = pathParams; | ||
} | ||
return this.ovh.requestPromised('POST', path, bodyParams); | ||
} | ||
delete(path, pathParams, bodyParams) { | ||
path = this.replacePath(path, pathParams); | ||
if (~path.indexOf('{')) { | ||
path = this.replacePath(path, pathParams); | ||
} | ||
else if (!bodyParams) { | ||
bodyParams = pathParams; | ||
} | ||
return this.ovh.requestPromised('DELETE', path, bodyParams); | ||
@@ -36,0 +57,0 @@ } |
{ | ||
"name": "@ovh-api/common", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"main": "dist/index.js", | ||
@@ -14,3 +14,3 @@ "typings": "dist/index.d.ts", | ||
}, | ||
"gitHead": "ce051c102c7e3afd2e7c125fc40371585bcf8dca" | ||
"gitHead": "0eaca157fe48b82761499cba7ee318d0f58c6af5" | ||
} |
@@ -7,8 +7,8 @@ //module.exports = () => { | ||
private ovh: any; | ||
constructor(config: {appKey: string, appSecret: string, consumerKey: string}) { | ||
constructor(config: { appKey: string, appSecret: string, consumerKey: string }) { | ||
this.ovh = require('ovh')(config); | ||
} | ||
private replacePath(path: string, pathParams?:{ [key:string]:string | Number; }) : string{ | ||
private replacePath(path: string, pathParams?: { [key: string]: string | Number; }): string { | ||
// TODO add assert .match(/(\{[\w]+\})/g) | ||
if (!pathParams) | ||
if (!pathParams) | ||
return path; | ||
@@ -22,21 +22,39 @@ for (const key of Object.keys(pathParams)) { | ||
protected get(path: string, pathParams?:{ [key:string]: string | Number; }, queryParams?: any) : Promise<any> { | ||
path = this.replacePath(path, pathParams); | ||
protected get(path: string, pathParams?: { [key: string]: string | Number; }, queryParams?: { [key: string]: string | Number; }): Promise<any> { | ||
if (~path.indexOf('{')) { | ||
path = this.replacePath(path, pathParams); | ||
} else if (!queryParams) { | ||
queryParams = pathParams; | ||
} | ||
return this.ovh.requestPromised('GET', path, queryParams) | ||
} | ||
protected put(path: string, pathParams?: { [key:string]:string | Number; }, bodyParams?: any) : Promise<any> { | ||
path = this.replacePath(path, pathParams); | ||
protected put(path: string, pathParams?: { [key: string]: string | Number; }, bodyParams?: { [key: string]: string | Number; }): Promise<any> { | ||
if (~path.indexOf('{')) { | ||
path = this.replacePath(path, pathParams); | ||
} else { | ||
if (!bodyParams) | ||
bodyParams = pathParams; | ||
} | ||
return this.ovh.requestPromised('PUT', path, bodyParams) | ||
} | ||
protected post(path: string, pathParams?: { [key:string]:string | Number; }, bodyParams?: any) : Promise<any> { | ||
path = this.replacePath(path, pathParams); | ||
protected post(path: string, pathParams?: { [key: string]: string | Number; }, bodyParams?: { [key: string]: string | Number; }): Promise<any> { | ||
if (~path.indexOf('{')) { | ||
path = this.replacePath(path, pathParams); | ||
} else if (!bodyParams) { | ||
bodyParams = pathParams; | ||
} | ||
return this.ovh.requestPromised('POST', path, bodyParams) | ||
} | ||
protected delete(path: string, pathParams?: { [key:string]:string | Number; }, bodyParams?: any) : Promise<any> { | ||
path = this.replacePath(path, pathParams); | ||
protected delete(path: string, pathParams?: { [key: string]: string | Number; }, bodyParams?: { [key: string]: string | Number; }): Promise<any> { | ||
if (~path.indexOf('{')) { | ||
path = this.replacePath(path, pathParams); | ||
} | ||
else if (!bodyParams){ | ||
bodyParams = pathParams; | ||
} | ||
return this.ovh.requestPromised('DELETE', path, bodyParams) | ||
} | ||
} |
6772
146