Added a class for using the search endpoint.

This commit is contained in:
Nanda Scott 2018-02-06 21:52:21 -05:00
parent 7d87ad21b8
commit 4c045a3fe0
3 changed files with 45 additions and 0 deletions

View File

@ -6,6 +6,7 @@ from scrython.cards import Mtgo
from scrython.cards import Multiverse from scrython.cards import Multiverse
from scrython.cards import Named from scrython.cards import Named
from scrython.cards import Random from scrython.cards import Random
from scrython.cards import Search
#Import classes from rulings #Import classes from rulings
from scrython.rulings import Mtgo from scrython.rulings import Mtgo

View File

@ -5,3 +5,4 @@ from .mtgo import Mtgo
from .multiverse import Multiverse from .multiverse import Multiverse
from .named import Named from .named import Named
from .randomcard import Random from .randomcard import Random
from .search import Search

43
scrython/cards/search.py Normal file
View File

@ -0,0 +1,43 @@
from .scryfall_object import ScryfallObject
import urllib.parse
class Search(ScryfallObject):
def __init__(self, **kwargs):
self.q = kwargs.get('q')
self.order = kwargs.get('order')
self.dict = {}
if self.q is not None:
self.dict['q'] = self.q
if self.order is not None:
self.dict['order'] = self.order
self.args = urllib.parse.urlencode(self.dict)
self.url = 'cards/search?' + self.args
super(Search, self).__init__(self.url)
def __checkForKey(self, key):
try:
return self.scryfallJson[key]
except KeyError:
return None
def object(self):
if self.__checkForKey('object') is None:
return KeyError('This card has no associated object key.')
return self.scryfallJson['object']
def total_cards(self):
if self.__checkForKey('total_cards') is None:
return KeyError('This card has no associated total cards key.')
return self.scryfallJson['total_cards']
def data(self):
if self.__checkForKey('data') is None:
return KeyError('This card has no associated data key.')
return self.scryfallJson['data']