Updated rulings to be consistent with cards.

This commit is contained in:
Nanda Scott 2018-02-15 15:13:39 -05:00
parent 1177ebaf46
commit 0fd99425b6
5 changed files with 20 additions and 18 deletions

View File

@ -5,5 +5,5 @@ class Mtgo(RulingsObject):
if kwargs.get('id') is None: if kwargs.get('id') is None:
raise TypeError('No id provided to search by') raise TypeError('No id provided to search by')
self.url = 'cards/mtgo/{}/rulings'.format(str(kwargs.get('id'))) self.url = 'cards/mtgo/{}/rulings?'.format(str(kwargs.get('id')))
super(Mtgo, self).__init__(self.url) super(Mtgo, self).__init__(self.url)

View File

@ -5,5 +5,5 @@ class Multiverse(RulingsObject):
if kwargs.get('id') is None: if kwargs.get('id') is None:
raise TypeError('No id provided to search by') raise TypeError('No id provided to search by')
self.url = 'cards/multiverse/{}/rulings'.format(str(kwargs.get('id'))) self.url = 'cards/multiverse/{}/rulings?'.format(str(kwargs.get('id')))
super(Multiverse, self).__init__(self.url) super(Multiverse, self).__init__(self.url)

View File

@ -1,29 +1,31 @@
import asyncio import asyncio
import aiohttp import aiohttp
import urllib.parse
class RulingsObject(object): class RulingsObject(object):
def __init__(self, _url, **kwargs): def __init__(self, _url, **kwargs):
self._url = 'https://api.scryfall.com/' + _url self.params = {
loop = asyncio.get_event_loop() 'format': kwargs.get('format', 'json'), 'face': kwargs.get('face', ''),
self.session = aiohttp.ClientSession(loop=loop) 'version': kwargs.get('version', ''), 'pretty': kwargs.get('pretty', '')
}
async def getRequest(url, **kwargs): self.encodedParams = urllib.parse.urlencode(self.params)
async with self.session.get(url, **kwargs) as response: self._url = 'https://api.scryfall.com/' + _url + "&" + self.encodedParams #Find a fix for this later
async def getRequest(client, url, **kwargs):
async with client.get(url, **kwargs) as response:
return await response.json() return await response.json()
self.scryfallJson = loop.run_until_complete(getRequest( async def main(loop):
url = self._url, async with aiohttp.ClientSession(loop=loop) as client:
params={ self.scryfallJson = await getRequest(client, self._url)
'format': kwargs.get('format', 'json'),
'pretty': kwargs.get('pretty', 'false') loop = asyncio.get_event_loop()
})) loop.run_until_complete(main(loop))
if self.scryfallJson['object'] == 'error': if self.scryfallJson['object'] == 'error':
self.session.close()
raise Exception(self.scryfallJson['details']) raise Exception(self.scryfallJson['details'])
self.session.close()
def __checkForKey(self, key): def __checkForKey(self, key):
try: try:
return self.scryfallJson[key] return self.scryfallJson[key]

View File

@ -5,5 +5,5 @@ class Id(RulingsObject):
if kwargs.get('id') is None: if kwargs.get('id') is None:
raise TypeError('No id provided to search by') raise TypeError('No id provided to search by')
self.url = 'cards/{}/rulings'.format(str(kwargs.get('id'))) self.url = 'cards/{}/rulings?'.format(str(kwargs.get('id')))
super(Id, self).__init__(self.url) super(Id, self).__init__(self.url)

View File

@ -2,5 +2,5 @@ from .rulings_object import RulingsObject
class Code(RulingsObject): class Code(RulingsObject):
def __init__(self, code, collector_number): def __init__(self, code, collector_number):
self.url = 'cards/{}/{}/rulings'.format(code.lower(), str(collector_number)) self.url = 'cards/{}/{}/rulings?'.format(code.lower(), str(collector_number))
super(Code, self).__init__(self.url) super(Code, self).__init__(self.url)