From 2fd94776200d51c221b9139f2f4e279129c462f0 Mon Sep 17 00:00:00 2001 From: Date: Sat, 3 Mar 2018 16:40:57 -0500 Subject: [PATCH] Refactored autocompelete for more DRYness. --- scrython/cards/autocomplete.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/scrython/cards/autocomplete.py b/scrython/cards/autocomplete.py index 8badc66..e7e8b00 100644 --- a/scrython/cards/autocomplete.py +++ b/scrython/cards/autocomplete.py @@ -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']