Initial cleanup of the codebase

Change-Id: Idbc92ea3c2d7ee4d4807d1d83ceee9a299b9a9f7
diff --git a/service/APIFactory.py b/service/APIFactory.py
new file mode 100644
index 0000000..8be3073
--- /dev/null
+++ b/service/APIFactory.py
@@ -0,0 +1,39 @@
+import logging
+
+from flask import flash
+import requests.exceptions
+
+from config import URIBuilder
+
+__author__ = 'hanl'
+
+logging.basicConfig(level=logging.DEBUG)
+
+
+def get(path="", **kwargs):
+    return request('get', path, **kwargs)
+
+
+def post(path="", **kwargs):
+    path = URIBuilder().addPath(path).build()
+    if 'headers' in kwargs:
+        headers = kwargs['headers']
+        headers["Content-Type"] = "application/x-www-form-urlencoded"
+    else:
+        headers = {"Content-Type": "application/x-www-form-urlencoded"}
+    kwargs['headers'] = headers
+    return request('post', path, **kwargs)
+
+
+def request(method, path="", **kwargs):
+    path = URIBuilder().addPath(path).build()
+    if kwargs and path is not "":
+        try:
+            response = requests.request(method, path, **kwargs)
+        except requests.exceptions.RequestException as e:
+            print e
+            flash("Connection to API server could not be established", "danger")
+            return None
+        print "the response %i:%s" % (response.status_code, str(response.content))
+        return response
+    return None