(3.0.0) cleaned up uv dependencies for pep 735, made a backwards incompatible change in the FloweryApiConfig model, and set up ruff formatting
This commit is contained in:
parent
dcb5365fea
commit
fde5dad155
11 changed files with 273 additions and 243 deletions
|
@ -1,4 +1,4 @@
|
|||
"""This module contains the RestAdapter class, which is used to make requests to the Flowery API."""""
|
||||
"""This module contains the RestAdapter class, which is used to make requests to the Flowery API.""" ""
|
||||
from asyncio import sleep as asleep
|
||||
from json import JSONDecodeError
|
||||
|
||||
|
@ -22,11 +22,12 @@ class RestAdapter:
|
|||
Raises:
|
||||
ValueError: Raised when the keyword arguments passed to the class constructor conflict.
|
||||
"""
|
||||
def __init__(self, config = FloweryAPIConfig):
|
||||
|
||||
def __init__(self, config=FloweryAPIConfig) -> None:
|
||||
self._url = "https://api.flowery.pw/v1"
|
||||
self.config = config
|
||||
|
||||
async def _do(self, http_method: str, endpoint: str, params: dict = None, timeout: float = 60):
|
||||
async def _do(self, http_method: str, endpoint: str, params: dict = None, timeout: float = 60) -> Result | None:
|
||||
"""Internal method to make a request to the Flowery API. You shouldn't use this directly.
|
||||
|
||||
Args:
|
||||
|
@ -46,7 +47,7 @@ class RestAdapter:
|
|||
"""
|
||||
full_url = self._url + endpoint
|
||||
headers = {
|
||||
'User-Agent': self.config.prepended_user_agent(),
|
||||
"User-Agent": self.config.prepended_user_agent,
|
||||
}
|
||||
sanitized_params = {k: str(v) if isinstance(v, bool) else v for k, v in params.items()} if params else None
|
||||
retry_counter = 0
|
||||
|
@ -84,9 +85,11 @@ class RestAdapter:
|
|||
raise RetryLimitExceeded(message=f"Request failed more than {self.config.retry_limit} times, not retrying") from e
|
||||
return result
|
||||
|
||||
async def get(self, endpoint: str, params: dict = None, timeout: float = 60) -> Result:
|
||||
async def get(self, endpoint: str, params: dict = None, timeout: float = 60) -> Result | None:
|
||||
"""Make a GET request to the Flowery API. You should almost never have to use this directly.
|
||||
|
||||
If you need to use this method because an endpoint is missing, please open an issue on the [CoastalCommits repository](https://www.coastalcommits.com/cswimr/PyFlowery/issues).
|
||||
|
||||
Args:
|
||||
endpoint (str): The endpoint to make the request to.
|
||||
params (dict): Python dictionary of query parameters to send with the request.
|
||||
|
@ -101,4 +104,4 @@ class RestAdapter:
|
|||
Returns:
|
||||
Result: A Result object containing the status code, message, and data from the request.
|
||||
"""
|
||||
return await self._do(http_method='GET', endpoint=endpoint, params=params, timeout=timeout)
|
||||
return await self._do(http_method="GET", endpoint=endpoint, params=params, timeout=timeout)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue