From df3f5844ea334a83955efbab7f58861ae6ccd763 Mon Sep 17 00:00:00 2001 From: ngharo Date: Wed, 13 Dec 2017 00:19:14 -0600 Subject: Starting to build out cherrypy API --- server/button.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 server/button.py (limited to 'server/button.py') diff --git a/server/button.py b/server/button.py new file mode 100644 index 0000000..8530768 --- /dev/null +++ b/server/button.py @@ -0,0 +1,41 @@ +import cherrypy +import sqlite3 +import json +from lib import uuid +from lib import database + +@cherrypy.expose +class Button(object): + STATUS_INVENTORY = 0 + STATUS_ACTIVE = 1 + STATUS_INACTIVE = 2 + STATUS_SUSPENDED = 3 + STATUS_DEAD = 4 + + def __init__(self): + self.id = None + self.status = 0 + + def GET(self, id): + if not uuid.validate(id): + return cherrypy.HTTPError(404) + + db = database.connect() + db.execute("SELECT id,status FROM buttons WHERE id = ?" , (str(id),)) + return db.fetchone() +# return json.dumps({ +# 'id': self.id, +# 'status': self.status +# }) + + def POST(self): + return 'POST BIUTTON' + + def PUT(self, id): + if uuid.validate(id): + return self.GET(id) + + raise cherrypy.HTTPError(400, 'Invalid UUID') + + def DELETE(self): + return 'DELETE BUTTON' -- cgit v1.2.3