11import aiohttp
22import asyncio
3- from .models import Profile , Clan , Clans , Constants
3+ from .models import Profile , Clan , Constants
44
55
66class Client :
@@ -28,41 +28,29 @@ async def get_profile(self, tag):
2828 if resp .status == 200 :
2929 data = await resp .json ()
3030 else :
31- print ('API is down. Please be patient.' )
32- return None
31+ raise ConnectionError (f'API not responding: { resp .status } ' )
3332
3433 return Profile (self , data )
35-
36- async def get_clans (self , * , tags ):
34+
35+ async def get_clan (self , * tags ):
3736 '''Get a clan object using tag(s)'''
38- tags = tags .split (',' )
39-
40- if len (tags ) == 1 :
41- url = f'{ self .BASE } /clan/{ tags [0 ]} '
42- async with self .session .get (url ) as resp :
43- if resp .status == 200 :
44- data = await resp .json ()
45- else :
46- print ('API is down. Please be patient.' )
47- return None
48- return Clan (self , data )
49-
50- taglist = ''
51- i = 0
52- for tag in tags :
53- i += 1
54- taglist += tag [1 :]
55- if i != len (tags ):
56- taglist += ','
57-
58- url = f'{ self .BASE } /clan/{ taglist } '
37+
38+ tags = ',' .join (tags )
39+
40+ url = f'{ self .BASE } /clan/{ tags } '
41+
5942 async with self .session .get (url ) as resp :
6043 if resp .status == 200 :
6144 data = await resp .json ()
6245 else :
63- print ('API is down. Please be patient.' )
64- return None
65- return Clans (self , data )
46+ raise ConnectionError (f'API not responding: { resp .status } ' )
47+
48+ if isinstance (data , list ):
49+ return [Clan (self , c ) for c in data ]
50+ else :
51+ return Clan (self , c )
52+
53+ get_clans = get_clan
6654
6755 async def get_constants (self ):
6856 '''Get a profile object using a tag.'''
@@ -73,8 +61,7 @@ async def get_constants(self):
7361 if resp .status == 200 :
7462 data = await resp .json ()
7563 else :
76- print ('API is down. Please be patient.' )
77- return None
64+ raise ConnectionError (f'API not responding: { resp .status } ' )
7865
7966 return Constants (self , data )
8067
0 commit comments