From fbf341a3ec435fca9375733f552d6de1f30c0af2 Mon Sep 17 00:00:00 2001 From: thec0sm0s Date: Sun, 10 May 2020 17:20:20 +0530 Subject: [PATCH] Modify request method so that it can be used for standard requests as well --- flask_discord/_http.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/flask_discord/_http.py b/flask_discord/_http.py index 848ef5a..6385d4f 100644 --- a/flask_discord/_http.py +++ b/flask_discord/_http.py @@ -1,3 +1,4 @@ +import requests import os import abc @@ -73,7 +74,7 @@ class DiscordOAuth2HttpClient(abc.ABC): auto_refresh_url=configs.DISCORD_TOKEN_URL, token_updater=self._token_updater) - def request(self, route: str, method="GET", data=None, **kwargs) -> dict: + def request(self, route: str, method="GET", data=None, oauth=True, **kwargs) -> dict: """Sends HTTP request to provided route or discord endpoint. Note @@ -88,6 +89,8 @@ class DiscordOAuth2HttpClient(abc.ABC): Specify the HTTP method to use to perform this request. data : dict, optional The optional payload the include with the request. + oauth : bool + A boolean determining if this should be Discord OAuth2 session request or any standard request. Returns ------- @@ -100,7 +103,11 @@ class DiscordOAuth2HttpClient(abc.ABC): Raises :py:class:`flask_discord.Unauthorized` if current user is not authorized. """ - response = self._make_session().request(method, configs.DISCORD_API_BASE_URL + route, data, **kwargs) + route = configs.DISCORD_API_BASE_URL + route + if oauth: + response = self._make_session().request(method, route, data, **kwargs) + else: + response = requests.request(method, route, data=data, **kwargs) if response.status_code == 401: raise exceptions.Unauthorized