about summary refs log tree commit diff stats
path: root/discord/utils
diff options
context:
space:
mode:
authormjk134 <57556877+mjk134@users.noreply.github.com>2022-07-12 08:40:43 +0000
committerGitHub <noreply@github.com>2022-07-12 08:40:43 +0000
commit3c61b5814f2f7636e269624c72e876d48a8f4eef (patch)
tree7f564a8bcdb9256cc2aef3e70f18319407db36ad /discord/utils
parentde4b806a7e5b823680acae4627607198cf1f59a6 (diff)
downloaddiscobra-3c61b5814f2f7636e269624c72e876d48a8f4eef.tar.gz
feat(client): Switch to aiohttp for webscokets connections
Diffstat (limited to 'discord/utils')
-rw-r--r--discord/utils/rest.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/discord/utils/rest.py b/discord/utils/rest.py
index 652de5d..fc3f729 100644
--- a/discord/utils/rest.py
+++ b/discord/utils/rest.py
@@ -11,7 +11,14 @@ class RESTClient:
     """
     def __init__(self, token: str, session: aiohttp.ClientSession):
         self.token = token
-        self.session = session
+        self._session = session
+
+    @property
+    def session(self) -> aiohttp.ClientSession:
+        """
+        Returns the _session used by the client.
+        """
+        return self._session
 
     async def get(self, url: str):
         """
@@ -20,7 +27,7 @@ class RESTClient:
         **Parameters:**
         - url: The part of the request URL that goes after `https://discord.com/api/v10`
         """
-        async with self.session.get(url='https://discord.com/api/v10' + url) as r:
+        async with self._session.get(url='https://discord.com/api/v10' + url) as r:
             data = await r.json()
             match r.status:
                 case 200:
@@ -36,7 +43,7 @@ class RESTClient:
         - url: The part of the request URL that goes after `https://discord.com/api/v10`
         - data: The data to post.
         """
-        async with self.session.post(url='https://discord.com/api/v10' + url, data=data) as r:
+        async with self._session.post(url='https://discord.com/api/v10' + url, data=data) as r:
             data = await r.json()
             match r.status:
                 case 200 | 204 | 201:
@@ -52,7 +59,7 @@ class RESTClient:
         - url: The part of the request URL that goes after `https://discord.com/api/v10`
         - data: The data to patch.
         """
-        async with self.session.patch(url='https://discord.com/api/v10' + url, data=data) as res:
+        async with self._session.patch(url='https://discord.com/api/v10' + url, data=data) as res:
             data = await res.json()
             match res.status:
                 case 200 | 204:
@@ -67,7 +74,7 @@ class RESTClient:
         **Parameters:**
         - url: The part of the request URL that goes after `https://discord.com/api/v10`
         """
-        async with self.session.delete(url='https://discord.com/api/v10' + url) as r:
+        async with self._session.delete(url='https://discord.com/api/v10' + url) as r:
             data = await r.json()
             match r.status:
                 case 200: