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:
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)

View File

@ -5,5 +5,5 @@ class Multiverse(RulingsObject):
if kwargs.get('id') is None:
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)

View File

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

View File

@ -5,5 +5,5 @@ class Id(RulingsObject):
if kwargs.get('id') is None:
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)

View File

@ -2,5 +2,5 @@ from .rulings_object import RulingsObject
class Code(RulingsObject):
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)