Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af4f06b

Browse files
committed
Per new api
Signed-off-by: Vishal Rana <[email protected]>
1 parent 9de19fd commit af4f06b

File tree

4 files changed

+32
-125
lines changed

4 files changed

+32
-125
lines changed

labstack/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
from .client import Client
2-
from .jet import JetMessage, JetError
1+
from .client import Client

labstack/client.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,46 @@
11
import requests
2-
from .hub import _Hub
3-
from .jet import _Jet
2+
3+
API_URL = 'https://api.labstack.com'
44

55
class _Interceptor(requests.auth.AuthBase):
66
def __init__(self, api_key):
77
self.api_key = api_key
88

99
def __call__(self, r):
1010
r.headers['Authorization'] = 'Bearer ' + self.api_key
11-
r.headers['Content-Type'] = 'application/json; charset=utf-8'
1211
return r
1312

1413
class Client():
15-
def __init__(self, account_id, api_key):
16-
self.account_id = account_id
14+
def __init__(self, api_key):
1715
self.api_key = api_key
1816
self.interceptor = _Interceptor(api_key)
1917

20-
def hub(self, client_id):
21-
return _Hub(self.account_id, self.api_key, client_id)
18+
def image_compress(self, file=None):
19+
files = {'file': open(file, 'rb')}
20+
r = requests.post('{}/image/compress'.format(API_URL), auth=self.interceptor, files=files)
21+
data = r.json()
22+
if not 200 <= r.status_code < 300:
23+
raise APIError(data['code'], data['message'])
24+
return data
25+
26+
def image_resize(self, file=None, width=None, height=None, crop=None):
27+
files = {'file': open(file, 'rb')}
28+
data = {
29+
'width': width,
30+
'height': height,
31+
'crop': crop
32+
}
33+
r = requests.post('{}/image/resize'.format(API_URL), auth=self.interceptor,
34+
files=files, data=data)
35+
data = r.json()
36+
if not 200 <= r.status_code < 300:
37+
raise APIError(data['code'], data['message'])
38+
return data
2239

23-
def jet(self):
24-
return _Jet(self.interceptor)
25-
40+
class APIError(Exception):
41+
def __init__(self, code, message):
42+
self.code = code
43+
self.message = message
44+
45+
def __str__(self):
46+
return self.messag

labstack/hub.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

labstack/jet.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)