Module pyrule_compendium.utils
Expand source code
from typing import Union, Any
from requests import get
class types:
entry = Union[int, str]
timeout = Union[int, float, None]
def api_req(url: str, timeout: types.timeout=None) -> Union[list, dict]: return get(url, timeout=timeout).json()["data"]
class api():
def __init__(self, base_url: str): self.base_url = base_url
def endpoint(self, target_endpoint: str) -> str: return f"{self.base_url}{target_endpoint}"
def request(self, endpoint: str, timeout: types.timeout=None) -> Any: return api_req(f"{self.endpoint(endpoint)}", timeout)
Functions
def api_req(url: str, timeout: Union[int, float, None] = None) ‑> Union[dict, list]
-
Expand source code
def api_req(url: str, timeout: types.timeout=None) -> Union[list, dict]: return get(url, timeout=timeout).json()["data"]
Classes
class api (base_url: str)
-
Expand source code
class api(): def __init__(self, base_url: str): self.base_url = base_url def endpoint(self, target_endpoint: str) -> str: return f"{self.base_url}{target_endpoint}" def request(self, endpoint: str, timeout: types.timeout=None) -> Any: return api_req(f"{self.endpoint(endpoint)}", timeout)
Methods
def endpoint(self, target_endpoint: str) ‑> str
-
Expand source code
def endpoint(self, target_endpoint: str) -> str: return f"{self.base_url}{target_endpoint}"
def request(self, endpoint: str, timeout: Union[int, float, None] = None) ‑> Any
-
Expand source code
def request(self, endpoint: str, timeout: types.timeout=None) -> Any: return api_req(f"{self.endpoint(endpoint)}", timeout)
class types
-
Expand source code
class types: entry = Union[int, str] timeout = Union[int, float, None]
Class variables
var entry
var timeout