|
1 | 1 | """This module is a wrapper for using the SquareCloud API""" |
2 | 2 | from __future__ import annotations |
3 | 3 |
|
4 | | -import io |
5 | 4 | import logging |
6 | 5 | from abc import ABC, abstractmethod |
7 | 6 | from io import BytesIO |
@@ -400,34 +399,55 @@ async def upload_app(self, file: File, |
400 | 399 | await self._listener.on_request(endpoint=endpoint, response=response) |
401 | 400 | return app |
402 | 401 |
|
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): |
404 | 403 | response: Response = await self._http.fetch_app_files_list(app_id, |
405 | 404 | 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) |
406 | 409 |
|
407 | 410 | if not response.response[0]: # type ignore |
408 | 411 | return |
409 | 412 | return [FileInfo(**data) for data in response.response] |
410 | 413 |
|
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): |
412 | 415 | 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) |
413 | 420 | if response.response: |
414 | 421 | return BytesIO(bytes(response.response.get('data'))) |
415 | 422 |
|
416 | 423 | async def create_app_file(self, app_id: str, file: File, |
417 | | - path: str): |
| 424 | + path: str, **kwargs): |
418 | 425 | if not isinstance(file, File): |
419 | 426 | raise SquareException( |
420 | 427 | 'the file must be an string or a squarecloud.File object') |
421 | 428 | 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) |
423 | 435 | file.bytes.close() |
424 | 436 |
|
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): |
426 | 438 | 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) |
427 | 443 | return response |
428 | 444 |
|
429 | | - async def statistics(self): |
| 445 | + async def statistics(self, **kwargs): |
430 | 446 | 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) |
431 | 451 | data = response.response['statistics'] |
432 | 452 | return StatisticsData(**data) |
433 | 453 |
|
|
0 commit comments