Doodle3D-API/src/api/network.js

58 lines
1.6 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) {
2017-11-30 17:23:13 +01:00
return fetch(`${this.api}network/associate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ssid, phrase, recreate })
}).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
disassociate() {
//not tested
2017-11-30 17:23:13 +01:00
return fetch(`${this.api}network/disassociate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({})
}).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
openAccesPoint() {
//not tested
2017-11-30 17:23:13 +01:00
return fetch(`${this.api}network/openap`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({})
}).then(parseFetch);
2016-04-21 15:52:23 +02:00
}
remove(ssid) {
2017-11-30 17:23:13 +01:00
return fetch(`${this.api}network/remove`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ssid })
}).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:23:13 +01:00
await fecth(`${this.api}network/alive`, { method: 'GET' }).then(parseFetch);
2016-04-21 15:52:23 +02:00
return true;
} catch(error) {
return false;
}
}
}