Updated sets_object to the new refactor scheme.

This commit is contained in:
2018-03-03 18:19:59 -05:00
parent 64e9cf0632
commit 5276b70be9
1 changed files with 17 additions and 31 deletions

View File

@ -55,92 +55,78 @@ class SetsObject(object):
if self.scryfallJson['object'] == 'error': if self.scryfallJson['object'] == 'error':
raise Exception(self.scryfallJson['details']) raise Exception(self.scryfallJson['details'])
def __checkForKey(self, key): def _checkForKey(self, key):
try: try:
return self.scryfallJson[key] return self.scryfallJson[key]
except KeyError: except Exception:
return None raise KeyError('This object has no key \'{}\''.format(key))
def object(self): def object(self):
if self.__checkForKey('object') is None: self._checkForKey('object')
raise KeyError('This object has no key \'object\'')
return self.scryfallJson['object'] return self.scryfallJson['object']
def code(self): def code(self):
if self.__checkForKey('object') is None: self._checkForKey('object')
raise KeyError('This object has no key \'code\'')
return self.scryfallJson['code'] return self.scryfallJson['code']
def mtgo_code(self): def mtgo_code(self):
if self.__checkForKey('mtgo_code') is None: self._checkForKey('mtgo_code')
raise KeyError('This object has no key \'mtgo_code\'')
return self.scryfallJson['mtgo_code'] return self.scryfallJson['mtgo_code']
def name(self): def name(self):
if self.__checkForKey('name') is None: self._checkForKey('name')
raise KeyError('This object has no key \'name\'')
return self.scryfallJson['name'] return self.scryfallJson['name']
def set_type(self): def set_type(self):
if self.__checkForKey('set_type') is None: self._checkForKey('set_type')
raise KeyError('This object has no key \'set_type\'')
return self.scryfallJson['set_type'] return self.scryfallJson['set_type']
def released_at(self): def released_at(self):
if self.__checkForKey('released_at') is None: self._checkForKey('released_at')
raise KeyError('This object has no key \'released_at\'')
return self.scryfallJson['released_at'] return self.scryfallJson['released_at']
def block_code(self): def block_code(self):
if self.__checkForKey('block_code') is None: self._checkForKey('block_code')
raise KeyError('This object has no key \'block_code\'')
return self.scryfallJson['block_code'] return self.scryfallJson['block_code']
def block(self): def block(self):
if self.__checkForKey('block') is None: self._checkForKey('block')
raise KeyError('This object has no key \'block\'')
return self.scryfallJson['block'] return self.scryfallJson['block']
def parent_set_code(self): def parent_set_code(self):
if self.__checkForKey('parent_set_code') is None: self._checkForKey('parent_set_code')
raise KeyError('This object has no key \'parent_set_code\'')
return self.scryfallJson['parent_set_code'] return self.scryfallJson['parent_set_code']
def card_count(self): def card_count(self):
if self.__checkForKey('card_count') is None: self._checkForKey('card_count')
raise KeyError('This object has no key \'card_count\'')
return self.scryfallJson['card_count'] return self.scryfallJson['card_count']
def digital(self): def digital(self):
if self.__checkForKey('digital') is None: self._checkForKey('digital')
raise KeyError('This object has no key \'digital\'')
return self.scryfallJson['digital'] return self.scryfallJson['digital']
def foil(self): def foil(self):
if self.__checkForKey('foil') is None: self._checkForKey('foil')
raise KeyError('This object has no key \'foil\'')
return self.scryfallJson['foil'] return self.scryfallJson['foil']
def icon_svg_uri(self): def icon_svg_uri(self):
if self.__checkForKey('icon_svg_uri') is None: self._checkForKey('icon_svg_uri')
raise KeyError('This object has no key \'icon_svg_uri\'')
return self.scryfallJson['icon_svg_uri'] return self.scryfallJson['icon_svg_uri']
def search_uri(self): def search_uri(self):
if self.__checkForKey('search_uri') is None: self._checkForKey('search_uri')
raise KeyError('This object has no key \'search_uri\'')
return self.scryfallJson['search_uri'] return self.scryfallJson['search_uri']