Refactored autocompelete for more DRYness.
This commit is contained in:
parent
4d45c17e06
commit
2fd9477620
|
@ -35,27 +35,18 @@ class Autocomplete(CardsObject):
|
||||||
self.url = 'cards/autocomplete?' + self.args
|
self.url = 'cards/autocomplete?' + self.args
|
||||||
super(Autocomplete, self).__init__(self.url)
|
super(Autocomplete, self).__init__(self.url)
|
||||||
|
|
||||||
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:
|
super(Autocomplete, self)._checkForKey('object')
|
||||||
raise KeyError('This card has no key \'object\'')
|
|
||||||
|
|
||||||
return self.scryfallJson['object']
|
return self.scryfallJson['object']
|
||||||
|
|
||||||
def total_items(self):
|
def total_items(self):
|
||||||
if self.__checkForKey('total_items') is None:
|
super(Autocomplete, self)._checkForKey('total_items')
|
||||||
raise KeyError('This card has no key \'total_items\'')
|
|
||||||
|
|
||||||
return self.scryfallJson['total_items']
|
return self.scryfallJson['total_items']
|
||||||
|
|
||||||
def data(self):
|
def data(self):
|
||||||
if self.__checkForKey('data') is None:
|
super(Autocomplete, self)._checkForKey('data')
|
||||||
raise KeyError('This card has no key \'data\'')
|
|
||||||
|
|
||||||
return self.scryfallJson['data']
|
return self.scryfallJson['data']
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue