mirror of
https://github.com/franjsco/trackmyd-bot
synced 2025-02-16 11:31:46 +01:00
add api
This commit is contained in:
parent
d2148df68c
commit
d6c7c6a6c8
53
api.js
Normal file
53
api.js
Normal 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;
|
@ -9,8 +9,11 @@
|
||||
"api": {
|
||||
"baseURL": "http://localhost:3500/api",
|
||||
"headers": {
|
||||
"secret": "mysecret",
|
||||
"Authorization": "Basic Y2xpZW50MjpjbGllbnQy",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
"paths": {
|
||||
"devices": "/devices/"
|
||||
}
|
||||
},
|
||||
"logger": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user