mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-08-04 12:33:47 +08:00
ADD: url params for apis for multi api req
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user