22from .utils import bstag
33
44
5- __all__ = ['Player' , 'Club' , 'Members' , 'Ranking' , 'BattleLog' , 'Constants' ]
5+ __all__ = ['Player' , 'Club' , 'Members' , 'Ranking' , 'BattleLog' , 'Constants' , 'Brawlers' ]
6+
67
78class BaseBox :
89 def __init__ (self , client , data ):
@@ -11,14 +12,7 @@ def __init__(self, client, data):
1112
1213 def from_data (self , data ):
1314 self .raw_data = data
14- if isinstance (data , list ):
15- self ._boxed_data = BoxList (
16- data , camel_killer_box = True
17- )
18- else :
19- self ._boxed_data = Box (
20- data , camel_killer_box = True
21- )
15+ self ._boxed_data = Box (data , camel_killer_box = True )
2216 return self
2317
2418 def __getattr__ (self , attr ):
@@ -37,6 +31,17 @@ def __getitem__(self, item):
3731 raise IndexError ('No such index: {}' .format (item ))
3832
3933
34+ class BaseBoxList (BaseBox ):
35+ def from_data (self , data ):
36+ data = data ['items' ]
37+ self .raw_data = data
38+ self ._boxed_data = BoxList (data , camel_killer_box = True )
39+ return self
40+
41+ def __len__ (self ):
42+ return sum (1 for i in self )
43+
44+
4045class Player (BaseBox ):
4146 """
4247 Returns a full player object with all of its attributes.
@@ -85,47 +90,45 @@ def get_members(self):
8590 return self .client ._get_model (url , model = Members )
8691
8792
88- class Members (BaseBox ):
93+ class Members (BaseBoxList ):
8994 """
9095 Returns the members in a club.
9196 """
9297
93- def __init__ (self , client , data ):
94- super ().__init__ (client , data ['items' ])
95-
96- def __len__ (self ):
97- return sum (1 for i in self )
98-
9998 def __repr__ (self ):
10099 return '<Members object count={}>' .format (len (self ))
101100
102101
103- class Ranking (BaseBox ):
102+ class Ranking (BaseBoxList ):
104103 """
105104 Returns a player or club ranking that contains a list of players or clubs.
106105 """
107106
108- def __init__ (self , client , data ):
109- super ().__init__ (client , data ['items' ])
110-
111- def __len__ (self ):
112- return sum (1 for i in self )
113-
114107 def __repr__ (self ):
115108 return '<Ranking object count={}>' .format (len (self ))
116109
117110
118- class BattleLog (BaseBox ):
111+ class BattleLog (BaseBoxList ):
119112 """
120113 Returns a full player battle object with all of its attributes.
121114 """
122-
123- def __init__ (self , client , data ):
124- super ().__init__ (client , data ['items' ])
115+ pass
125116
126117
127118class Constants (BaseBox ):
128119 """
129120 Returns some Brawl Stars constants.
130121 """
131122 pass
123+
124+
125+ class Brawlers (BaseBoxList ):
126+ """
127+ Returns list of available brawlers and information about them.
128+ """
129+
130+ def __repr__ (self ):
131+ return '<Brawlers object count={}>' .format (len (self ))
132+
133+ def __str__ (self ):
134+ return 'Here {} brawlers' .format (len (self ))
0 commit comments