summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorngharo <nick@ngha.ro>2017-12-13 00:19:14 -0600
committerngharo <nick@ngha.ro>2017-12-13 00:19:14 -0600
commitdf3f5844ea334a83955efbab7f58861ae6ccd763 (patch)
tree3ec77c93fa1527c2212fefccc789a552898dc417
downloadimOk-www-df3f5844ea334a83955efbab7f58861ae6ccd763.tar.xz
imOk-www-df3f5844ea334a83955efbab7f58861ae6ccd763.zip
Starting to build out cherrypy API
-rw-r--r--.gitignore2
-rw-r--r--data/imok.dbbin0 -> 12288 bytes
-rw-r--r--data/sessions/.keepme0
-rw-r--r--server/button.py41
-rw-r--r--server/lib/database.py5
-rw-r--r--server/lib/uuid.py9
-rw-r--r--server/server.conf7
-rw-r--r--server/server.py20
-rw-r--r--www/index.htm13
-rw-r--r--www/j.js2
-rw-r--r--www/s.css3
11 files changed, 102 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..24c2769
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.pyc
+data/sessions/session-*
diff --git a/data/imok.db b/data/imok.db
new file mode 100644
index 0000000..b3b3d18
--- /dev/null
+++ b/data/imok.db
Binary files differ
diff --git a/data/sessions/.keepme b/data/sessions/.keepme
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/data/sessions/.keepme
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'
diff --git a/server/lib/database.py b/server/lib/database.py
new file mode 100644
index 0000000..d4e47e6
--- /dev/null
+++ b/server/lib/database.py
@@ -0,0 +1,5 @@
+import sqlite3
+
+def connect():
+ connection = sqlite3.connect('../data/imok.db')
+ return connection.cursor()
diff --git a/server/lib/uuid.py b/server/lib/uuid.py
new file mode 100644
index 0000000..9558f21
--- /dev/null
+++ b/server/lib/uuid.py
@@ -0,0 +1,9 @@
+from uuid import UUID
+
+def validate(uuid_to_test, version=4):
+ try:
+ uuid_obj = UUID(uuid_to_test, version=version)
+ except:
+ return False
+
+ return str(uuid_obj) == uuid_to_test
diff --git a/server/server.conf b/server/server.conf
new file mode 100644
index 0000000..863cb58
--- /dev/null
+++ b/server/server.conf
@@ -0,0 +1,7 @@
+[/]
+tools.sessions.on = True
+tools.sessions.storage_class = cherrypy.lib.sessions.FileSession
+tools.sessions.storage_path = "/home/ngharo/src/imOk/data/sessions"
+tools.sessions.timeout = 60
+tools.sessions.secure = True
+tools.sessions.httponly = True
diff --git a/server/server.py b/server/server.py
new file mode 100644
index 0000000..9ec12a1
--- /dev/null
+++ b/server/server.py
@@ -0,0 +1,20 @@
+import string
+from time import time
+
+import cherrypy
+import uuid
+
+class Root(object):
+ @cherrypy.expose
+ def index(self):
+ return 'Sup?'
+
+from button import Button
+
+cherrypy.tree.mount(Root())
+cherrypy.tree.mount(Button(), '/button', {
+ '/': {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}
+})
+
+cherrypy.engine.start()
+cherrypy.engine.block()
diff --git a/www/index.htm b/www/index.htm
new file mode 100644
index 0000000..9ba7132
--- /dev/null
+++ b/www/index.htm
@@ -0,0 +1,13 @@
+<!doctype html>
+<html>
+ <head>
+ <link href="s.css" type="text/css"/>
+ </head>
+ <body>
+ <div id="container">
+
+ </div>
+
+ <script src="app.js"></script>
+ </body>
+</html>
diff --git a/www/j.js b/www/j.js
new file mode 100644
index 0000000..8aeadc5
--- /dev/null
+++ b/www/j.js
@@ -0,0 +1,2 @@
+function Button() {
+}
diff --git a/www/s.css b/www/s.css
new file mode 100644
index 0000000..699a279
--- /dev/null
+++ b/www/s.css
@@ -0,0 +1,3 @@
+body {
+ margin: 0;
+}