Commits

mickael9 committed 4d43297

Start working on ge.tt API wrappers.

Comments (0)

Files changed (1)

+import json
+from urllib.request import urlopen
+from urllib.parse import urlencode
+from urllib.error import HTTPError
+
+API_BASE = 'https://open.ge.tt/1/'
+API_KEY = 't05kormjprb2o6rm8f8wmts2thjjor'
+
+class APIError(Exception):
+    pass
+
+def _post_request(path, **kwargs):
+    input_data = json.dumps(kwargs).encode('utf-8')
+    
+    try:
+        resp = urlopen(API_BASE + path, input_data).read()
+    except HTTPError as ex:
+        resp = ex.read()
+    
+    result = json.loads(resp.decode('utf-8'))
+
+    if "error" in result:
+        raise APIError(result["error"])
+
+class User(object):
+    def _load(result):
+        self.accesstoken = result['accesstoken']
+        self.storage_used = result['storage']['used']
+        self.storage_limit = result['storage']['limit']
+
+    def login_auth(self, email, password):
+        result = _post_request('users/login', apikey=API_KEY, email=email, password=password)
+
+    def login_token(self, refreshtoken):
+        result = _post_request('users/login', refreshtoken=refreshtoken)
+
+
+class Share(object):
+    pass
+
+class File(object):
+    pass
+