From eee66d482604886ed4ad38d3c42a3464e5d2163c Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Tue, 6 Feb 2018 22:01:08 -0500 Subject: [PATCH] Refactored cards to be more clear and consistent. --- scrython/cards/autocomplete.py | 14 -------------- scrython/cards/cardid.py | 10 ++-------- .../cards/{scryfall_object.py => cards_object.py} | 2 +- scrython/cards/collector.py | 11 ++--------- scrython/cards/mtgo.py | 11 ++--------- scrython/cards/multiverse.py | 9 ++------- scrython/cards/named.py | 11 ++--------- scrython/cards/randomcard.py | 5 ++--- 8 files changed, 13 insertions(+), 60 deletions(-) rename scrython/cards/{scryfall_object.py => cards_object.py} (99%) diff --git a/scrython/cards/autocomplete.py b/scrython/cards/autocomplete.py index 99517b7..05d6e82 100644 --- a/scrython/cards/autocomplete.py +++ b/scrython/cards/autocomplete.py @@ -1,20 +1,6 @@ import asyncio, aiohttp class Autocomplete(object): - """ cards/autocomplete - - Parameters: - query: str The string to autocomplete. - format: str The data format to return. Currently only supports JSON. - pretty: bool If true, the returned JSON will be prettified. Avoid using for production code. - - Attributes: - object: str Returns the type of object it is. - total_items: int Returns the number of items in data. - data: arr The full autocompleted list. - - """ - def __init__(self, query, **kwargs): self.query = query self.pretty = kwargs.get('pretty') diff --git a/scrython/cards/cardid.py b/scrython/cards/cardid.py index 65d4a0b..1581e58 100644 --- a/scrython/cards/cardid.py +++ b/scrython/cards/cardid.py @@ -1,12 +1,6 @@ -from .scryfall_object import ScryfallObject - -class Id(ScryfallObject): - """ cards/:id - - Parameters: - id: str The Scryfall id of the card. - """ +from .cards_object import CardsObject +class Id(CardsObject): def __init__(self, **kwargs): self.id = kwargs.get('id') self.url = 'cards/' + str(self.id) diff --git a/scrython/cards/scryfall_object.py b/scrython/cards/cards_object.py similarity index 99% rename from scrython/cards/scryfall_object.py rename to scrython/cards/cards_object.py index e35192c..bfd53aa 100644 --- a/scrython/cards/scryfall_object.py +++ b/scrython/cards/cards_object.py @@ -1,7 +1,7 @@ import aiohttp import asyncio -class ScryfallObject(object): +class CardsObject(object): def __init__(self, _url, **kwargs): self._url = 'https://api.scryfall.com/' + _url loop = asyncio.get_event_loop() diff --git a/scrython/cards/collector.py b/scrython/cards/collector.py index 8fc2bf3..e73c691 100644 --- a/scrython/cards/collector.py +++ b/scrython/cards/collector.py @@ -1,13 +1,6 @@ -from .scryfall_object import ScryfallObject - -class Collector(ScryfallObject): - """ cards/:code/:collector_number - - Parameters: - code: str The 3 or 4 letter set code. - collector_number: int The collector number of the card. - """ +from .cards_object import CardsObject +class Collector(CardsObject): def __init__(self, **kwargs): self.code = kwargs.get('code') self.collector_number = kwargs.get('collector_number') diff --git a/scrython/cards/mtgo.py b/scrython/cards/mtgo.py index ef267ed..8f85d19 100644 --- a/scrython/cards/mtgo.py +++ b/scrython/cards/mtgo.py @@ -1,14 +1,7 @@ -from .scryfall_object import ScryfallObject +from .cards_object import CardsObject import urllib.parse -class Mtgo(ScryfallObject): - """ cards/mtgo/:id - - Parameters: - id: int The mtgo id of the card. - - """ - +class Mtgo(CardsObject): def __init__(self, **kwargs): self.mtgoid = kwargs.get('id') self.url = 'cards/mtgo/' + str(self.mtgoid) diff --git a/scrython/cards/multiverse.py b/scrython/cards/multiverse.py index 28734ab..52b1671 100644 --- a/scrython/cards/multiverse.py +++ b/scrython/cards/multiverse.py @@ -1,11 +1,6 @@ -from .scryfall_object import ScryfallObject - -class Multiverse(ScryfallObject): - """ - Parameters: - id: int The multiverse id of the card. - """ +from .cards_object import CardsObject +class Multiverse(CardsObject): def __init__(self, **kwargs): self.multiverseid = kwargs.get('id') self.url = 'cards/multiverse/' + self.multiverseid diff --git a/scrython/cards/named.py b/scrython/cards/named.py index 7d9553f..be3696f 100644 --- a/scrython/cards/named.py +++ b/scrython/cards/named.py @@ -1,14 +1,7 @@ -from .scryfall_object import ScryfallObject +from .cards_object import CardsObject import urllib.parse -class Named(ScryfallObject): - """ - Parameters: - exact: str The exact card name to search for, case insenstive. - fuzzy: str A fuzzy card name to search for. - set: str A set code to limit the search to one set. - """ - +class Named(CardsObject): def __init__(self, **kwargs): self.exact = kwargs.get('exact') self.fuzzy = kwargs.get('fuzzy') diff --git a/scrython/cards/randomcard.py b/scrython/cards/randomcard.py index ac16cba..cf1f8af 100644 --- a/scrython/cards/randomcard.py +++ b/scrython/cards/randomcard.py @@ -1,8 +1,7 @@ -from .scryfall_object import ScryfallObject +from .cards_object import CardsObject -class Random(ScryfallObject): - """This will return a random card. No parameters are passed while creating.""" +class Random(CardsObject): def __init__(self): self.url = 'cards/random' super(Random, self).__init__(self.url)