0
0
mirror of https://github.com/Doodle3D/Doodle3D-API synced 2024-11-14 00:17:55 +01:00

comply with linter

This commit is contained in:
casperlamboo 2016-04-21 15:44:20 +02:00
parent fbd5d5bf2d
commit 48693feaab
11 changed files with 61 additions and 108 deletions

View File

@ -1,19 +1,16 @@
import * as rest from '../rest.js';
export default class {
constructor (api) {
export default class Config {
constructor(api) {
this.api = api;
}
get (...keys) {
get(...keys) {
return rest.get(`${ this.api }config/?${ keys.join('=&') }=`);
}
getAll () {
getAll() {
return rest.get(`${ this.api }config/all`);
}
set (data) {
set(data) {
return rest.post(`${ this.api }config`, data);
}
}

View File

@ -1,23 +1,19 @@
import * as rest from '../rest.js';
export default class {
constructor (api) {
export default class Info {
constructor(api) {
this.api = api;
}
get () {
get() {
return rest.get(`${ this.api }info`);
}
status () {
status() {
return rest.get(`${ this.api }info/status`);
}
downloadLogFiles () {
downloadLogFiles() {
window.location = `${ this.api }info/logfiles`;
}
acces () {
acces() {
return rest.get(`${ this.api }info/access`);
}
}

View File

@ -1,51 +1,40 @@
import * as rest from '../rest.js';
export default class {
constructor (api) {
export default class Network {
constructor(api) {
this.api = api;
}
scan () {
scan() {
return rest.get(`${ this.api }network/scan`);
}
known () {
known() {
return rest.get(`${ this.api }network/known`);
}
status () {
status() {
return rest.get(`${ this.api }network/status`);
}
assosiate (ssid, phrase, recreate = false) {
assosiate(ssid, phrase, recreate = false) {
const data = { ssid, recreate, phrase };
return rest.post(`${ this.api }network/associate`, data);
}
disassociate () {
disassociate() {
//not tested
return rest.post(`${ this.api }network/disassociate`, {});
}
openAccesPoint () {
openAccesPoint() {
//not tested
return rest.post(`${ this.api }network/openap`, {});
}
remove (ssid) {
remove(ssid) {
return rest.post(`${ this.api }network/remove`, {
'ssid': ssid
});
}
signin () {
signin() {
return rest.get(`${ this.api }network/signin`);
}
async alive () {
async alive() {
try {
await rest.get(`${ this.api }network/alive`);

View File

@ -1,37 +1,30 @@
import * as rest from '../rest.js';
export default class {
constructor (api) {
export default class Printer {
constructor(api) {
this.api = api;
}
temperature () {
temperature() {
return rest.get(`${ this.api }printer/temperature`);
}
progress () {
progress() {
return rest.get(`${ this.api }printer/progress`);
}
state () {
state() {
return rest.get(`${ this.api }printer/state`);
}
listAll () {
listAll() {
return rest.get(`${ this.api }printer/listall`);
}
heatup () {
heatup() {
return rest.post(`${ this.api }printer/heatup`, {});
}
print (gcode = '', first = false, start = false, last) {
print(gcode = '', first = false, start = false, last) {
const data = { gcode, first, start, last };
return rest.post(`${ this.api }printer/print`, data);
}
stop (gcode = '') {
stop(gcode = '') {
const data = { gcode };
return rest.post(`${ this.api }printer/stop`, data);

View File

@ -1,23 +1,19 @@
import * as rest from '../rest.js';
export default class {
constructor (api) {
export default class Sketch {
constructor(api) {
this.api = api;
}
getSketch (id) {
getSketch(id) {
return rest.get(`${ this.api }sketch/?id=${ id }`);
}
set (data = '') {
set(data = '') {
return rest.post(`${ this.api }sketch`, { data });
}
status () {
status() {
return rest.get(`${ this.api }sketch/status`);
}
clear () {
clear() {
return rest.post(`${ this.api }sketch/clear`);
}
}

View File

@ -1,11 +1,10 @@
import * as rest from '../rest.js';
export default class {
constructor (api) {
export default class System {
constructor(api) {
this.api = api;
}
versions () {
versions() {
return rest.get(`${ this.api }system/fwversions`);
}
}

View File

@ -1,29 +1,22 @@
import * as rest from '../rest.js';
export default class {
constructor (api) {
export default class Update {
constructor(api) {
this.api = api;
}
status () {
status() {
return rest.get(`${ this.api }update/status`);
}
download () {
download() {
//not tested
return rest.post(`${ this.api }update/download`, {});
}
install () {
install() {
//not tested
return rest.post(`${ this.api }update/install`, {});
}
clear () {
clear() {
//not tested
return rest.post(`${ this.api }update/clear`, {});
}
}

View File

@ -9,7 +9,7 @@ import SystemAPI from './api/system.js';
import UpdateAPI from './api/update.js';
export default class Doodle3DBox extends EventDispatcher {
constructor (boxData) {
constructor(boxData) {
super();
this.boxData = boxData;
@ -31,8 +31,7 @@ export default class Doodle3DBox extends EventDispatcher {
this.system = new SystemAPI(this.api);
this.update = new UpdateAPI(this.api);
}
setAutoUpdate (autoUpdate = true, updateInterval = 1000) {
setAutoUpdate(autoUpdate = true, updateInterval = 1000) {
this.updateInterval = updateInterval;
if (this.autoUpdate === autoUpdate) return;
@ -41,8 +40,7 @@ export default class Doodle3DBox extends EventDispatcher {
return this;
}
async checkAlive () {
async checkAlive() {
const alive = await this.network.alive();
if (alive !== this.alive) {
@ -53,8 +51,7 @@ export default class Doodle3DBox extends EventDispatcher {
this.alive = alive;
return alive;
}
async sendGCode (gcode) {
async sendGCode(gcode) {
const printerState = await this.printer.state();
if (printerState.state !== 'idle') {
throw `Cannot print, print state is ${ printerState.state }`;
@ -78,8 +75,7 @@ export default class Doodle3DBox extends EventDispatcher {
lastIndex = index + 1; //skip next \n
}
}
async _update () {
async _update() {
while (this.autoUpdate) {
if (this.alive) {
try {
@ -96,8 +92,7 @@ export default class Doodle3DBox extends EventDispatcher {
await sleep(this.updateInterval);
}
}
async _sendBatch (gcode, start) {
async _sendBatch(gcode, start) {
try {
const response = await this.printer.print(gcode, start, start);
// maybe do something with failing response

View File

@ -4,7 +4,7 @@ import EventDispatcher from 'casperlamboo/EventDispatcher';
import { sleep } from './utils.js';
export default class Doodle3DManager extends EventDispatcher {
constructor () {
constructor() {
super();
this.api = 'http://connect.doodle3d.com/api/';
@ -22,8 +22,7 @@ export default class Doodle3DManager extends EventDispatcher {
this.autoUpdate = false;
}
setAutoUpdate (autoUpdate = true, updateInterval = 1000) {
setAutoUpdate(autoUpdate = true, updateInterval = 1000) {
this.updateInterval = updateInterval;
if (this.autoUpdate === autoUpdate) return;
@ -32,16 +31,14 @@ export default class Doodle3DManager extends EventDispatcher {
return this;
}
async _update () {
async _update() {
while (this.autoUpdate) {
await this._checkNew();
await sleep(this.updateInterval);
}
}
async _checkNew () {
async _checkNew() {
let boxes;
try {
boxes = await rest.get(`${ this.api }list.php`);
@ -76,14 +73,12 @@ export default class Doodle3DManager extends EventDispatcher {
this.dispatchEvent({ type: 'boxeschanged', boxes: this.boxes });
}
}
_addBox (box) {
_addBox(box) {
this.boxes.push(box);
this.dispatchEvent({ type: 'boxappeared', box });
}
_removeBox (box) {
_removeBox(box) {
const index = this.boxes.indexOf(box);
if (index !== -1) {
this.boxes.splice(index, 1);

View File

@ -3,11 +3,11 @@ import $ from 'jquery';
const GET_TIMEOUT = 5000;
const POST_TIMEOUT = 10000;
export function get (url) {
export function get(url) {
return send(url, 'GET');
}
export function post (url, data) {
export function post(url, data) {
return send(url, 'POST', data);
}

View File

@ -1,4 +1,4 @@
export function sleep (time) {
export function sleep(time) {
return new Promise((resolve, reject) => {
setTimeout(resolve, time);
});