-
Notifications
You must be signed in to change notification settings - Fork 7
/
helper.js
31 lines (26 loc) · 827 Bytes
/
helper.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
'use strict';
const defaults = require("./constants.json");
const querystring = require("querystring");
const httpRequest = require('./request');
const GetEndpoint = (api_key, calltype) => {
return `${defaults.endpoints.BASE_URL}${defaults.endpoints[calltype]}${querystring.stringify({ "api_key": api_key })}`
}
const GetResponse = url => {
return new Promise((resolve, reject) => {
httpRequest.get(url, {}, (err, res, body) => {
resolve(body.toString());
});
});
};
const PostResponse = (url, body) => {
return new Promise((resolve, reject) => {
httpRequest.post(url, body, (err, res, body) => {
resolve(body.toString());
});
});
};
module.exports = {
getEndpoint: GetEndpoint,
getResponse: GetResponse,
postResponse: PostResponse
};