1
0
mirror of https://github.com/franjsco/trackmyd-bot synced 2025-02-16 11:31:46 +01:00
This commit is contained in:
Francesco Esposito 2019-02-20 15:51:31 +01:00
parent d2148df68c
commit d6c7c6a6c8
2 changed files with 57 additions and 1 deletions

53
api.js Normal file
View File

@ -0,0 +1,53 @@
const fetch = require('node-fetch');
const { api } = require('./config');
const devicesPath = `${api.baseURL}${api.paths.devices}`;
function getDevices() {
const init = {
method: 'GET',
headers: api.headers,
};
return fetch(devicesPath, init);
}
function getInfoDevice(name) {
const init = {
method: 'GET',
headers: api.headers,
};
const path = `${devicesPath}?name=${name}`;
return fetch(path, init);
}
function addDevice(name) {
const body = {
name,
};
const init = {
method: 'POST',
headers: api.headers,
body: JSON.stringify(body),
};
return fetch(devicesPath, init);
}
function removeDevice(id) {
const init = {
method: 'DELETE',
headers: api.headers,
};
const path = `${devicesPath}${id}`;
return fetch(path, init);
}
module.exports.getDevices = getDevices;
module.exports.getInfoDevice = getInfoDevice;
module.exports.addDevice = addDevice;
module.exports.removeDevice = removeDevice;

View File

@ -9,8 +9,11 @@
"api": {
"baseURL": "http://localhost:3500/api",
"headers": {
"secret": "mysecret",
"Authorization": "Basic Y2xpZW50MjpjbGllbnQy",
"Content-Type": "application/json"
},
"paths": {
"devices": "/devices/"
}
},
"logger": {