aboutsummaryrefslogtreecommitdiff
path: root/discord/http.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-05-30 22:27:45 -0400
committerRapptz <[email protected]>2017-05-30 22:27:45 -0400
commit8d3279b291f9f39ed5a9012eaad5f56442453714 (patch)
tree0aad8b2a29c5b4db96f768b293e3fa8ccdf3b4e6 /discord/http.py
parentRemove unused functions in HTTPClient. (diff)
downloaddiscord.py-8d3279b291f9f39ed5a9012eaad5f56442453714.tar.xz
discord.py-8d3279b291f9f39ed5a9012eaad5f56442453714.zip
Implement an Attachment model.
Diffstat (limited to 'discord/http.py')
-rw-r--r--discord/http.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/discord/http.py b/discord/http.py
index dfb11b6d..ae816043 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -119,7 +119,6 @@ class HTTPClient:
if self.token is not None:
headers['Authorization'] = 'Bot ' + self.token if self.bot_token else self.token
-
# some checking if it's a JSON request
if 'json' in kwargs:
headers['Content-Type'] = 'application/json'
@@ -210,6 +209,20 @@ class HTTPClient:
# clean-up just in case
yield from r.release()
+ def get_attachment(self, url):
+ resp = yield from self._session.get(url)
+ try:
+ if resp.status == 200:
+ return (yield from resp.read())
+ elif resp.status == 404:
+ raise NotFound(resp, 'attachment not found')
+ elif resp.status == 403:
+ raise Forbidden(resp, 'cannot retrieve attachment')
+ else:
+ raise HTTPException(resp, 'failed to get attachment')
+ finally:
+ yield from resp.release()
+
# state management
@asyncio.coroutine