0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-11-13 01:57:56 +01:00

added API wrappers

This commit is contained in:
Rick Companje 2017-06-20 21:42:18 +02:00
parent 2d2b6cf32d
commit 9bf4b90b2f
4 changed files with 130 additions and 4 deletions

View File

@ -13,7 +13,7 @@ function ConfigAPI() {
var _wifiboxURL;
var _wifiboxCGIBinURL;
var _timeoutTime = 3000;
var _timeoutTime = 3000;
var _saveSettingsTimeoutTime = 8000;
var _self = this;
@ -33,13 +33,13 @@ function ConfigAPI() {
timeout: _timeoutTime,
success: function(response){
if(response.status == "error" || response.status == "fail") {
if(failedHandler) failedHandler(response);
if (failedHandler) failedHandler(response);
} else {
completeHandler(response.data);
if (completeHandler) completeHandler(response.data);
}
}
}).fail(function() {
if(failedHandler) failedHandler();
if (failedHandler) failedHandler();
});
};
this.load = function(targetSettings,completeHandler,failedHandler) {

View File

@ -58,4 +58,24 @@ function InfoAPI() {
if(failedHandler) failedHandler();
});
};
this.getStatus = function(completeHandler,failedHandler) {
$.ajax({
url: _wifiboxURL + "/info/status",
type: "GET",
dataType: 'json',
timeout: _timeoutTime,
success: function(response){
if (response.status == "error" || response.status == "fail") {
if (failedHandler) failedHandler(response);
} else {
if (completeHandler) completeHandler(response.data);
}
}
}).fail(function() {
if (failedHandler) failedHandler();
});
};
}

View File

@ -46,4 +46,72 @@ function PrinterAPI() {
if(failedHandler) failedHandler();
});
};
this.fetch = function(data, completeHandler,failedHandler) {
console.log("fetch",_wifiboxURL,data);
$.ajax({
url: _wifiboxURL + "/printer/fetch",
type: "POST",
dataType: 'json',
data: data,
timeout: _timeoutTime,
success: function(response){
console.log("printerAPI.fetch response=",response);
if(response.status == "error" || response.status == "fail") {
if (failedHandler) failedHandler(response);
} else {
if (completeHandler) completeHandler(response.data);
}
}
}).fail(function() {
if(failedHandler) failedHandler();
});
};
this.print = function(data, completeHandler,failedHandler) {
// data = { "gcode": gcode, "first": first, "start": start },
console.log("print",_wifiboxURL,data);
$.ajax({
url: _wifiboxURL + "/printer/print",
type: "POST",
dataType: 'json',
data: data,
timeout: _timeoutTime,
success: function(response){
console.log("printerAPI.print response=",response);
if(response.status == "error" || response.status == "fail") {
if (failedHandler) failedHandler(response);
} else {
if (completeHandler) completeHandler(response.data);
}
}
}).fail(function() {
if (failedHandler) failedHandler();
});
};
this.stop = function(data, completeHandler, failedHandler) {
console.log("stop",_wifiboxURL,data);
$.ajax({
url: _wifiboxURL + "/printer/stop",
type: "POST",
dataType: 'json',
data: data,
timeout: _timeoutTime,
success: function(response){
console.log("printerAPI.stop response=",response);
if(response.status == "error" || response.status == "fail") {
if (failedHandler) failedHandler(response);
} else {
if (completeHandler) completeHandler(response.data);
}
}
}).fail(function() {
if (failedHandler) failedHandler();
});
};
}

38
js/api/ServerAPI.js Normal file
View File

@ -0,0 +1,38 @@
/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
* Copyright (c) 2013, Doodle3D
* This software is licensed under the terms of the GNU GPL v2 or later.
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
*/
function ServerAPI() {
var _apiURL = "";
var _timeoutTime = 6000;
this.init = function(url) {
_apiURL = url;
}
this.getInfo = function(uuid, completeHandler, failedHandler) {
console.log("ServerAPI:getInfo");
$.ajax({
url: _apiURL + "/info/" + uuid,
type: "GET",
dataType: 'json',
timeout: _timeoutTime,
cache: false,
success: function(response) {
if (completeHandler) completeHandler(response);
}
}).fail(function(response) {
console.log("fail");
if (failedHandler) failedHandler();
});
};
// '/fetch/'+uid.value+'/'+line.value;
}