diff --git a/brawlstars.egg-info/PKG-INFO b/brawlstars.egg-info/PKG-INFO index 161e064..0433514 100644 --- a/brawlstars.egg-info/PKG-INFO +++ b/brawlstars.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: brawlstars -Version: 0.2.2 +Version: 0.2.3 Summary: A wrapper, both asynchronous and not, for the Brawl Stars API made by Zihad! Home-page: https://github.com/umbresp/brawlstars Author: Umbresp diff --git a/brawlstars/__init__.py b/brawlstars/__init__.py index 0dcf7c2..e995e5c 100644 --- a/brawlstars/__init__.py +++ b/brawlstars/__init__.py @@ -4,5 +4,5 @@ __author__ = 'Umbresp' __title__ = 'brawlstars' __license__ = 'MIT' -__version__ = '0.2.2' +__version__ = '0.2.3' __github__ = 'https://www.github.com/umbresp/brawlstars' diff --git a/brawlstars/asyncclient.py b/brawlstars/asyncclient.py index 01de424..9771ec3 100644 --- a/brawlstars/asyncclient.py +++ b/brawlstars/asyncclient.py @@ -51,6 +51,31 @@ async def get_player(self, tag=None): player = Player(data) return player + async def get_band(self, tag=None): + if tag is None: + raise MissingArg('tag') + + tag = tag.strip("#") + tag = tag.upper() + + try: + async with self.session.get(f'{self.baseUrl}bands/{tag}', timeout=self.timeout, headers=self.headers) as resp: + if resp.status == 200: + data = await resp.json() + elif 500 > resp.status > 400: + raise HTTPError(resp.status) + else: + raise Error() + except asyncio.TimeoutError: + raise Timeout() + except Exception: + raise InvalidArg('tag') + + + data = Box(data) + band = Band(data) + return band + class Player(Box): async def get_id(self): @@ -76,6 +101,61 @@ async def get_brawlers(self): return something + async def get_band(self): + try: + band = self.band + except AttributError: + return None + band = Box(band) + band = MinimalBand(band) + return band + +class MinimalBand(Box): + + async def get_id(self): + try: + ret = self.id + except AttributeError: + return None + ret = Box(ret) + ret = Id(ret) + return ret + +class Band(Box): + + async def get_id(self): + try: + ret = self.id + except AttributeError: + return None + ret = Box(ret) + ret = Id(ret) + return ret + + async def get_members(self): + try: + memberList = self.bandMembers + except AttributError: + return None + members = [] + for i in memberList: + thing = Box(i) + thing = Member(thing) + members.append(thing) + + return members + +class Member(Box): + + async def get_id(self): + try: + ret = self.id + except AttributeError: + return None + ret = Box(ret) + ret = Id(ret) + return ret + class Id(Box): pass diff --git a/brawlstars/client.py b/brawlstars/client.py index f7fb1b2..6ef9bd0 100644 --- a/brawlstars/client.py +++ b/brawlstars/client.py @@ -46,6 +46,28 @@ def get_player(self, tag=None): player = Player(data) return player + def get_band(self, tag=None): + if tag is None: + raise MissingArg('tag') + + tag = tag.strip("#") + tag = tag.upper() + + try: + resp = requests.get(f'{self.baseUrl}bands/{tag}', params=self.headers, timeout=self.timeout) + if resp.status_code == 200: + data = resp.json() + elif 500 > resp.status_code > 400: + raise HTTPError(resp.status_code) + else: + raise Error() + except: + raise Timeout() + + data = Box(data) + band = Band(data) + return band + class Player(Box): def get_id(self): @@ -71,6 +93,62 @@ def get_brawlers(self): return something + def get_band(self): + try: + band = self.band + except AttributError: + return None + band = Box(band) + band = MinimalBand(band) + return band + + +class MinimalBand(Box): + + def get_id(self): + try: + ret = self.id + except AttributeError: + return None + ret = Box(ret) + ret = Id(ret) + return ret + +class Band(Box): + + def get_id(self): + try: + ret = self.id + except AttributeError: + return None + ret = Box(ret) + ret = Id(ret) + return ret + + def get_members(self): + try: + memberList = self.bandMembers + except AttributError: + return None + members = [] + for i in memberList: + thing = Box(i) + thing = Member(thing) + members.append(thing) + + return members + +class Member(Box): + + def get_id(self): + try: + ret = self.id + except AttributeError: + return None + ret = Box(ret) + ret = Id(ret) + return ret + class Id(Box): pass diff --git a/dist/brawlstars-0.2.2.tar.gz b/dist/brawlstars-0.2.2.tar.gz new file mode 100644 index 0000000..bcea9e9 Binary files /dev/null and b/dist/brawlstars-0.2.2.tar.gz differ diff --git a/setup.py b/setup.py index d601aed..b2c8b4e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='brawlstars', - version='0.2.2', + version='0.2.3', description='A wrapper, both asynchronous and not, for the Brawl Stars API made by Zihad!', long_description="I am bad at writing descriptions. TODO", url='https://github.com/umbresp/brawlstars',