Doodle3D-API/src/api/network.js

54 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-11-30 17:23:13 +01:00
import { parseFetch } from '../utils.js';
2015-07-15 15:06:18 +02:00
2016-04-21 15:44:20 +02:00
export default class Network {
2016-04-21 15:52:23 +02:00
constructor(api) {
this.api = api;
}
scan() {
2017-11-30 17:23:13 +01:00
return fecth(`${this.api}network/scan`, { method: 'GET' }).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
known() {
2017-11-30 17:23:13 +01:00
return fecth(`${this.api}network/known`, { method: 'GET' }).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
status() {
2017-11-30 17:23:13 +01:00
return fecth(`${this.api}network/status`, { method: 'GET' }).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
assosiate(ssid, phrase, recreate = false) {
2018-01-25 17:29:51 +01:00
const body = new URLSearchParams();
body.append('ssid', ssid);
body.append('phrase', phrase);
body.append('recreate', recreate);
return fetch(`${this.api}network/associate`, { method: 'POST', body }).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
disassociate() {
//not tested
2018-01-25 17:29:51 +01:00
const body = new URLSearchParams();
return fetch(`${this.api}network/disassociate`, { method: 'POST', body }).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
openAccesPoint() {
//not tested
2018-01-25 17:29:51 +01:00
const body = new URLSearchParams();
return fetch(`${this.api}network/openap`, { method: 'POST', body }).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
remove(ssid) {
2018-01-25 17:29:51 +01:00
const body = new URLSearchParams();
body.append('ssid', ssid);
return fetch(`${this.api}network/remove`, { method: 'POST', body }).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
signin() {
2017-11-30 17:23:13 +01:00
return fecth(`${this.api}network/signin`, { method: 'GET' }).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
async alive() {
try {
2017-11-30 17:57:22 +01:00
await fetch(`${this.api}network/alive`, { method: 'GET' }).then(parseFetch);
2016-04-21 15:52:23 +02:00
return true;
} catch(error) {
return false;
}
}
}