-
Notifications
You must be signed in to change notification settings - Fork 2
/
services.js
54 lines (49 loc) · 1.64 KB
/
services.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function getOptionsForGetRequest(rootURL, credentials) {
// reusable function to return values required for making an HTTP GET request to Application Simulator
return {
method: "GET",
headers: {
"Accept": "application/json",
Authorization: "Basic " + Buffer.from(credentials).toString("base64"),
},
url: rootURL,
qs: {},
};
}
function getOptionsForCreateRequest(rootURL, credentials, requestBody) {
// reusable function to return values required for making an HTTP GET request to Application Simulator
return {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + Buffer.from(credentials).toString("base64"),
},
url: rootURL,
body: requestBody,
json: true,
qs: {},
};
}
function makeHttpRequest(option, output) {
// reusable function to make an HTTP Request
var request = require("request");
request(option, function (error, response, body) {
if (error) {
output(error);
}
else if (response.statusCode == 401) {
output("Invalid credentials");
}
else if (response.statusCode >= 200 || response.statusCode == 201) {
output(null, body);
}
else {
output("Something went wrong. Please check the input parameters or contact global presales team if the issue persists.");
}
});
}
module.exports = {
getOptionsForGetRequest: getOptionsForGetRequest,
getOptionsForCreateRequest: getOptionsForCreateRequest,
makeHttpRequest: makeHttpRequest,
};