Skip to content

Commit

Permalink
huge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
umbresp committed Feb 23, 2018
1 parent a64643c commit f606253
Show file tree
Hide file tree
Showing 2 changed files with 238 additions and 4 deletions.
122 changes: 121 additions & 1 deletion brawlstars/asyncclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,50 @@ async def get_band(self, tag):
band = Band(data)
return band

async def get_player_leaderboard(self):

try:
async with self.session.get(self._base_url + 'leaderboards/players', 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 ValueError:
raise MissingData('data')
except:
raise InvalidArg('tag')


data = Box(data)
data = PlayerLeaderboard(data)
return data

async def get_band_leaderboard(self):

try:
async with self.session.get(self._base_url + 'leaderboards/bands', 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 ValueError:
raise MissingData('data')
except:
raise InvalidArg('tag')


data = Box(data)
data = BandLeaderboard(data)
return data

class Player(Box):

def __str__(self):
Expand Down Expand Up @@ -191,7 +235,7 @@ async def get_id(self):
async def get_members(self):
try:
memberList = self.bandMembers
except AttributError:
except AttributeError:
return None
members = []
for i in memberList:
Expand Down Expand Up @@ -232,3 +276,79 @@ def __str__(self):

def __repr__(self):
return '<Asynchronous Brawler trophies = ' + self.trophies + ' name = ' + self.name + '>'

class PlayerLeaderboard(Box):

def __str__(self):
return 'Player Leaderboard'

def __repr__(self):
return '<Asynchronous Player Leaderboard>'

async def get_players(self):
try:
memberList = self.players
except AttributeError:
return None
members = []
for i in memberList:
thing = Box(i)
thing = RankedPlayer(thing)
members.append(thing)

return members

class RankedPlayer(Box):

def __str__(self):
return self.name + ' (#' + self.tag + '), ranked #' + self.positionInLeaderboard

def __repr__(self):
return '<Asynchronous RankedPlayer name = ' + self.name + ' tag = ' + self.tag + ' rank = ' + self.positionInLeaderboard + '>'

async def get_id(self):
try:
ret = self.id
except AttributeError:
return None
ret = Box(ret)
ret = Id(ret)
return ret

class BandLeaderboard(Box):

def __str__(self):
return 'Band Leaderboard'

def __repr__(self):
return '<Asynchronous Band Leaderboard>'

async def get_bands(self):
try:
memberList = self.bands
except AttributeError:
return None
members = []
for i in memberList:
thing = Box(i)
thing = RankedBand(thing)
members.append(thing)

return members

class RankedBand(Box):

def __str__(self):
return self.name + ' (#' + self.tag + '), ranked #' + self.positionInLeaderboard

def __repr__(self):
return '<Asynchronous RankedBand name = ' + self.name + ' tag = ' + self.tag + ' rank = ' + self.positionInLeaderboard + '>'

async def get_id(self):
try:
ret = self.id
except AttributeError:
return None
ret = Box(ret)
ret = Id(ret)
return ret
120 changes: 117 additions & 3 deletions brawlstars/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,44 @@ def get_band(self, tag):
band = Band(data)
return band

def get_player_leaderboard(self):

try:
resp = requests.get(self._base_url + 'leaderboards/players', headers=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 ValueError:
raise MissingData('data')
except:
raise Timeout()

data = Box(data)
data = PlayerLeaderboard(data)
return data

def get_band_leaderboard(self):

try:
resp = requests.get(self._base_url + 'leaderboards/bands', headers=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 ValueError:
raise MissingData('data')
except:
raise Timeout()

data = Box(data)
data = BandLeaderboard(data)
return data

class Player(Box):

def __str__(self):
Expand Down Expand Up @@ -140,7 +178,7 @@ def get_brawlers(self):
def get_band(self):
try:
band = self.band
except AttributError:
except AttributeError:
return None
band = Box(band)
band = MinimalBand(band)
Expand Down Expand Up @@ -184,7 +222,7 @@ def get_id(self):
def get_members(self):
try:
memberList = self.bandMembers
except AttributError:
except AttributeError:
return None
members = []
for i in memberList:
Expand Down Expand Up @@ -225,4 +263,80 @@ def __str__(self):
return self.name + ' (' + self.trophies + ' trophies)'

def __repr__(self):
return '<Brawler trophies = ' + self.trophies + ' name = ' + self.name + '>'
return '<Brawler trophies = ' + self.trophies + ' name = ' + self.name + '>'

class PlayerLeaderboard(Box):

def __str__(self):
return 'Player Leaderboard'

def __repr__(self):
return '<Player Leaderboard>'

def get_players(self):
try:
memberList = self.players
except AttributeError:
return None
members = []
for i in memberList:
thing = Box(i)
thing = RankedPlayer(thing)
members.append(thing)

return members

class RankedPlayer(Box):

def __str__(self):
return self.name + ' (#' + self.tag + '), ranked #' + self.positionInLeaderboard

def __repr__(self):
return '<RankedPlayer name = ' + self.name + ' tag = ' + self.tag + ' rank = ' + self.positionInLeaderboard + '>'

def get_id(self):
try:
ret = self.id
except AttributeError:
return None
ret = Box(ret)
ret = Id(ret)
return ret

class BandLeaderboard(Box):

def __str__(self):
return 'Band Leaderboard'

def __repr__(self):
return '<Band Leaderboard>'

def get_bands(self):
try:
memberList = self.bands
except AttributeError:
return None
members = []
for i in memberList:
thing = Box(i)
thing = RankedBand(thing)
members.append(thing)

return members

class RankedBand(Box):

def __str__(self):
return self.name + ' (#' + self.tag + '), ranked #' + self.positionInLeaderboard

def __repr__(self):
return '<RankedBand name = ' + self.name + ' tag = ' + self.tag + ' rank = ' + self.positionInLeaderboard + '>'

async def get_id(self):
try:
ret = self.id
except AttributeError:
return None
ret = Box(ret)
ret = Id(ret)
return ret

0 comments on commit f606253

Please sign in to comment.