forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-handler-service.js
34 lines (31 loc) · 1.02 KB
/
api-handler-service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const request = require('request');
exports.getResponse = function (url, requestParameters, headers) {
return new Promise(
(resolve, reject) => {
if (url && requestParameters && headers) {
const requestData = {
url: url + constructRequestParams(requestParameters),
headers: headers,
json: true
}
request.get(requestData, (error, response, body) => {
if (error) {
reject(error);
} else if (response.statusCode != 200) {
reject(body);
} else {
resolve(body);
}
});
} else {
reject("");
}
}
);
}
function constructRequestParams(data) {
var ret = [];
for (var d in data)
ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(data[d]));
return "?" + ret.join('&');
}