diff options
author | ngharo <nick@ngha.ro> | 2017-12-13 00:19:14 -0600 |
---|---|---|
committer | ngharo <nick@ngha.ro> | 2017-12-13 00:19:14 -0600 |
commit | df3f5844ea334a83955efbab7f58861ae6ccd763 (patch) | |
tree | 3ec77c93fa1527c2212fefccc789a552898dc417 /server/button.py | |
download | imOk-www-df3f5844ea334a83955efbab7f58861ae6ccd763.tar.xz imOk-www-df3f5844ea334a83955efbab7f58861ae6ccd763.zip |
Starting to build out cherrypy API
Diffstat (limited to 'server/button.py')
-rw-r--r-- | server/button.py | 41 |
1 files changed, 41 insertions, 0 deletions
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' |