Skip to content

Commit

Permalink
Merge pull request #30 from 201st-Luka/new-features
Browse files Browse the repository at this point in the history
New features
  • Loading branch information
201st-Luka authored Aug 23, 2023
2 parents c8608a3 + bae4821 commit b21023a
Show file tree
Hide file tree
Showing 41 changed files with 458 additions and 164 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ good as I can.
- some "average" attributes for `Clan`-classes, `WarLog`-classes, ...
- attributes `king`, `queen`, `warden`, `royal_champion` for the `Player.heroes` attribute
- autosort for the `ClanCurrentWarRequest` members of the `member_list` attribute (sorted by the map position)

- events and an `EventClient`
---

If you find a bug, an error or want custom functionality, please tell
Expand Down
2 changes: 2 additions & 0 deletions pyclasher/api/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from .clan_rankings import ClanRankingsRequest
from .clan_search import ClanSearchRequest
from .clan_war_log import ClanWarLogRequest
from .clan_currentwar_leaguegroup import ClanCurrentwarLeaguegroupRequest
from .clan_warleagues_wars import ClanWarleaguesWarsRequest
# goldpass
from .gold_pass import GoldPassRequest
from .league import LeagueRequest
Expand Down
4 changes: 2 additions & 2 deletions pyclasher/api/requests/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self,
:param url_kwargs: the url kwargs that are to replace in raw_url
"""

if Client.initialised:
if Client.initialized():
global request_id

self._request_id = request_id
Expand Down Expand Up @@ -94,7 +94,7 @@ async def request(self):
"""
makes a request to the ClashOfClans API
"""
self.client = Client()
self.client = Client.get_instance()

if not self.client.is_running:
raise ClientIsNotRunning
Expand Down
4 changes: 3 additions & 1 deletion pyclasher/api/requests/builder_base_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

class BuilderBaseLeagueRequest(RequestModel, BuilderBaseLeague):
def __init__(self, league_id):
RequestModel.__init__(self, "builderbaseleagues/{league_id}", league_id=league_id)
RequestModel.__init__(self,
"builderbaseleagues/{league_id}",
league_id=league_id)
BuilderBaseLeague.__init__(self, None)
self.league_id = league_id
self._main_attribute = self.league_id
Expand Down
10 changes: 7 additions & 3 deletions pyclasher/api/requests/builder_base_leagues.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ class BuilderBaseLeaguesRequest(IterRequestModel):

def __init__(self, limit=None, after=None, before=None):
super().__init__("builderbaseleagues",
kwargs={'limit': limit, 'after': after, 'before': before})
kwargs={
'limit': limit,
'after': after,
'before': before
})
self._main_attribute = self._len
return

async def _async_request(self):
await super()._async_request()
async def request(self):
await super().request()
self._main_attribute = len(self)
return self
3 changes: 2 additions & 1 deletion pyclasher/api/requests/capital_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

class CapitalLeagueRequest(RequestModel, CapitalLeague):
def __init__(self, league_id):
RequestModel.__init__(self, "capitalleagues/{league_id}", league_id=league_id)
RequestModel.__init__(self, "capitalleagues/{league_id}",
league_id=league_id)
CapitalLeague.__init__(self, None)
self.league_id = league_id
self._main_attribute = self.league_id
Expand Down
6 changes: 5 additions & 1 deletion pyclasher/api/requests/capital_league_seasons.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class CapitalLeaguesRequest(IterRequestModel):

def __init__(self, limit=None, after=None, before=None):
super().__init__("capitalleagues",
kwargs={'limit': limit, 'after': after, 'before': before})
kwargs={
'limit': limit,
'after': after,
'before': before
})
self._main_attribute = self._len
return
17 changes: 6 additions & 11 deletions pyclasher/api/requests/clan.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,23 @@ def __init__(self, clan_tag):
"""

self.clan_tag = clan_tag
RequestModel.__init__(self, "clans/{clan_tag}", clan_tag=self.clan_tag)
RequestModel.__init__(self,
"clans/{clan_tag}",
clan_tag=self.clan_tag)
Clan.__init__(self, None)
self._main_attribute = self.clan_tag
return

@classmethod
def from_base_clan(cls, base_clan):
async def from_base_clan(cls, base_clan):
"""
method that returns the clan object of a BaseClan or a BaseClan subclass model
:param base_clan: The BaseClan or a BaseClan subclass model
:type base_clan: BaseClan
:return: returns a ClanRequest object
:rtype: ClanRequest
"""
self = await cls(base_clan.tag).request()
return self

async def async_from_base_clan():
self = await cls(base_clan.tag).request()
return self

