ADD: url params for apis for multi api req

This commit is contained in:
Chris Lee
2015-06-05 13:50:13 -04:00
parent 5623f6de90
commit 6e0ac4cd5d
7 changed files with 13 additions and 14 deletions
+5 -6
View File
@@ -8,7 +8,7 @@ from indicoio import config
B64_PATTERN = re.compile("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)")
def api_handler(arg, cloud, api, batch=False, api_key=None, **kwargs):
def api_handler(arg, cloud, api, url_params = {"batch":False, "api_key":None}, **kwargs):
data = {'data': arg}
data.update(**kwargs)
json_data = json.dumps(data)
@@ -21,12 +21,11 @@ def api_handler(arg, cloud, api, batch=False, api_key=None, **kwargs):
# default to indico public cloud
host = config.PUBLIC_API_HOST
if not api_key:
api_key = config.api_key
url = config.url_protocol + "//%s/%s" % (host, api)
url = url + "/batch" if batch else url
url += "?key=%s" % api_key
url = url + "/batch" if url_params.get("batch", False) else url
url += "?key=%s" % (url_params.get("api_key", None) or config.api_key)
if "apis" in url_params:
url += "&apis=%s" % ",".join(url_params["apis"])
response = requests.post(url, data=json_data, headers=JSON_HEADERS)
if response.status_code == 503 and cloud != None:
+1 -1
View File
@@ -27,7 +27,7 @@ def multi(data, type, apis, available, batch=False, **kwargs):
)
# Convert client api names to server names before sending request
apis = map(CLIENT_SERVER_MAP.get, apis)
result = api_handler(data, apis=apis, batch=batch, **kwargs)
result = api_handler(data, url_params = {"apis":apis, "batch":batch}, **kwargs)
return handle_response(result)
def handle_response(result):