44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
|
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']
|