try:
get_running_loop()
except RuntimeError:
return run(async_from_base_clan())
else:
return async_from_base_clan()
13 changes: 10 additions & 3 deletions pyclasher/api/requests/clan_builder_base_rankings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ class ClanBuilderBaseRankingsRequest(IterRequestModel):

def __init__(self, location_id,
limit=None, after=None, before=None):
self.location_id = location_id if isinstance(location_id, int) else location_id.id
super().__init__("locations/{location_id}/rankings/clans-builder-base", location_id=self.location_id,
kwargs={'limit': limit, 'after': after, 'before': before})
self.location_id = location_id if isinstance(location_id, int) \
else location_id.id
super().__init__("locations/{location_id}"
"/rankings/clans-builder-base",
location_id=self.location_id,
kwargs={
'limit': limit,
'after': after,
'before': before
})
self._main_attribute = self.location_id
return
10 changes: 8 additions & 2 deletions pyclasher/api/requests/clan_capital_raid_seasons.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ def __init__(self, clan_tag, limit=None, after=None, before=None):
"""

self.clan_tag = clan_tag
IterRequestModel.__init__(self, "clans/{clan_tag}/capitalraidseasons", clan_tag=clan_tag,
kwargs={'limit': limit, 'after': after, 'before': before})
IterRequestModel.__init__(self,
"clans/{clan_tag}/capitalraidseasons",
clan_tag=clan_tag,
kwargs={
'limit': limit,
'after': after,
'before': before
})
self._main_attribute = self.clan_tag
return
18 changes: 6 additions & 12 deletions pyclasher/api/requests/clan_current_war.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,22 @@ def __init__(self, clan_tag):
"""

self.clan_tag = clan_tag
RequestModel.__init__(self, "clans/{clan_tag}/currentwar", clan_tag=self.clan_tag)
RequestModel.__init__(self,
"clans/{clan_tag}/currentwar",
clan_tag=self.clan_tag)
ClanWar.__init__(self, None)
self._main_attribute = self.clan_tag
return

@classmethod
def from_base_clan(cls, base_clan):
async def from_base_clan(cls, base_clan):
"""
method that returns the clan object of a BaseClan or a BaseClan subclass model
:param base_clan: The BaseClan or a BaseClan subclass model
:type base_clan: BaseClan
:return: returns a ClanCurrentWarRequest object
:rtype: ClanCurrentWarRequest
"""
self = await cls(base_clan.tag).request()
return self

async def async_from_base_clan():
self = await cls(base_clan.tag).request()
return self

try:
get_running_loop()
except RuntimeError:
return run(async_from_base_clan())
else:
return async_from_base_clan()
2 changes: 1 addition & 1 deletion pyclasher/api/requests/clan_current_war.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ClanCurrentWarRequest(RequestModel, ClanWar):
...

@classmethod
def from_base_clan(cls, base_clan: BaseClan) -> ClanCurrentWarRequest | Coroutine[Any, Any, ClanCurrentWarRequest]:
async def from_base_clan(cls, base_clan: BaseClan) -> ClanCurrentWarRequest:
async def async_from_base_clan() -> ClanCurrentWarRequest:
...

Expand Down
40 changes: 40 additions & 0 deletions pyclasher/api/requests/clan_currentwar_leaguegroup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from asyncio import get_running_loop, run

from .abc import RequestModel
from ..models import ClanWarLeagueGroup


class ClanCurrentwarLeaguegroupRequest(RequestModel, ClanWarLeagueGroup):
"""
Retrieve information about clan's current clan war league group
"""
clan_tag = None

def __init__(self, clan_tag):
"""
initialisation of the clan currentwar leaguegroup request
:param clan_tag: Tag of the clan.
:type clan_tag: str
"""

self.clan_tag = clan_tag
RequestModel.__init__(self,
"clans/{clan_tag}/currentwar/leaguegroup",
clan_tag=self.clan_tag)
ClanWarLeagueGroup.__init__(self, None)
self._main_attribute = self.clan_tag
return

@classmethod
async def from_base_clan(cls, base_clan):
"""
method that returns the clan object of a BaseClan or a BaseClan subclass model
:param base_clan: The BaseClan or a BaseClan subclass model
:type base_clan: BaseClan
:return: returns a ClanRequest object
:rtype: ClanRequest
"""
self = await cls(base_clan.tag).request()
return self


14 changes: 14 additions & 0 deletions pyclasher/api/requests/clan_currentwar_leaguegroup.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .abc import RequestModel
from ..models import ClanWarLeagueGroup, BaseClan


class ClanCurrentwarLeaguegroupRequest(RequestModel, ClanWarLeagueGroup):
clan_tag: str = None

def __init__(self, clan_tag: str) -> None:
self.clan_tag = clan_tag
...

