diff --git a/rulings/mtgo.py b/rulings/mtgo.py index 5ba1329..b0ab7ed 100644 --- a/rulings/mtgo.py +++ b/rulings/mtgo.py @@ -1,7 +1,6 @@ from .rulings_object import RulingsObject class Mtgo(RulingsObject): - """docstring for Mtgo.""" def __init__(self, _id): self.id = _id self.url = 'cards/mtgo/{}/rulings'.format(self.id) diff --git a/rulings/multiverse_id.py b/rulings/multiverse_id.py index 4ba0deb..b290c4f 100644 --- a/rulings/multiverse_id.py +++ b/rulings/multiverse_id.py @@ -1,7 +1,6 @@ from .rulings_object import RulingsObject class Multiverse(RulingsObject): - """docstring for Multiverse.""" def __init__(self, _id): self.id = str(_id) self.url = 'cards/multiverse/{}/rulings'.format(self.id) diff --git a/rulings/rulings_object.py b/rulings/rulings_object.py index 178e6f4..dd433cc 100644 --- a/rulings/rulings_object.py +++ b/rulings/rulings_object.py @@ -2,7 +2,6 @@ import asyncio import aiohttp class RulingsObject(object): - def __init__(self, _url, **kwargs): self.pretty = kwargs.get('pretty') self.format = kwargs.get('format') @@ -33,38 +32,56 @@ class RulingsObject(object): except KeyError: return None + def __checkForTupleKey(self, parent, num, key): + try: + return self.scryfallJson[parent][num][key] + except KeyError: + return None + def object(self): if self.__checkForKey('object') is None: - return KeyError('This ruling has no associated object key.') + return KeyError('This ruling object has no associated object key.') return self.scryfallJson['object'] def has_more(self): if self.__checkForKey('has_more') is None: - return KeyError('This ruling has no associated has_more key.') + return KeyError('This ruling object has no associated has_more key.') return self.scryfallJson['has_more'] def data(self): if self.__checkForKey('data') is None: - return KeyError('This ruling has no associated data key.') + return KeyError('This ruling object has no associated data key.') return self.scryfallJson['data'] def data_length(self): if self.__checkForKey('data') is None: - return KeyError('This ruling has no associated data key.') + return KeyError('This ruling object has no associated data key.') return len(self.scryfallJson['data']) def ruling_object(self, num): + if self.__checkForTupleKey('data', num, 'object') is None: + return KeyError('This ruling has no object key.') + return self.scryfallJson['data'][num]['object'] def ruling_source(self, num): + if self.__checkForTupleKey('data', num, 'source') is None: + return KeyError('This ruling has no source key.') + return self.scryfallJson['data'][num]['source'] def ruling_published_at(self, num): + if self.__checkForTupleKey('data', num, 'published_at') is None: + return KeyError('This ruling has no published_at key.') + return self.scryfallJson['data'][num]['published_at'] def ruling_comment(self, num): + if self.__checkForTupleKey('data', num, 'comment') is None: + return KeyError('This ruling has no comment key.') + return self.scryfallJson['data'][num]['comment'] diff --git a/rulings/scryfall_id.py b/rulings/scryfall_id.py index b1c1415..04757de 100644 --- a/rulings/scryfall_id.py +++ b/rulings/scryfall_id.py @@ -1,7 +1,6 @@ from .rulings_object import RulingsObject class Id(RulingsObject): - """docstring for Id.""" def __init__(self, _id): self.id = str(_id) self.url = 'cards/{}/rulings'.format(self.id) diff --git a/rulings/set_code.py b/rulings/set_code.py index ea8fd8e..08994b0 100644 --- a/rulings/set_code.py +++ b/rulings/set_code.py @@ -1,7 +1,6 @@ from .rulings_object import RulingsObject class Code(RulingsObject): - """docstring for Code.""" def __init__(self, code, number): self.code = code.lower() self.number = str(number)