Implement an Attachment model.
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user