@classmethod
async def from_base_clan(cls, base_clan: BaseClan) -> ClanCurrentwarLeaguegroupRequest:
...
10 changes: 8 additions & 2 deletions pyclasher/api/requests/clan_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ def __init__(self, clan_tag, limit=None, after=None, before=None):
"""

self.clan_tag = clan_tag
IterRequestModel.__init__(self, "clans/{clan_tag}/members", clan_tag=clan_tag,
kwargs={'limit': limit, 'after': after, 'before': before})
IterRequestModel.__init__(self,
"clans/{clan_tag}/members",
clan_tag=clan_tag,
kwargs={
'limit': limit,
'after': after,
'before': before
})
self._main_attribute = self.clan_tag
return
9 changes: 7 additions & 2 deletions pyclasher/api/requests/clan_rankings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ class ClanRankingsRequest(IterRequestModel):
def __init__(self, location_id,
limit=None, after=None, before=None):
self.location_id = location_id if isinstance(location_id, int) else location_id.id
super().__init__("locations/{location_id}/rankings/clans", location_id=self.location_id,
kwargs={'limit': limit, 'after': after, 'before': before})
super().__init__("locations/{location_id}/rankings/clans",
location_id=self.location_id,
kwargs={
'limit': limit,
'after': after,
'before': before
})
self._main_attribute = self.location_id
return
44 changes: 30 additions & 14 deletions pyclasher/api/requests/clan_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@ class ClanSearchRequest(IterRequestModel):
_iter_rtype = Clan
_list_rtype = ClanList

def __init__(self, name=None, war_frequency=None, location=None, min_members=None,
max_members=None, min_clan_points=None, min_clan_level=None, label_ids=None,
limit=None, after=None, before=None) -> None:
def __init__(
self,
name=None,
war_frequency=None,
location=None,
min_members=None,
max_members=None,
min_clan_points=None,
min_clan_level=None,
label_ids=None,
limit=None,
after=None,
before=None
) -> None:
"""
initialisation of the clan request
:param name: Search clans by name. If name is used as part of search query, it needs to be at least
Expand Down Expand Up @@ -49,16 +60,21 @@ def __init__(self, name=None, war_frequency=None, location=None, min_members=Non
"""

self.clan_name = name
IterRequestModel.__init__(self, "clans",
kwargs={
'name': name,
'warFrequency': war_frequency.value if war_frequency is not None else None,
'locationId': location.value.id if location is not None else None,
'minMembers': min_members,
'maxMembers': max_members,
'minClanPoints': min_clan_points,
'minClanLevel': min_clan_level,
'labelIds': ",".join((label.value.id for label in label_ids)) if label_ids is not None else None,
'limit': limit, 'after': after, 'before': before})
IterRequestModel.__init__(
self,
"clans",
kwargs={
'name': name,
'warFrequency': war_frequency.value if war_frequency is not None else None,
'locationId': location.value.id if location is not None else None,
'minMembers': min_members,
'maxMembers': max_members,
'minClanPoints': min_clan_points,
'minClanLevel': min_clan_level,
'labelIds': ",".join(
(label.value.id for label in
label_ids)) if label_ids is not None else None,
'limit': limit, 'after': after,
'before': before})
self._main_attribute = self.clan_name
return
10 changes: 8 additions & 2 deletions pyclasher/api/requests/clan_war_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ def __init__(self, clan_tag, limit=None, after=None, before=None):
"""

self.clan_tag = clan_tag
IterRequestModel.__init__(self, "clans/{clan_tag}/warlog", clan_tag=self.clan_tag,
kwargs={'limit': limit, 'after': after, 'before': before})
IterRequestModel.__init__(self,
"clans/{clan_tag}/warlog",
clan_tag=self.clan_tag,
kwargs={
'limit': limit,
'after': after,
'before': before
})
self._main_attribute = self.clan_tag
return
15 changes: 15 additions & 0 deletions pyclasher/api/requests/clan_warleagues_wars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .abc import RequestModel
from ..models import ClanWarLeagueGroup


class ClanWarleaguesWarsRequest(RequestModel, ClanWarLeagueGroup):
"""
Retrieve information about individual clan war league war
"""

def __init__(self, war_tag):
self.war_tag = war_tag
super().__init__("clanwarleagues/wars/{war_tag}",
war_tag=self.war_tag)
self._main_attribute = self.war_tag
return
13 changes: 13 additions & 0 deletions pyclasher/api/requests/clan_warleagues_wars.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .abc import RequestModel
from ..models import ClanWarLeagueGroup


class ClanWarleaguesWarsRequest(RequestModel, ClanWarLeagueGroup):
"""
Retrieve information about individual clan war league war
"""

def __init__(self, war_tag) -> None:
self.war_tag: str = ...
self._main_attribute: str = ...
...
Loading

0 comments on commit b21023a

Please sign in to comment.