Skip to content

Commit eabd405

Browse files
committed
Add refetch param
1 parent 428bddf commit eabd405

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

codingame/clash_of_code.py

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def fetch(self):
177177
"""|maybe_coro|
178178
179179
Get and update the information about this Clash Of Code.
180+
181+
This modifies this object's own attributes in place.
180182
"""
181183

182184
if self._state.is_async:
@@ -197,14 +199,20 @@ def _fetch():
197199

198200
return _fetch()
199201

200-
def join(self):
202+
def join(self, refetch: bool = False):
201203
"""|maybe_coro|
202204
203205
Join this Clash Of Code.
204206
205207
You need to be logged in to join a Clash of Code or else a
206208
:exc:`~codingame.LoginRequired` will be raised.
207209
210+
Parameters
211+
-----------
212+
refetch: :class:`bool`
213+
Whether to update this object after joining.
214+
Default: `False`
215+
208216
Raises
209217
------
210218
:exc:`LoginRequired`
@@ -218,7 +226,7 @@ def join(self):
218226

219227
async def _join():
220228
try:
221-
data = await self._state.http.join_clash_of_code_by_handle(
229+
await self._state.http.join_clash_of_code_by_handle(
222230
self._state.codingamer.id, self.public_handle
223231
)
224232
except HTTPError as error:
@@ -229,13 +237,14 @@ async def _join():
229237

230238
raise # pragma: no cover
231239

232-
self._set_data(data)
240+
if refetch:
241+
await self.fetch()
233242

234243
else:
235244

236245
def _join():
237246
try:
238-
data = self._state.http.join_clash_of_code_by_handle(
247+
self._state.http.join_clash_of_code_by_handle(
239248
self._state.codingamer.id, self.public_handle
240249
)
241250
except HTTPError as error:
@@ -246,11 +255,12 @@ def _join():
246255

247256
raise # pragma: no cover
248257

249-
self._set_data(data)
258+
if refetch:
259+
self.fetch()
250260

251261
return _join()
252262

253-
def start(self):
263+
def start(self, refetch: bool = False):
254264
"""|maybe_coro|
255265
256266
Start this Clash Of Code.
@@ -262,6 +272,12 @@ def start(self):
262272
This sets the countdown to the start to 5s. You will need to fetch
263273
the Clash Of Code again in 5-10s.
264274
275+
Parameters
276+
-----------
277+
refetch: :class:`bool`
278+
Whether to update this object after starting.
279+
Default: `False`
280+
265281
Raises
266282
------
267283
:exc:`LoginRequired`
@@ -278,9 +294,6 @@ async def _start():
278294
await self._state.http.start_clash_of_code_by_handle(
279295
self._state.codingamer.id, self.public_handle
280296
)
281-
data = await self._state.http.get_clash_of_code_from_handle(
282-
self.public_handle
283-
)
284297
except HTTPError as error:
285298
if error.data["id"] in (504, 505, 506):
286299
raise ClashOfCodeError.from_id(
@@ -289,7 +302,8 @@ async def _start():
289302

290303
raise # pragma: no cover
291304

292-
self._set_data(data)
305+
if refetch:
306+
await self.fetch()
293307

294308
else:
295309

@@ -298,9 +312,6 @@ def _start():
298312
self._state.http.start_clash_of_code_by_handle(
299313
self._state.codingamer.id, self.public_handle
300314
)
301-
data = self._state.http.get_clash_of_code_from_handle(
302-
self.public_handle
303-
)
304315
except HTTPError as error:
305316
if error.data["id"] in (504, 505, 506):
306317
raise ClashOfCodeError.from_id(
@@ -309,18 +320,25 @@ def _start():
309320

310321
raise # pragma: no cover
311322

312-
self._set_data(data)
323+
if refetch:
324+
self.fetch()
313325

314326
return _start()
315327

316-
def leave(self):
328+
def leave(self, refetch: bool = False):
317329
"""|maybe_coro|
318330
319331
Leave this Clash Of Code.
320332
321333
You need to be logged in or else a
322334
:exc:`~codingame.LoginRequired` will be raised.
323335
336+
Parameters
337+
-----------
338+
refetch: :class:`bool`
339+
Whether to update this object after leaving.
340+
Default: `False`
341+
324342
Raises
325343
------
326344
:exc:`LoginRequired`
@@ -337,9 +355,6 @@ async def _leave():
337355
await self._state.http.leave_clash_of_code_by_handle(
338356
self._state.codingamer.id, self.public_handle
339357
)
340-
data = await self._state.http.get_clash_of_code_from_handle(
341-
self.public_handle
342-
)
343358
except HTTPError as error:
344359
if error.data["id"] in (504, 505, 506):
345360
raise ClashOfCodeError.from_id(
@@ -348,7 +363,8 @@ async def _leave():
348363

349364
raise # pragma: no cover
350365

351-
self._set_data(data)
366+
if refetch:
367+
await self.fetch()
352368

353369
else:
354370

@@ -357,9 +373,6 @@ def _leave():
357373
self._state.http.leave_clash_of_code_by_handle(
358374
self._state.codingamer.id, self.public_handle
359375
)
360-
data = self._state.http.get_clash_of_code_from_handle(
361-
self.public_handle
362-
)
363376
except HTTPError as error:
364377
if error.data["id"] in (504, 505, 506):
365378
raise ClashOfCodeError.from_id(
@@ -368,7 +381,8 @@ def _leave():
368381

369382
raise # pragma: no cover
370383

371-
self._set_data(data)
384+
if refetch:
385+
self.fetch()
372386

373387
return _leave()
374388

0 commit comments

Comments
 (0)