summaryrefslogtreecommitdiff
path: root/server/buttonDispatcher.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/buttonDispatcher.py')
-rw-r--r--server/buttonDispatcher.py44
1 files changed, 24 insertions, 20 deletions
diff --git a/server/buttonDispatcher.py b/server/buttonDispatcher.py
index 59672d6..8938288 100644
--- a/server/buttonDispatcher.py
+++ b/server/buttonDispatcher.py
@@ -8,38 +8,26 @@ from lib import uuid
@cherrypy.expose
class ButtonDispatcher(Dispatcher):
+ @cherrypy.tools.json_out()
def GET(self, id=None):
# GET /button - return all buttons
if id is None:
- return self.response(loadAll())
+ return loadAll()
# GET /button/{id} - return single button
self.validate_uuid(id)
button = Button()
- return self.response(button.loadById(id).toJSON())
+ return button.loadById(id).toDict()
- def POST(self, id, status):
- # POST /button/{id}?status={} - updates button status
- self.validate_uuid(id)
-
- button = Button()
- button.loadById(id)
-
- cherrypy.log("Updating status to " + str(status))
- # TODO validate status
- button.status = int(status)
- button.save()
-
- return self.response(button.toJSON())
-
- def PUT(self, id=None):
+ @cherrypy.tools.json_out()
+ def POST(self, id=None):
button = Button()
# PUT /button - creates button
if id is None:
button.id = uuid.gen()
- return self.response(button.save().toJSON())
+ return button.save().toDict()
# PUT /button/{id} - presses button
else:
@@ -48,12 +36,28 @@ class ButtonDispatcher(Dispatcher):
button.save()
- return self.response(button.toJSON())
+ return button.toDict()
+
+ @cherrypy.tools.json_out()
+ def PUT(self, id, status):
+ # POST /button/{id}?status={} - updates button status
+ self.validate_uuid(id)
+
+ button = Button()
+ button.loadById(id)
+
+ cherrypy.log("Updating status to " + str(status))
+ # TODO validate status
+ button.status = int(status)
+ button.save()
+
+ return button.toDict()
+ @cherrypy.tools.json_out()
def DELETE(self, id):
# DELETE /button/{id} - deletes button
button = Button()
button.loadById(id)
button.delete()
- return self.response(True)
+ return True