@@ -48,40 +48,28 @@ async def get_profile(self, *, tags):
4848 if resp .status == 200 :
4949 data = await resp .json ()
5050 else :
51- print ('API is down. Please be patient.' )
52- return None
51+ raise ConnectionError (f'API not responding: { resp .status } ' )
5352 return Profiles (self , data )
5453
5554 async def get_clans (self , * , tags ):
5655 '''Get a clan object using tag(s)'''
57- tags = tags .split (',' )
5856
59- if len (tags ) == 1 :
60- url = f'{ self .BASE } /clan/{ tags [0 ]} '
61- async with self .session .get (url ) as resp :
62- if resp .status == 200 :
63- data = await resp .json ()
64- else :
65- print ('API is down. Please be patient.' )
66- return None
67- return Clan (self , data )
57+ tags = ',' .join (tags )
6858
69- taglist = ''
70- i = 0
71- for tag in tags :
72- i += 1
73- taglist += tag [1 :]
74- if i != len (tags ):
75- taglist += ','
59+ url = f'{ self .BASE } /clan/{ tags } '
7660
77- url = f'{ self .BASE } /clan/{ taglist } '
7861 async with self .session .get (url ) as resp :
7962 if resp .status == 200 :
8063 data = await resp .json ()
8164 else :
82- print ('API is down. Please be patient.' )
83- return None
84- return Clans (self , data )
65+ raise ConnectionError (f'API not responding: { resp .status } ' )
66+
67+ if isinstance (data , list ):
68+ return [Clan (self , c ) for c in data ]
69+ else :
70+ return Clan (self , c )
71+
72+ get_clans = get_clan
8573
8674 async def get_constants (self ):
8775 '''Get a profile object using a tag.'''
@@ -92,8 +80,7 @@ async def get_constants(self):
9280 if resp .status == 200 :
9381 data = await resp .json ()
9482 else :
95- print ('API is down. Please be patient.' )
96- return None
83+ raise ConnectionError (f'API not responding: { resp .status } ' )
9784
9885 return Constants (self , data )
9986
0 commit comments