import os
import typing
import requests
[docs]def call_api(
method: str,
url: str,
headers: typing.Optional[typing.Dict[str, str]] = None,
params: typing.Optional[typing.Union[typing.Dict[str, typing.Any], str]] = None,
data: typing.Optional[typing.Union[typing.Dict[str, str], str]] = None,
) -> typing.Union[
typing.Dict[str, typing.Any], typing.List[typing.Dict[str, typing.Any]]
]:
"""Generic method to interact with strike API endpoints
Args:
method (str): HTTP Method
url (str): Fully qualifed url to interact with a strike endpoint
headers (typing.Optional[typing.Dict[str, str]], optional): HTTP Headers. Defaults to None.
params (typing.Optional[typing.Union[typing.Dict[str, typing.Any], str]], optional): params to pass to Strike as query string. Defaults to None.
data (typing.Optional[typing.Union[typing.Dict[str, str], str]], optional): Data to pass to Strike as body. Defaults to None.
Returns:
typing.Union[ typing.Dict[str, typing.Any], typing.List[typing.Dict[str, typing.Any]] ]: response from api call
"""
headers = set_default_headers(headers)
response = requests.request(method, url, headers=headers, params=params, data=data)
response.raise_for_status()
if response.content:
return response.json()
else:
return {}