Refactored cards.
This commit is contained in:
parent
91a5f04113
commit
5bb912da76
|
@ -3,8 +3,11 @@ import urllib.parse
|
||||||
|
|
||||||
class Autocomplete(CardsObject):
|
class Autocomplete(CardsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
if kwargs.get('q') is None:
|
||||||
|
raise TypeError('No query provided to search by')
|
||||||
|
|
||||||
self.dict = {
|
self.dict = {
|
||||||
'q': kwargs.get('query', ''),
|
'q': kwargs.get('q'),
|
||||||
'pretty': kwargs.get('pretty', 'false'),
|
'pretty': kwargs.get('pretty', 'false'),
|
||||||
'format': kwargs.get('format', 'json')
|
'format': kwargs.get('format', 'json')
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ from .cards_object import CardsObject
|
||||||
|
|
||||||
class Id(CardsObject):
|
class Id(CardsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.id = kwargs.get('id')
|
if kwargs.get('id') is None:
|
||||||
self.url = 'cards/' + str(self.id)
|
raise TypeError('No id provided to search by')
|
||||||
|
|
||||||
|
self.url = 'cards/' + str(kwargs.get('id'))
|
||||||
super(Id, self).__init__(self.url)
|
super(Id, self).__init__(self.url)
|
||||||
|
|
|
@ -2,7 +2,8 @@ from .cards_object import CardsObject
|
||||||
|
|
||||||
class Collector(CardsObject):
|
class Collector(CardsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.code = kwargs.get('code')
|
if kwargs.get('code') is None:
|
||||||
self.collector_number = kwargs.get('collector_number')
|
raise TypeError('No code provided to search by')
|
||||||
self.url = 'cards/{}/{}'.format(self.code, str(self.collector_number))
|
|
||||||
|
self.url = 'cards/{}/{}'.format(kwargs.get('code'), str(kwargs.get('collector_number')))
|
||||||
super(Collector, self).__init__(self.url)
|
super(Collector, self).__init__(self.url)
|
||||||
|
|
|
@ -3,6 +3,7 @@ import urllib.parse
|
||||||
|
|
||||||
class Mtgo(CardsObject):
|
class Mtgo(CardsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.mtgoid = kwargs.get('id')
|
if kwargs.get('id') is None:
|
||||||
self.url = 'cards/mtgo/' + str(self.mtgoid)
|
raise TypeError('No id provided to search by')
|
||||||
|
self.url = 'cards/mtgo/' + str(kwargs.get('id'))
|
||||||
super(Mtgo, self).__init__(self.url)
|
super(Mtgo, self).__init__(self.url)
|
||||||
|
|
|
@ -2,6 +2,7 @@ from .cards_object import CardsObject
|
||||||
|
|
||||||
class Multiverse(CardsObject):
|
class Multiverse(CardsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.multiverseid = kwargs.get('id')
|
if kwargs.get('id') is None:
|
||||||
self.url = 'cards/multiverse/' + self.multiverseid
|
raise TypeError('No id provided to search by')
|
||||||
|
self.url = 'cards/multiverse/' + kwargs.get('id')
|
||||||
super(Multiverse, self).__init__(self.url)
|
super(Multiverse, self).__init__(self.url)
|
||||||
|
|
|
@ -3,19 +3,11 @@ import urllib.parse
|
||||||
|
|
||||||
class Named(CardsObject):
|
class Named(CardsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.exact = kwargs.get('exact')
|
self.dict = {
|
||||||
self.fuzzy = kwargs.get('fuzzy')
|
'exact':kwargs.get('exact', ''),
|
||||||
self.set = kwargs.get('set', 'None')
|
'fuzzy':kwargs.get('fuzzy', ''),
|
||||||
self.dict = {}
|
'set':kwargs.get('set', 'none')
|
||||||
|
}
|
||||||
if self.exact is not None:
|
|
||||||
self.dict['exact'] = self.exact
|
|
||||||
|
|
||||||
if self.fuzzy is not None:
|
|
||||||
self.dict['fuzzy'] = self.fuzzy
|
|
||||||
|
|
||||||
if self.set is not None:
|
|
||||||
self.dict['set'] = self.set
|
|
||||||
|
|
||||||
self.args = urllib.parse.urlencode(self.dict)
|
self.args = urllib.parse.urlencode(self.dict)
|
||||||
self.url = 'cards/named?' + self.args
|
self.url = 'cards/named?' + self.args
|
||||||
|
|
|
@ -3,19 +3,16 @@ import urllib.parse
|
||||||
|
|
||||||
class Search(CardsObject):
|
class Search(CardsObject):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.q = kwargs.get('q', 'None')
|
if kwargs.get('q') is None:
|
||||||
self.order = kwargs.get('order', 'None')
|
raise TypeError('No query is specified.')
|
||||||
self.unique = kwargs.get('unique', 'False')
|
|
||||||
self.dir = kwargs.get('dir', 'Auto')
|
|
||||||
self.include_extras = kwargs.get('include_extras', 'False')
|
|
||||||
self.page = kwargs.get('page', '1')
|
|
||||||
self.dict = {
|
self.dict = {
|
||||||
'q':self.q,
|
'q':kwargs.get('q'),
|
||||||
'order':self.order,
|
'order':kwargs.get('order', 'none'),
|
||||||
'unique':self.unique,
|
'unique':kwargs.get('unique', 'none'),
|
||||||
'dir':self.dir,
|
'dir':kwargs.get('dir', 'none'),
|
||||||
'include_extras':self.include_extras,
|
'include_extras':kwargs.get('include_extras', 'false'),
|
||||||
'page':self.page
|
'page':kwargs.get('page', '1')
|
||||||
}
|
}
|
||||||
|
|
||||||
self.args = urllib.parse.urlencode(self.dict)
|
self.args = urllib.parse.urlencode(self.dict)
|
||||||
|
|
Loading…
Reference in New Issue