From 5276b70be982e8846ce2007b0f8ca120cbddc957 Mon Sep 17 00:00:00 2001 From: Date: Sat, 3 Mar 2018 18:19:59 -0500 Subject: [PATCH] Updated sets_object to the new refactor scheme. --- scrython/sets/sets_object.py | 48 +++++++++++++----------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/scrython/sets/sets_object.py b/scrython/sets/sets_object.py index 4ff0d69..987ce35 100644 --- a/scrython/sets/sets_object.py +++ b/scrython/sets/sets_object.py @@ -55,92 +55,78 @@ class SetsObject(object): if self.scryfallJson['object'] == 'error': raise Exception(self.scryfallJson['details']) - def __checkForKey(self, key): + def _checkForKey(self, key): try: return self.scryfallJson[key] - except KeyError: - return None + except Exception: + raise KeyError('This object has no key \'{}\''.format(key)) def object(self): - if self.__checkForKey('object') is None: - raise KeyError('This object has no key \'object\'') + self._checkForKey('object') return self.scryfallJson['object'] def code(self): - if self.__checkForKey('object') is None: - raise KeyError('This object has no key \'code\'') + self._checkForKey('object') return self.scryfallJson['code'] def mtgo_code(self): - if self.__checkForKey('mtgo_code') is None: - raise KeyError('This object has no key \'mtgo_code\'') + self._checkForKey('mtgo_code') return self.scryfallJson['mtgo_code'] def name(self): - if self.__checkForKey('name') is None: - raise KeyError('This object has no key \'name\'') + self._checkForKey('name') return self.scryfallJson['name'] def set_type(self): - if self.__checkForKey('set_type') is None: - raise KeyError('This object has no key \'set_type\'') + self._checkForKey('set_type') return self.scryfallJson['set_type'] def released_at(self): - if self.__checkForKey('released_at') is None: - raise KeyError('This object has no key \'released_at\'') + self._checkForKey('released_at') return self.scryfallJson['released_at'] def block_code(self): - if self.__checkForKey('block_code') is None: - raise KeyError('This object has no key \'block_code\'') + self._checkForKey('block_code') return self.scryfallJson['block_code'] def block(self): - if self.__checkForKey('block') is None: - raise KeyError('This object has no key \'block\'') + self._checkForKey('block') return self.scryfallJson['block'] def parent_set_code(self): - if self.__checkForKey('parent_set_code') is None: - raise KeyError('This object has no key \'parent_set_code\'') + self._checkForKey('parent_set_code') return self.scryfallJson['parent_set_code'] def card_count(self): - if self.__checkForKey('card_count') is None: - raise KeyError('This object has no key \'card_count\'') + self._checkForKey('card_count') return self.scryfallJson['card_count'] def digital(self): - if self.__checkForKey('digital') is None: - raise KeyError('This object has no key \'digital\'') + self._checkForKey('digital') return self.scryfallJson['digital'] def foil(self): - if self.__checkForKey('foil') is None: - raise KeyError('This object has no key \'foil\'') + self._checkForKey('foil') return self.scryfallJson['foil'] def icon_svg_uri(self): - if self.__checkForKey('icon_svg_uri') is None: - raise KeyError('This object has no key \'icon_svg_uri\'') + self._checkForKey('icon_svg_uri') return self.scryfallJson['icon_svg_uri'] def search_uri(self): - if self.__checkForKey('search_uri') is None: - raise KeyError('This object has no key \'search_uri\'') + self._checkForKey('search_uri') return self.scryfallJson['search_uri']