Add support for optional arguments to API

This commit is contained in:
Madison May
2014-12-18 16:10:36 -05:00
parent 8b9e0841a0
commit 6c23d0d7ee
11 changed files with 35 additions and 34 deletions
+6 -4
View File
@@ -20,15 +20,17 @@ def auth_query():
return (email, password)
def api_handler(arg, url, batch=False, auth=None):
data_dict = json.dumps({'data': arg})
def api_handler(arg, url, batch=False, auth=None, **kwargs):
data = {'data': arg}
data.update(**kwargs)
json_data = json.dumps(data)
if batch:
url += "/batch"
if not auth:
auth = auth_query()
response = requests.post(url, data=data_dict, headers=JSON_HEADERS, auth=auth).json()
response = requests.post(url, data=json_data, headers=JSON_HEADERS, auth=auth).json()
results = response.get('results', False)
if not results:
if results is False:
error = response.get('error')
raise ValueError(error)
return results