From 9a4f1d5b09433f791b9e275a2f02b0c35d56c531 Mon Sep 17 00:00:00 2001 From: Dan Fellin Date: Thu, 18 Jan 2024 12:19:54 -0800 Subject: [PATCH] next --- polyapi/execute.py | 18 ++++++++++++++++++ polyapi/generate.py | 7 +++++++ 2 files changed, 25 insertions(+) create mode 100644 polyapi/execute.py diff --git a/polyapi/execute.py b/polyapi/execute.py new file mode 100644 index 0000000..96410f6 --- /dev/null +++ b/polyapi/execute.py @@ -0,0 +1,18 @@ +import requests +from requests import Response +from typing import List, Dict, Any, TypedDict +from polyapi.config import get_api_key_and_url +from polyapi.exceptions import PolyApiException +from typing import List, TypedDict +from typing_extensions import Required + + +def execute(function_type, function_id, data) -> Response: + api_key, api_url = get_api_key_and_url() + headers = {"Authorization": f"Bearer {api_key}"} + url = f"{api_url}/functions/{function_type}/{function_id}/execute" + resp = requests.post(url, json=data, headers=headers) + if resp.status_code != 200 and resp.status_code != 201: + error_content = resp.content.decode("utf-8", errors="ignore") + raise PolyApiException(f"{resp.status_code}: {error_content}") + return resp \ No newline at end of file diff --git a/polyapi/generate.py b/polyapi/generate.py index 872b1ce..07b86b4 100644 --- a/polyapi/generate.py +++ b/polyapi/generate.py @@ -24,8 +24,15 @@ def get_specs() -> List: def parse_specs(specs: List) -> List[Tuple[str, str, str, List[PropertySpecification], Dict[str, Any]]]: + # optional array of ids to include in the generated library + # currently just used for testing/development purposes + allowed_ids: List[str] = [] + api_functions = [] for spec in specs: + if allowed_ids and spec['id'] not in allowed_ids: + continue + if spec['type'] != 'apiFunction' and spec['type'] != 'serverFunction': # for now we only support api and server functions continue