2016-05-22 00:24:02 +03:00
|
|
|
var request = require('request');
|
|
|
|
var Promise = require('promise');
|
2017-03-12 18:36:32 +02:00
|
|
|
|
2017-07-15 13:58:02 +03:00
|
|
|
function RequestPromise(url, urlArgs, headers, json) {
|
|
|
|
if(typeof headers === 'undefined') {
|
|
|
|
headers = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if(typeof json === 'undefined') {
|
|
|
|
json = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var promise = new Promise(function(resolve, reject) {
|
|
|
|
request({
|
|
|
|
url: url,
|
|
|
|
qs: urlArgs,
|
|
|
|
headers: headers,
|
|
|
|
json: json
|
|
|
|
}, function(error, response, body) {
|
|
|
|
if(!error && response.statusCode == 200) {
|
|
|
|
resolve(JSON.parse(body));
|
|
|
|
} else {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return promise;
|
|
|
|
}
|
2016-05-22 00:24:02 +03:00
|
|
|
|
2017-03-12 18:36:32 +02:00
|
|
|
module.exports = RequestPromise;
|