-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
4,952 additions
and
7,284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
10.8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
import 'es6-promise'; | ||
import * as request from 'request'; | ||
import * as rp from 'request-promise-native'; | ||
|
||
/** | ||
* Wrapper class for the request package. Used to make HTTP calls. | ||
*/ | ||
export default class HTTPService { | ||
private debug?: boolean; | ||
private debug?: boolean; | ||
|
||
constructor(debug?: boolean) { | ||
this.debug = debug; | ||
} | ||
constructor(debug?: boolean) { | ||
this.debug = debug; | ||
} | ||
|
||
/** | ||
* Base function for GET requests | ||
* @async | ||
* @param options Options for the request package to use | ||
* @return {Promise.any} When fulfilled returns an object containing the response from the request | ||
*/ | ||
public get(options: rp.OptionsWithUri): Promise<object> { | ||
options.method = 'GET'; | ||
if (this.debug) { | ||
console.log('\x1b[33m%s\x1b[0m', 'Debug url:' + options.uri); | ||
} | ||
return new Promise<object>((resolve, reject) => { | ||
rp(options) | ||
.then((response) => { | ||
if (response.access_token) { // this is a oauth reponse | ||
resolve(response); | ||
} else if (response.ErrorCode !== 1) { | ||
reject(response); | ||
} else { | ||
resolve(response); | ||
} | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
/** | ||
* Base function for GET requests | ||
* @async | ||
* @param options Options for the request package to use | ||
* @return {Promise.any} When fulfilled returns an object containing the response from the request | ||
*/ | ||
public get(options: rp.OptionsWithUri): Promise<object> { | ||
options.method = 'GET'; | ||
if (this.debug) { | ||
console.log('\x1b[33m%s\x1b[0m', 'Debug url:' + options.uri); | ||
} | ||
|
||
/** | ||
* Base function for POST requests | ||
* @async | ||
* @param options Options for the request package to use | ||
* @return {Promise.any} When fulfilled returns an object containing the response from the request | ||
*/ | ||
public post(options: rp.OptionsWithUri): Promise<object> { | ||
options.method = 'POST'; | ||
if (this.debug) { | ||
console.log('\x1b[33m%s\x1b[0m', 'Debug url:' + options.uri); | ||
} | ||
return new Promise<object>((resolve, reject) => { | ||
rp(options) | ||
.then((response) => { | ||
if (response.access_token) { // this is a oauth reponse | ||
resolve(response); | ||
} else if (response.ErrorCode !== 1) { | ||
reject(response); | ||
} | ||
resolve(response); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
return new Promise<object>((resolve, reject) => { | ||
rp(options) | ||
.then(response => { | ||
if (response.access_token) { | ||
// this is a oauth reponse | ||
resolve(response); | ||
} else if (response.ErrorCode !== 1) { | ||
reject(response); | ||
} else { | ||
resolve(response); | ||
} | ||
}) | ||
.catch(err => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Base function for POST requests | ||
* @async | ||
* @param options Options for the request package to use | ||
* @return {Promise.any} When fulfilled returns an object containing the response from the request | ||
*/ | ||
public post(options: rp.OptionsWithUri): Promise<object> { | ||
options.method = 'POST'; | ||
if (this.debug) { | ||
console.log('\x1b[33m%s\x1b[0m', 'Debug url:' + options.uri); | ||
} | ||
return new Promise<object>((resolve, reject) => { | ||
rp(options) | ||
.then(response => { | ||
if (response.access_token) { | ||
// this is a oauth reponse | ||
resolve(response); | ||
} else if (response.ErrorCode !== 1) { | ||
reject(response); | ||
} | ||
resolve(response); | ||
}) | ||
.catch(err => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.