-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
36 lines (30 loc) · 1.11 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
import logging
logger = logging.getLogger(__name__)
class Client:
def __init__(self, client_id, oauth_token):
self.BASE_URL = 'https://api.put.io/v2/'
self.UPLOAD_URL = 'https://upload.put.io/v2/'
self.OAUTH_TOKEN = oauth_token
self.CLIENT_ID = client_id
def call(self, url, action='', params=None, data=None, method=None,
files=None, stream=False):
if params is None:
params = {}
if method is None:
method = 'GET'
params['oauth_token'] = self.OAUTH_TOKEN
headers = {"Accept": "application/json"}
if action == 'upload':
url = self.UPLOAD_URL + url + action
else:
url = self.BASE_URL + url + action
try:
response = requests.request(method, url, params=params,
headers=headers, data=data,
files=files, stream=True)
response.raise_for_status()
except Exception as e:
logging.error(e, exc_info=True)
raise
return response