fix posts

This commit is contained in:
casperlamboo 2018-01-25 17:29:51 +01:00
parent 5b7f8300bd
commit 5a11fafb0c
5 changed files with 60 additions and 65 deletions

View File

@ -11,10 +11,11 @@ export default class Config {
return fetch(`${this.api}config/all`, { method: 'GET' }).then(parseFetch); return fetch(`${this.api}config/all`, { method: 'GET' }).then(parseFetch);
} }
set(data) { set(data) {
return fetch(`${this.api}config`, { const body = new URLSearchParams();
method: 'POST', for (const key in data) {
headers: { 'Content-Type': 'application/json' }, body.append(key, data[key]);
body: JSON.stringify(data) }
}).then(parseFetch);
return fetch(`${this.api}config`, { method: 'POST', body }).then(parseFetch);
} }
} }

View File

@ -14,34 +14,30 @@ export default class Network {
return fecth(`${this.api}network/status`, { method: 'GET' }).then(parseFetch); return fecth(`${this.api}network/status`, { method: 'GET' }).then(parseFetch);
} }
assosiate(ssid, phrase, recreate = false) { assosiate(ssid, phrase, recreate = false) {
return fetch(`${this.api}network/associate`, { const body = new URLSearchParams();
method: 'POST', body.append('ssid', ssid);
headers: { 'Content-Type': 'application/json' }, body.append('phrase', phrase);
body: JSON.stringify({ ssid, phrase, recreate }) body.append('recreate', recreate);
}).then(parseFetch);
return fetch(`${this.api}network/associate`, { method: 'POST', body }).then(parseFetch);
} }
disassociate() { disassociate() {
//not tested //not tested
return fetch(`${this.api}network/disassociate`, { const body = new URLSearchParams();
method: 'POST',
headers: { 'Content-Type': 'application/json' }, return fetch(`${this.api}network/disassociate`, { method: 'POST', body }).then(parseFetch);
body: JSON.stringify({})
}).then(parseFetch);
} }
openAccesPoint() { openAccesPoint() {
//not tested //not tested
return fetch(`${this.api}network/openap`, { const body = new URLSearchParams();
method: 'POST',
headers: { 'Content-Type': 'application/json' }, return fetch(`${this.api}network/openap`, { method: 'POST', body }).then(parseFetch);
body: JSON.stringify({})
}).then(parseFetch);
} }
remove(ssid) { remove(ssid) {
return fetch(`${this.api}network/remove`, { const body = new URLSearchParams();
method: 'POST', body.append('ssid', ssid);
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ssid }) return fetch(`${this.api}network/remove`, { method: 'POST', body }).then(parseFetch);
}).then(parseFetch);
} }
signin() { signin() {
return fecth(`${this.api}network/signin`, { method: 'GET' }).then(parseFetch); return fecth(`${this.api}network/signin`, { method: 'GET' }).then(parseFetch);

View File

@ -17,25 +17,32 @@ export default class Printer {
return fetch(`${this.api}printer/listall`, { method: 'GET' }).then(parseFetch); return fetch(`${this.api}printer/listall`, { method: 'GET' }).then(parseFetch);
} }
heatup() { heatup() {
return fetch(`${this.api}printer/heatup`, { const body = new URLSearchParams();
method: 'POST',
headers: { 'Content-Type': 'application/json' }, return fetch(`${this.api}printer/heatup`, { method: 'POST', body }).then(parseFetch);
body: JSON.stringify({}) }
}).then(parseFetch); fetch(id, startCode = 'g28', endCode = 'g28') {
const body = new URLSearchParams();
body.append('id', id);
body.append('start_code', startCode);
body.append('end_code', endCode);
return fetch(`${this.api}printer/fetch`, { method: 'POST', body }).then(parseFetch);
} }
print(gcode = '', first = false, start = false, last) { print(gcode = '', first = false, start = false, last) {
return fetch(`${this.api}printer/print`, { const body = new URLSearchParams();
method: 'POST', body.append('gcode', gcode);
headers: { 'Content-Type': 'application/json' }, body.append('first', first);
body: JSON.stringify({ gcode, first, start, last }) body.append('start', start);
}).then(parseFetch); body.append('last', last);
return fetch(`${this.api}printer/print`, { method: 'POST', body }).then(parseFetch);
} }
stop(gcode = '') { stop(gcode = '') {
return fetch(`${this.api}printer/stop`, { const body = new URLSearchParams();
method: 'POST', body.append('gcode', gcode);
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ gcode, first, start, last }) return fetch(`${this.api}printer/stop`, { method: 'POST', body }).then(parseFetch);
}).then(parseFetch);
} }
async _sendBatch(gcode, start, index) { async _sendBatch(gcode, start, index) {
try { try {

View File

@ -8,20 +8,17 @@ export default class Sketch {
return fetch(`${this.api}sketch/?id=${id}`, { method: 'GET' }).then(parseFetch); return fetch(`${this.api}sketch/?id=${id}`, { method: 'GET' }).then(parseFetch);
} }
set(data = '') { set(data = '') {
return fetch(`${this.api}sketch`, { const body = new URLSearchParams();
method: 'POST', body.append('data', data);
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ data }) return fetch(`${this.api}sketch`, { method: 'POST', body }).then(parseFetch);
}).then(parseFetch);
} }
status() { status() {
return fetch(`${this.api}sketch/status`, { method: 'GET' }).then(parseFetch); return fetch(`${this.api}sketch/status`, { method: 'GET' }).then(parseFetch);
} }
clear() { clear() {
return fetch(`${this.api}sketch/clear`, { const body = new URLSearchParams();
method: 'POST',
headers: { 'Content-Type': 'application/json' }, return fetch(`${this.api}sketch/clear`, { method: 'POST', body }).then(parseFetch);
body: JSON.stringify({})
}).then(parseFetch);
} }
} }

View File

@ -9,26 +9,20 @@ export default class Update {
} }
download() { download() {
//not tested //not tested
return fetch(`${this.api}update/download`, { const body = new URLSearchParams();
method: 'POST',
headers: { 'Content-Type': 'application/json' }, return fetch(`${this.api}update/download`, { method: 'POST', body }).then(parseFetch);
body: JSON.stringify({})
}).then(parseFetch);
} }
install() { install() {
//not tested //not tested
return fetch(`${this.api}update/install`, { const body = new URLSearchParams();
method: 'POST',
headers: { 'Content-Type': 'application/json' }, return fetch(`${this.api}update/install`, { method: 'POST', body }).then(parseFetch);
body: JSON.stringify({})
}).then(parseFetch);
} }
clear() { clear() {
//not tested //not tested
return fetch(`${this.api}update/clear`, { const body = new URLSearchParams();
method: 'POST',
headers: { 'Content-Type': 'application/json' }, return fetch(`${this.api}update/clear`, { method: 'POST', body }).then(parseFetch);
body: JSON.stringify({})
}).then(parseFetch);
} }
} }