Implement an Attachment model.

This commit is contained in:
Rapptz
2017-05-30 22:27:45 -04:00
parent d21fb780fd
commit 8d3279b291
3 changed files with 92 additions and 4 deletions

View File

@ -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