Skip to content

Commit 91d79a7

Browse files
refactor: on_request event added in some squarecloud.Client methods
1 parent 114eca1 commit 91d79a7

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

squarecloud/client.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""This module is a wrapper for using the SquareCloud API"""
22
from __future__ import annotations
33

4-
import io
54
import logging
65
from abc import ABC, abstractmethod
76
from io import BytesIO
@@ -400,34 +399,55 @@ async def upload_app(self, file: File,
400399
await self._listener.on_request(endpoint=endpoint, response=response)
401400
return app
402401

403-
async def app_files_list(self, app_id: str, path: str):
402+
async def app_files_list(self, app_id: str, path: str, **kwargs):
404403
response: Response = await self._http.fetch_app_files_list(app_id,
405404
path)
405+
if not kwargs.get('avoid_listener'):
406+
endpoint: Endpoint = response.route.endpoint
407+
await self._listener.on_request(endpoint=endpoint,
408+
response=response)
406409

407410
if not response.response[0]: # type ignore
408411
return
409412
return [FileInfo(**data) for data in response.response]
410413

411-
async def read_app_file(self, app_id: str, path: str):
414+
async def read_app_file(self, app_id: str, path: str, **kwargs):
412415
response: Response = await self._http.read_app_file(app_id, path)
416+
if not kwargs.get('avoid_listener'):
417+
endpoint: Endpoint = response.route.endpoint
418+
await self._listener.on_request(endpoint=endpoint,
419+
response=response)
413420
if response.response:
414421
return BytesIO(bytes(response.response.get('data')))
415422

416423
async def create_app_file(self, app_id: str, file: File,
417-
path: str):
424+
path: str, **kwargs):
418425
if not isinstance(file, File):
419426
raise SquareException(
420427
'the file must be an string or a squarecloud.File object')
421428
file_bytes = list(file.bytes.read())
422-
await self._http.create_app_file(app_id, file_bytes, path)
429+
response: Response = await self._http.create_app_file(app_id,
430+
file_bytes, path)
431+
if not kwargs.get('avoid_listener'):
432+
endpoint: Endpoint = response.route.endpoint
433+
await self._listener.on_request(endpoint=endpoint,
434+
response=response)
423435
file.bytes.close()
424436

425-
async def delete_app_file(self, app_id: str, path: str):
437+
async def delete_app_file(self, app_id: str, path: str, **kwargs):
426438
response: Response = await self._http.file_delete(app_id, path)
439+
if not kwargs.get('avoid_listener'):
440+
endpoint: Endpoint = response.route.endpoint
441+
await self._listener.on_request(endpoint=endpoint,
442+
response=response)
427443
return response
428444

429-
async def statistics(self):
445+
async def statistics(self, **kwargs):
430446
response: Response = await self._http.get_statistics()
447+
if not kwargs.get('avoid_listener'):
448+
endpoint: Endpoint = response.route.endpoint
449+
await self._listener.on_request(endpoint=endpoint,
450+
response=response)
431451
data = response.response['statistics']
432452
return StatisticsData(**data)
433453

0 commit comments

Comments
 (0)