Updated autocomplete to be more consistent with the rest of cards.

This commit is contained in:
Nanda Scott 2018-01-30 10:30:14 -05:00
parent 4c53f33470
commit 7ab602cec7
1 changed files with 16 additions and 2 deletions

View File

@ -1,5 +1,4 @@
import asyncio, aiohttp import asyncio, aiohttp
import json
class Autocomplete(object): class Autocomplete(object):
""" cards/autocomplete """ cards/autocomplete
@ -32,16 +31,31 @@ class Autocomplete(object):
params={'q':self.query, 'pretty':self.pretty, 'format':self.format})) params={'q':self.query, 'pretty':self.pretty, 'format':self.format}))
if self.scryfallJson['object'] == 'error': if self.scryfallJson['object'] == 'error':
raise Exception(self.scryfallJson['details'])
self.session.close() self.session.close()
raise Exception(self.scryfallJson['details'])
self.session.close() self.session.close()
def __checkForKey(self, key):
try:
return self.scryfallJson[key]
except KeyError:
return None
def object(self): def object(self):
if self.__checkForKey('object') is None:
return KeyError('This card has no associated object key.')
return self.scryfallJson['object'] return self.scryfallJson['object']
def total_items(self): def total_items(self):
if self.__checkForKey('total_items') is None:
return KeyError('This card has no associated total items key.')
return self.scryfallJson['total_items'] return self.scryfallJson['total_items']
def data(self): def data(self):
if self.__checkForKey('data') is None:
return KeyError('This card has no associated data key.')
return self.scryfallJson['data'] return self.scryfallJson['data']