From 2b7cedfcf6996004601d12d36968bf445aa31742 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Fri, 17 Jul 2015 16:02:27 +0200 Subject: [PATCH] removed chaining in sub api's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit made no sense to be able to chain sub api’s --- example/app.js | 39 ++++++++++++++++++++------------------- example/index.html | 12 ++++++------ src/configapi.js | 11 ----------- src/infoapi.js | 6 ------ src/networkapi.js | 18 ------------------ src/printerapi.js | 14 -------------- src/restapi.js | 1 + src/sketchapi.js | 8 -------- src/systemapi.js | 2 -- src/updateapi.js | 8 -------- 10 files changed, 27 insertions(+), 92 deletions(-) diff --git a/example/app.js b/example/app.js index c3f117c..53167c1 100644 --- a/example/app.js +++ b/example/app.js @@ -1,18 +1,19 @@ import Doodle3DAPI from 'doodle3d-API'; import rest from 'rest-API'; -var api = "http://connect.doodle3d.com/api/"; +var api = 'http://connect.doodle3d.com/api/'; var known = []; function addBox (boxData) { - if (know.indexOf(boxData.localip) === -1) { + if (known.indexOf(boxData.localip) === -1) { known.push(boxData.localip); var row = document.createElement('tr'); - row.style.color = "gray"; + row.style.color = 'gray'; var id = document.createElement('td'); + var state = document.createElement('td'); var localIP = document.createElement('td'); var bed = document.createElement('td'); var bedTarget = document.createElement('td'); @@ -21,36 +22,36 @@ function addBox (boxData) { var hasControl = document.createElement('td'); var hotend = document.createElement('td'); var hotendTarget = document.createElement('td'); - var state = document.createElement('td'); var totalLines = document.createElement('td'); row.appendChild(id); row.appendChild(localIP); - row.appendChild(bed); - row.appendChild(bedTarget); - row.appendChild(bufferedLines); + row.appendChild(state); row.appendChild(currentLine); - row.appendChild(hasControl); + row.appendChild(bufferedLines); + row.appendChild(totalLines); row.appendChild(hotend); row.appendChild(hotendTarget); - row.appendChild(state); - row.appendChild(totalLines); + row.appendChild(bed); + row.appendChild(bedTarget); + row.appendChild(hasControl); id.innerHTML = boxData.wifiboxid; localIP.innerHTML = boxData.localip; - document.getElementById("table").appendChild(row); + document.getElementById('table').appendChild(row); var doodle3DAPI = new Doodle3DAPI(boxData.localip); doodle3DAPI.onconnect = function () { - row.style.color = "black"; + row.style.color = 'black'; }; doodle3DAPI.ondisconnect = function () { - row.style.color = "gray"; + row.style.color = 'gray'; }; doodle3DAPI.onupdate = function (data) { + console.log(data); state.innerHTML = data.state; - if (data.state === "idle") { + if (data.state !== 'disconnected' && data.state !== 'connecting' && data.state !== 'unknown') { bed.innerHTML = data.bed; bedTarget.innerHTML = data.bed_target; bufferedLines.innerHTML = data.buffered_lines; @@ -69,7 +70,7 @@ function addBox (boxData) { } function searchBoxes () { - rest.get(api + "list.php", function (error, boxes) { + rest.get(api + 'list.php', function (error, boxes) { if (error) { return; console.warn(error); @@ -87,11 +88,11 @@ setInterval(searchBoxes, 5000); searchBoxes(); addBox({ - localip: window.location.host + ":3000", - wifiboxid: "Node Server" + localip: window.location.host + ':3000', + wifiboxid: 'Node Server' }); addBox({ - localip: "192.168.5.1", - wifiboxid: "Wired Printer" + localip: '192.168.5.1', + wifiboxid: 'Wired Printer' }); \ No newline at end of file diff --git a/example/index.html b/example/index.html index 8357144..742b390 100644 --- a/example/index.html +++ b/example/index.html @@ -27,15 +27,15 @@ ID Local IP - Bed - Bed Target - Buffered Lines + State Current Line - Has Control + Buffered Lines + Total Lines Hotend Hotend Target - State - Total Lines + Bed + Bed Target + Has Control diff --git a/src/configapi.js b/src/configapi.js index b15599f..aa04414 100644 --- a/src/configapi.js +++ b/src/configapi.js @@ -8,31 +8,20 @@ export default class { get (keys, callback) { rest.get(this.api + 'config/?' + keys.join('=&') + '=', callback); - - return this; } getAll (callback) { rest.get(this.api + 'config/all', callback); - - return this; } set (data, callback) { var scope = this; rest.post(this.api + 'config', data, function (response) { - /*for (var i in response.validation) { - if (response.validation[i] === 'ok') { - scope[i] = data[i]; - } - }*/ if (callback !== undefined) { callback(response); } }); - - return this; } } \ No newline at end of file diff --git a/src/infoapi.js b/src/infoapi.js index 45d85fd..011413c 100644 --- a/src/infoapi.js +++ b/src/infoapi.js @@ -8,14 +8,10 @@ export default class { get (callback) { rest.get(this.api + 'info', callback); - - return this; } status (callback) { rest.get(this.api + 'info/status', callback); - - return this; } downloadLogFiles () { @@ -24,7 +20,5 @@ export default class { acces (callback) { rest.get(this.api + 'info/access', callback); - - return this; } } \ No newline at end of file diff --git a/src/networkapi.js b/src/networkapi.js index 920f762..dbb8e94 100644 --- a/src/networkapi.js +++ b/src/networkapi.js @@ -8,61 +8,43 @@ export default class { scan (callback) { rest.get(this.api + 'network/scan', callback); - - return this; } known (callback) { rest.get(this.api + 'network/known', callback); - - return this; } status (callback) { rest.get(this.api + 'network/status', callback); - - return this; } assosiate (data, callback) { rest.post(this.api + 'network/associate', data, callback); - - return this; } disassosiate (callback) { //not tested rest.post(this.api + 'network/disassociate', {}, callback); - - return this; } openAccesPoint (callback) { //not tested rest.post(this.api + 'network/openap', {}, callback); - - return this; } remove (ssid, callback) { rest.post(this.api + 'network/remove', { 'ssid': ssid }, callback); - - return this; } signin (callback) { rest.get(this.api + 'network/signin', callback); - - return this; } alive (callback) { rest.get(this.api + 'network/alive', callback); - - return this; } } \ No newline at end of file diff --git a/src/printerapi.js b/src/printerapi.js index 7721141..1455634 100644 --- a/src/printerapi.js +++ b/src/printerapi.js @@ -8,43 +8,29 @@ export default class { temperature (callback) { rest.get(this.api + 'printer/temperature', callback); - - return this; } progress (callback) { rest.get(this.api + 'printer/progress', callback); - - return this; } state (callback) { rest.get(this.api + 'printer/state', callback); - - return this; } listAll (callback) { rest.get(this.api + 'printer/listall', callback); - - return this; } heatup (callback) { rest.post(this.api + 'printer/heatup', {}, callback); - - return this; } print (data, callback) { rest.post(this.api + 'printer/print', data, callback); - - return this; } stop (data, callback) { rest.post(this.api + 'printer/stop', data, callback); - - return this; } } \ No newline at end of file diff --git a/src/restapi.js b/src/restapi.js index c52ea9b..6e0f2de 100644 --- a/src/restapi.js +++ b/src/restapi.js @@ -1,4 +1,5 @@ import $ from 'jquery'; +//in future remove jquery and use framework specificly for ajax calls or write own ajax calls export default { post (url, data, callback) { diff --git a/src/sketchapi.js b/src/sketchapi.js index d6fbe76..c60a087 100644 --- a/src/sketchapi.js +++ b/src/sketchapi.js @@ -8,27 +8,19 @@ export default class { getSketch (id, callback) { rest.get(this.api + 'sketch/?id=' + id, callback); - - return this; } set (data, callback) { rest.post(this.api + 'sketch', { 'data': data }, callback); - - return this; } status (callback) { rest.get(this.api + 'sketch/status', callback); - - return this; } clear (callback) { rest.post(this.api + 'sketch/clear', callback); - - return this; } } \ No newline at end of file diff --git a/src/systemapi.js b/src/systemapi.js index 2290bf0..98b22d1 100644 --- a/src/systemapi.js +++ b/src/systemapi.js @@ -8,7 +8,5 @@ export default class { versions (callback) { rest.get(this.api + 'system/fwversions', callback); - - return this; } } \ No newline at end of file diff --git a/src/updateapi.js b/src/updateapi.js index 1ae2df3..8aa9abf 100644 --- a/src/updateapi.js +++ b/src/updateapi.js @@ -8,31 +8,23 @@ export default class { status (callback) { rest.get(this.api + 'update/status', callback); - - return this; } download (callback) { //not tested rest.post(this.api + 'update/download', {}, callback); - - return this; } install (callback) { //not tested rest.post(this.api + 'update/install', {}, callback); - - return this; } clear (callback) { //not tested rest.post(this.api + 'update/clear', {}, callback); - - return this; } } \ No newline at end of file