-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.mjs
68 lines (55 loc) · 1.83 KB
/
utils.mjs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import axios from 'axios';
export async function get(endpoint, api_url, api_token){
console.log("Doing authenticated GET request to the API")
console.log(endpoint)
let config = {
headers: {
'User-Agent': 'python-requests',
'Content-Type': 'application/json',
'Authorization': api_token
}
};
let result = await axios.get(`${api_url}/${endpoint}`, config);
console.log(`Status code: ${result.status}`)
if (result.status != 200)
console.error(result)
return result.data;
}
export async function deleteRow(endpoint, api_url, api_token){
console.log("Doing authenticated DELETE request to the API")
console.log(endpoint)
let config = {
headers: {
'User-Agent': 'python-requests',
'Content-Type': 'application/json',
'Authorization': api_token
}
};
let result = await axios.delete(`${api_url}/${endpoint}`, config);
console.log(`Status code: ${result.status}`)
if (result.status != 200)
console.error(result)
return result.data
}
export async function post(payload, endpoint, api_url, api_token){
console.log("Doing authenticated POST request to the API")
console.log(endpoint)
let config = {
headers: {
'User-Agent': 'python-requests',
'Content-Type': 'application/json',
'Authorization': api_token
}
};
let result = await axios.post(`${api_url}/${endpoint}`, payload, config);
console.log(`Status code: ${result.status}`)
if (result.status != 200)
console.error(result)
return result.data
}
export const waitFor = async (ms) => new Promise(r => setTimeout(r, ms))
export const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}