Refactored autocompelete for more DRYness.

This commit is contained in:
2018-03-03 16:40:57 -05:00
parent 4d45c17e06
commit 2fd9477620
1 changed files with 3 additions and 12 deletions

View File

@ -35,27 +35,18 @@ class Autocomplete(CardsObject):
self.url = 'cards/autocomplete?' + self.args
super(Autocomplete, self).__init__(self.url)
def __checkForKey(self, key):
try:
return self.scryfallJson[key]
except KeyError:
return None
def object(self):
if self.__checkForKey('object') is None:
raise KeyError('This card has no key \'object\'')
super(Autocomplete, self)._checkForKey('object')
return self.scryfallJson['object']
def total_items(self):
if self.__checkForKey('total_items') is None:
raise KeyError('This card has no key \'total_items\'')
super(Autocomplete, self)._checkForKey('total_items')
return self.scryfallJson['total_items']
def data(self):
if self.__checkForKey('data') is None:
raise KeyError('This card has no key \'data\'')
super(Autocomplete, self)._checkForKey('data')
return self.scryfallJson['data']