From b1fa3626f96bcad7da7275e83d86cf0e19b785d3 Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Fri, 11 Mar 2022 21:22:09 +0300 Subject: [PATCH] http POST method --- melisa/core/http.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/melisa/core/http.py b/melisa/core/http.py index d655605..8e127cc 100644 --- a/melisa/core/http.py +++ b/melisa/core/http.py @@ -39,7 +39,7 @@ class HTTPClient: if ttl != 0: 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( self, @@ -51,6 +51,7 @@ class HTTPClient: **kwargs ) -> Optional[Dict]: """Handle responses from the Discord API.""" + if res.ok: return await res.json() @@ -71,7 +72,7 @@ class HTTPClient: params: Optional[Dict] = None ) -> Optional[Dict]: """|coro| - Sends a get request to a Discord REST endpoint. + Sends a GET request to a Discord REST endpoint. Parameters ---------- @@ -90,3 +91,30 @@ class HTTPClient: route, 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, + ) +