From 1deea79b50d7d44f9c4c69fb980a5b49e1c46529 Mon Sep 17 00:00:00 2001 From: Alexander James Wallar Date: Fri, 20 Sep 2013 18:02:45 +0100 Subject: [PATCH] Added a little bit to the JavaScript client --- bowtie/client/js/bowtie.js | 69 ++++++++++++++++++------ bowtie/client/python/bowtie.py | 12 ++--- bowtie/server/static/js/sensor_client.js | 2 +- 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/bowtie/client/js/bowtie.js b/bowtie/client/js/bowtie.js index 36c99f3..a2e9df7 100644 --- a/bowtie/client/js/bowtie.js +++ b/bowtie/client/js/bowtie.js @@ -2,7 +2,7 @@ ///////////////////////////////////////////////////////// // // Bowtie bindings for JavaScript -// +// // Github : http://github.com/wallarelvo/Bowtie // Contact : aw204@st-andrews.ac.uk // Website : www.bowtie.mobi @@ -45,7 +45,7 @@ bowtie.constants.BOWTIE_URL = "www.bowtie.mobi"; // // util.Callback // -// Class used to organize callback functions +// Class used to organize callback functions // ///////////////////////////////////////////////////////// @@ -70,9 +70,9 @@ bowtie.util.Callback.prototype = { ///////////////////////////////////////////////////////// // -// BowtieClient +// BowtieClient // -// Class used for making requests to the bowtie server +// Class used for making requests to the bowtie server // of your choosing // ///////////////////////////////////////////////////////// @@ -94,13 +94,13 @@ bowtie.BowtieClient.prototype = { nodeId, sensor ); - }, + }, getNode : function (groupId, nodeId) { return new bowtie.util.Callback( this.url, bowtie.prefixes.SENSORS, - groupId, + groupId, nodeId ); }, @@ -127,15 +127,15 @@ bowtie.BowtieClient.prototype = { type : "DELETE", url : ( - this.url + "/" + - bowtie.prefixes.SENSORS + "/" + - groupId + "/" + - nodeId + "/" + + this.url + "/" + + bowtie.prefixes.SENSORS + "/" + + groupId + "/" + + nodeId + "/" + sensor ) } ); - }, + }, deleteNode : function (groupId, nodeId) { return $.ajax( @@ -144,27 +144,66 @@ bowtie.BowtieClient.prototype = { url : ( this.url + "/" + - bowtie.prefixes.SENSORS + "/" + - groupId + "/" + + bowtie.prefixes.SENSORS + "/" + + groupId + "/" + nodeId ) } ); }, - deleteGroup : function (groupId, nodeId) { + deleteGroup : function (groupId) { return $.ajax( { type : "DELETE", url : ( this.url + "/" + - bowtie.prefixes.SENSORS + "/" + + bowtie.prefixes.SENSORS + "/" + groupId ) } ); } + + postSensor : function (data, groupId, nodeId, sensor) { + return $.ajax( + { + type : "POST", + + url : ( + this.url + "/" + + bowtie.prefixes.SENSORS + "/" + + groupId + "/" + + nodeId + "/" + + sensor + ), + + data : { + sensorData : JSON.stringify(data) + } + } + ); + }, + + postNode : function (data, groupId, nodeId) { + return $.ajax( + { + type : "POST", + + url : ( + this.url + "/" + + bowtie.prefixes.SENSORS + "/" + + groupId + "/" + + nodeId + ), + + data : { + sensorData : JSON.stringify(data) + } + } + ); + }, } diff --git a/bowtie/client/python/bowtie.py b/bowtie/client/python/bowtie.py index 4bb4f96..8ae3ee2 100644 --- a/bowtie/client/python/bowtie.py +++ b/bowtie/client/python/bowtie.py @@ -17,24 +17,24 @@ def __init__(self, url="http://www.bowtie.mobi/"): def getGroup(self, groupId): jsonStr = urllib2.urlopen( - self.url + "sensors/" + + self.url + "sensors/" + groupId ).read() return json.loads(jsonStr) def getNode(self, groupId, nodeId): jsonStr = urllib2.urlopen( - self.url + "sensors/" + - groupId + "/" + + self.url + "sensors/" + + groupId + "/" + nodeId ).read() return json.loads(jsonStr) def getSensor(self, groupId, nodeId, sensor): jsonStr = urllib2.urlopen( - self.url + "sensors/" + - groupId + "/" + - nodeId + "/" + + self.url + "sensors/" + + groupId + "/" + + nodeId + "/" + sensor ).read() return json.loads(jsonStr) diff --git a/bowtie/server/static/js/sensor_client.js b/bowtie/server/static/js/sensor_client.js index 7ac8f8b..c4f3dc5 100644 --- a/bowtie/server/static/js/sensor_client.js +++ b/bowtie/server/static/js/sensor_client.js @@ -344,7 +344,7 @@ function sendAjax() { ) }, - success : onSuccessAjax + success : onSuccessAjax } ); }