def api_request(self, call, params, kind='auth', http_call='get'):
"""
General API request. Generally, use the convenience functions below
:param kind: the type of request to make. 'auth' makes an authenticated call; 'basic' is unauthenticated
:param call: the API call to make
:param params: a dict of query parameters
:return: a json response, a BitXAPIError is thrown if the api returns with an error
"""
url = self.construct_url(call)
auth = self.auth if kind == 'auth' else None
if http_call == 'get':
response = requests.get(url, params, headers=self.headers, auth=auth)
elif http_call == 'post':
response = requests.post(url, data = params, headers=self.headers, auth=auth)
else:
raise ValueError('Invalid http_call parameter')
try:
result = response.json()
except ValueError:
result = {'error': 'No JSON content returned'}
if response.status_code != 200 or 'error' in result:
raise BitXAPIError(response)
else:
return result
评论列表
文章目录