-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
36 lines (31 loc) · 1.28 KB
/
utils.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
const fetch = require('node-fetch');
async function getToken() {
const data = await fetch('https://rooftop-career-switch.herokuapp.com/[email protected]');
const jsonData = await data.json();
return jsonData.token;
}
async function getBlocks(token) {
const data = await fetch(`https://rooftop-career-switch.herokuapp.com/blocks?token=${token}`);
const jsonData = await data.json();
return jsonData.data;
}
async function checkAdjacent(string1, string2, token) {
const url = `https://rooftop-career-switch.herokuapp.com/check?token=${token}`;
const body = {method: "POST", body: JSON.stringify({ "blocks": [string1,string2]}), headers: {"Content-Type":"application/json"}};
const data = await fetch(url, body);
const jsonData = await data.json();
return jsonData.message;
}
async function checkResult(orderedArray, token) {
const url = `https://rooftop-career-switch.herokuapp.com/check?token=${token}`;
const body = {method: "POST", body: JSON.stringify({ "encoded": orderedArray.join('')}), headers: {"Content-Type":"application/json"}};
const data = await fetch(url, body);
const jsonData = await data.json();
return jsonData.message;
}
module.exports = {
getToken,
getBlocks,
checkAdjacent,
checkResult
}