Created data_length and data_tuple attributes for Search

This commit is contained in:
2018-03-03 12:29:37 -05:00
parent 4817763f27
commit 50e9d35064
1 changed files with 18 additions and 0 deletions

View File

@ -53,6 +53,12 @@ class Search(CardsObject):
except KeyError: except KeyError:
return None return None
def __checkForTupleKey(self, parent, num, key):
try:
return self.scryfallJson[parent][num][key]
except KeyError:
return None
def object(self): def object(self):
if self.__checkForKey('object') is None: if self.__checkForKey('object') is None:
raise KeyError('This object has no key \'object\'') raise KeyError('This object has no key \'object\'')
@ -83,6 +89,18 @@ class Search(CardsObject):
return self.scryfallJson['warnings'] return self.scryfallJson['warnings']
def data_length(self):
if self.__checkForKey('data') is None:
raise KeyError('This object has no key \'data\'')
return len(self.scryfallJson['data'])
def data_tuple(self, num):
if self.__checkForKey('data') is None:
raise KeyError('This object has no key \'data\'')
return self.scryfallJson['data'][num]
#The following attributes are only to override the inherited class attributes. #The following attributes are only to override the inherited class attributes.
#This class has no matching attributes but we still need the getRequest function from CardsObject #This class has no matching attributes but we still need the getRequest function from CardsObject