mickael9 avatar 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
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.