blob: 5dac61c8c98e2da59871e550021a0b1f25c4d4d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import json
import cherrypy
from button import loadAll, Button
from lib import uuid
@cherrypy.expose
class ButtonDispatcher(object):
def GET(self, id=None):
if id is None:
return json.dumps(loadAll())
elif uuid.validate(id):
button = Button()
return button.loadById(id).toJSON()
else:
raise cherrypy.HTTPError(400, 'Invalid ID')
def POST(self, id, status):
if not uuid.validate(id):
raise cherrypy.HTTPError(401)
button = Button()
button.loadById(id)
cherrypy.log("Updating status to " + str(status))
button.status = status
button.save()
return button.toJSON()
def PUT(self):
cherrypy.log('Generating new button')
button = Button()
button.id = uuid.gen()
return button.save().toJSON()
def DELETE(self):
return 'DELETE BUTTON'
|