Skip to content

Commit 9faa1b4

Browse files
committed
[Reversed coc.login changes] Reverted making coc.login a coroutine
1 parent b6cb5ad commit 9faa1b4

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ This example will get a player with a certain tag, and search for 5 clans with a
5252
5353
5454
async def main():
55+
coc_client = coc.Client()
5556
try:
56-
coc_client = await coc.login("email", "password")
57+
await coc_client.login("email", "password")
5758
except coc.invalidcredentials as error:
5859
exit(error)
5960
@@ -105,10 +106,9 @@ whenever someone joins the clan or a member of the clan donates troops.
105106
106107
107108
async def main():
109+
coc_client = coc.EVentsClient()
108110
try:
109-
coc_client = await coc.login("email",
110-
"password",
111-
client=coc.EventsClient)
111+
await coc.login("email", "password")
112112
except coc.InvalidCredentials as error:
113113
exit(error)
114114

coc/login.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from .events import EventsClient
2929

3030

31-
async def login(
31+
def login(
3232
email: str, password: str, client: Type[Union[Client, EventsClient]] = Client, **kwargs
3333
) -> Union[Client, EventsClient]:
3434
r"""Eases logging into the coc.py Client.
@@ -50,9 +50,9 @@ async def login(
5050
**kwargs
5151
Any kwargs you wish to pass into the Client object.
5252
"""
53-
coc_client = client(**kwargs)
54-
await coc_client.login(email, password)
55-
return coc_client
53+
instance = client(**kwargs)
54+
instance.loop.run_until_complete(instance.login(email, password))
55+
return instance
5656

5757

5858
def login_with_keys(*keys: str, client: Type[Union[Client, EventsClient]] = Client, **kwargs) -> Union[Client, EventsClient]:

examples/discord_bot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,12 @@ async def current_war_status(ctx, clan_tag):
255255
async def main():
256256
logging.basicConfig(level=logging.ERROR)
257257

258+
coc_client = coc.Client()
259+
258260
# Attempt to log into CoC API using your credentials.
259261
try:
260-
coc_client = await coc.login(os.environ.get("DEV_SITE_EMAIL"),
261-
os.environ.get("DEV_SITE_PASSWORD"))
262+
await coc_client.login(os.environ.get("DEV_SITE_EMAIL"),
263+
os.environ.get("DEV_SITE_PASSWORD"))
262264
except coc.InvalidCredentials as error:
263265
exit(error)
264266

examples/discord_bot_with_cogs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,13 @@ async def on_clan_trophy_change(old_clan, new_clan):
223223

224224

225225
async def main():
226+
coc_client = coc.EventsClient()
227+
226228
# Attempt to log into CoC API using your credentials. To enable events,
227229
# you must use the coc.EventsClient class
228230
try:
229-
coc_client = await coc.login(os.environ.get("DEV_SITE_EMAIL"),
230-
os.environ.get("DEV_SITE_PASSWORD"),
231-
client=coc.EventsClient)
231+
await coc_client.login(os.environ.get("DEV_SITE_EMAIL"),
232+
os.environ.get("DEV_SITE_PASSWORD"))
232233
except coc.InvalidCredentials as error:
233234
exit(error)
234235

examples/events_example.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,14 @@ async def season_started():
104104
str(utils.get_season_end()))
105105

106106

107-
108107
async def main() -> None:
108+
coc_client = coc.EventsClient()
109109

110110
# Attempt to log into CoC API using your credentials. You must use the
111111
# coc.EventsClient to enable event listening
112112
try:
113-
coc_client = await coc.login(os.environ.get("DEV_SITE_EMAIL"),
114-
os.environ.get("DEV_SITE_PASSWORD"),
115-
client=coc.EventsClient)
113+
await coc_client.login(os.environ.get("DEV_SITE_EMAIL"),
114+
os.environ.get("DEV_SITE_PASSWORD"))
116115
except coc.InvalidCredentials as error:
117116
exit(error)
118117

examples/war_logs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ async def get_warlog_opponents_from_clan_name(client: coc.Client, name: str, no_
4444

4545

4646
async def main():
47+
coc_client = coc.Client()
4748
try:
48-
coc_client = await coc.login(os.environ.get("DEV_SITE_EMAIL"),
49-
os.environ.get("DEV_SITE_PASSWORD"))
49+
await coc_client.login(os.environ.get("DEV_SITE_EMAIL"),
50+
os.environ.get("DEV_SITE_PASSWORD"))
5051
except coc.InvalidCredentials as error:
5152
exit(error)
5253

0 commit comments

Comments
 (0)