From d92aad46b64d2efe9431769dd4af88ada5c77d21 Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Tue, 13 Feb 2018 16:55:32 -0500 Subject: [PATCH] Refactored rulings. --- scrython/rulings/mtgo.py | 6 ++++-- scrython/rulings/multiverse_id.py | 6 ++++-- scrython/rulings/rulings_object.py | 6 ++---- scrython/rulings/scryfall_id.py | 6 ++++-- scrython/rulings/set_code.py | 4 +--- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/scrython/rulings/mtgo.py b/scrython/rulings/mtgo.py index 5a17dd9..7ddc9ce 100644 --- a/scrython/rulings/mtgo.py +++ b/scrython/rulings/mtgo.py @@ -2,6 +2,8 @@ from .rulings_object import RulingsObject class Mtgo(RulingsObject): def __init__(self, **kwargs): - self.id = kwargs.get('id') - self.url = 'cards/mtgo/{}/rulings'.format(self.id) + if kwargs.get('id') is None: + raise TypeError('No id provided to search by') + + self.url = 'cards/mtgo/{}/rulings'.format(str(kwargs.get('id'))) super(Mtgo, self).__init__(self.url) diff --git a/scrython/rulings/multiverse_id.py b/scrython/rulings/multiverse_id.py index e92c43b..97e6a5c 100644 --- a/scrython/rulings/multiverse_id.py +++ b/scrython/rulings/multiverse_id.py @@ -2,6 +2,8 @@ from .rulings_object import RulingsObject class Multiverse(RulingsObject): def __init__(self, **kwargs): - self.id = str(kwargs.get('id')) - self.url = 'cards/multiverse/{}/rulings'.format(self.id) + if kwargs.get('id') is None: + raise TypeError('No id provided to search by') + + self.url = 'cards/multiverse/{}/rulings'.format(str(kwargs.get('id'))) super(Multiverse, self).__init__(self.url) diff --git a/scrython/rulings/rulings_object.py b/scrython/rulings/rulings_object.py index a478803..95df49c 100644 --- a/scrython/rulings/rulings_object.py +++ b/scrython/rulings/rulings_object.py @@ -3,8 +3,6 @@ import aiohttp class RulingsObject(object): def __init__(self, _url, **kwargs): - self.pretty = kwargs.get('pretty', 'None') - self.format = kwargs.get('format', 'None') self._url = 'https://api.scryfall.com/' + _url loop = asyncio.get_event_loop() self.session = aiohttp.ClientSession(loop=loop) @@ -16,8 +14,8 @@ class RulingsObject(object): self.scryfallJson = loop.run_until_complete(getRequest( url = self._url, params={ - 'format': self.format, - 'pretty': self.pretty + 'format': kwargs.get('format', 'json'), + 'pretty': kwargs.get('pretty', 'false') })) if self.scryfallJson['object'] == 'error': diff --git a/scrython/rulings/scryfall_id.py b/scrython/rulings/scryfall_id.py index 416ae7e..efe2433 100644 --- a/scrython/rulings/scryfall_id.py +++ b/scrython/rulings/scryfall_id.py @@ -2,6 +2,8 @@ from .rulings_object import RulingsObject class Id(RulingsObject): def __init__(self, **kwargs): - self.id = str(kwargs.get('id')) - self.url = 'cards/{}/rulings'.format(self.id) + if kwargs.get('id') is None: + raise TypeError('No id provided to search by') + + self.url = 'cards/{}/rulings'.format(str(kwargs.get('id'))) super(Id, self).__init__(self.url) diff --git a/scrython/rulings/set_code.py b/scrython/rulings/set_code.py index 943352e..c2250e1 100644 --- a/scrython/rulings/set_code.py +++ b/scrython/rulings/set_code.py @@ -2,7 +2,5 @@ from .rulings_object import RulingsObject class Code(RulingsObject): def __init__(self, code, collector_number): - self.code = code.lower() - self.number = str(collector_number) - self.url = 'cards/{}/{}/rulings'.format(self.code, self.number) + self.url = 'cards/{}/{}/rulings'.format(code.lower(), str(collector_number)) super(Code, self).__init__(self.url)