Skip to content

Commit

Permalink
Support for band
Browse files Browse the repository at this point in the history
  • Loading branch information
umbresp committed Feb 14, 2018
1 parent a17b655 commit db104c7
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 3 deletions.
2 changes: 1 addition & 1 deletion brawlstars.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion brawlstars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
80 changes: 80 additions & 0 deletions brawlstars/asyncclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down
78 changes: 78 additions & 0 deletions brawlstars/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down
Binary file added dist/brawlstars-0.2.2.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit db104c7

Please sign in to comment.