about summary refs log tree commit diff stats
path: root/discord/utils
diff options
context:
space:
mode:
authorNoah <mounderfod@gmail.com>2022-07-09 19:14:04 +0100
committerNoah <mounderfod@gmail.com>2022-07-09 19:14:04 +0100
commit6576d95f3601613fc03232b106f1cdeda1d99e06 (patch)
treeb9ddd69206b3aa0d84d29847e376780f9f6c0788 /discord/utils
parentfabbc3ac7a6a39dbb6c44512ec4bf17ac2745126 (diff)
downloaddiscobra-6576d95f3601613fc03232b106f1cdeda1d99e06.tar.gz
docs: Add more documentation where possible.
Diffstat (limited to 'discord/utils')
-rw-r--r--discord/utils/rest.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/discord/utils/rest.py b/discord/utils/rest.py
index 53853ed..652de5d 100644
--- a/discord/utils/rest.py
+++ b/discord/utils/rest.py
@@ -4,11 +4,22 @@ from discord.utils.exceptions import APIException
 
 
 class RESTClient:
+    """
+    Utility class to make it easier to make HTTP requests to Discord's API. This should not be used manually,
+    as it only works with Discord's API and the library should cover anything that can be requested from it. Any
+    requests to other APIs should use `aiohttp`.
+    """
     def __init__(self, token: str, session: aiohttp.ClientSession):
         self.token = token
         self.session = session
 
     async def get(self, url: str):
+        """
+        Makes a GET request to Discord's API.
+
+        **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:
             data = await r.json()
             match r.status:
@@ -18,15 +29,29 @@ class RESTClient:
                     raise APIException(data['message'])
 
     async def post(self, url: str, data):
+        """
+        Makes a POST request to Discord's API.
+
+        **Parameters:**
+        - 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:
             data = await r.json()
             match r.status:
-                case 200 | 204:
+                case 200 | 204 | 201:
                     return data
                 case other:
                     raise APIException(data['message'])
 
     async def patch(self, url, data):
+        """
+        Makes a PATCH request to Discord's API.
+
+        **Parameters:**
+        - 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:
             data = await res.json()
             match res.status:
@@ -36,6 +61,12 @@ class RESTClient:
                     raise APIException(data['message'])
 
     async def delete(self, url):
+        """
+        Makes a POST request to Discord's API.
+
+        **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:
             data = await r.json()
             match r.status: