http POST method

This commit is contained in:
grey-cat-1908 2022-03-11 21:22:09 +03:00
parent 8ff4983d83
commit b1fa3626f9

View file

@ -39,7 +39,7 @@ class HTTPClient:
if ttl != 0: if ttl != 0:
async with self.__aiohttp_session.request(method, url, **kwargs) as response: async with self.__aiohttp_session.request(method, url, **kwargs) as response:
return await self.__handle_response(response, method, endpoint, __ttl=ttl, **kwargs) return await self.__handle_response(response, method, endpoint, _ttl=ttl, **kwargs)
async def __handle_response( async def __handle_response(
self, self,
@ -51,6 +51,7 @@ class HTTPClient:
**kwargs **kwargs
) -> Optional[Dict]: ) -> Optional[Dict]:
"""Handle responses from the Discord API.""" """Handle responses from the Discord API."""
if res.ok: if res.ok:
return await res.json() return await res.json()
@ -71,7 +72,7 @@ class HTTPClient:
params: Optional[Dict] = None params: Optional[Dict] = None
) -> Optional[Dict]: ) -> Optional[Dict]:
"""|coro| """|coro|
Sends a get request to a Discord REST endpoint. Sends a GET request to a Discord REST endpoint.
Parameters Parameters
---------- ----------
@ -90,3 +91,30 @@ class HTTPClient:
route, route,
params=params params=params
) )
async def post(
self,
route: str,
data: Optional[Dict] = None
) -> Optional[Dict]:
"""|coro|
Sends a POST request to a Discord REST endpoint.
Parameters
----------
route : :class:`str`
The endpoint to send the request to.
data : Dict
Data to post
Returns
-------
Optional[:class:`Dict`]
JSON response from the discord API.
"""
return await self.__send(
"POST",
route,
json=data,
)