Skip to content

Commit d8400b8

Browse files
♻️ refactor: rename BackupData to Backup and introduce BackupInfo in data.py
- Updated imports and type annotations in `squarecloud/__init__.py`, `squarecloud/app.py`, `squarecloud/client.py`, `squarecloud/listeners/*` to reflect the renaming. - Modified `AppCache` and `Client` methods to use `Backup` instead of `BackupData`. - Refactored `BackupData` class to `Backup` and added `BackupInfo` class in `squarecloud/data.py`.
1 parent d1c57a7 commit d8400b8

File tree

6 files changed

+47
-29
lines changed

6 files changed

+47
-29
lines changed

squarecloud/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from .client import Client
66
from .data import (
77
AppData,
8-
BackupData,
8+
Backup,
9+
BackupInfo,
910
DeployData,
1011
DomainAnalytics,
1112
FileInfo,

squarecloud/app.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from .data import (
1212
AppData,
13-
BackupData,
13+
Backup,
1414
DeployData,
1515
DomainAnalytics,
1616
FileInfo,
@@ -46,7 +46,7 @@ def __init__(self) -> None:
4646
"""
4747
self._status: StatusData | None = None
4848
self._logs: LogsData | None = None
49-
self._backup: BackupData | None = None
49+
self._backup: Backup | None = None
5050
self._app_data: AppData | None = None
5151

5252
@property
@@ -72,13 +72,13 @@ def logs(self) -> LogsData:
7272
return self._logs
7373

7474
@property
75-
def backup(self) -> BackupData:
75+
def backup(self) -> Backup:
7676
"""
77-
The backup method is a property that returns the cached BackupData of
77+
The backup method is a property that returns the cached Backup of
7878
the application.
7979
8080
:return: The value of the _backup attribute
81-
:rtype: BackupData
81+
:rtype: Backup
8282
"""
8383
return self._backup
8484

@@ -111,7 +111,7 @@ def update(self, *args):
111111
The update method is used to update the data of a given instance.
112112
It takes in an arbitrary number of arguments, and updates the
113113
corresponding data if it is one of the following types:
114-
StatusData, LogsData, BackupData or AppData.
114+
StatusData, LogsData, Backup or AppData.
115115
If any other type is provided as an argument to this function,
116116
a SquareException will be raised.
117117
@@ -123,7 +123,7 @@ def update(self, *args):
123123
self._status = arg
124124
elif isinstance(arg, LogsData):
125125
self._logs = arg
126-
elif isinstance(arg, BackupData):
126+
elif isinstance(arg, Backup):
127127
self._backup = arg
128128
elif isinstance(arg, AppData):
129129
self._app_data = arg
@@ -133,7 +133,7 @@ def update(self, *args):
133133
for i in [
134134
StatusData,
135135
LogsData,
136-
BackupData,
136+
Backup,
137137
AppData,
138138
]
139139
]
@@ -463,15 +463,15 @@ async def status(self, *_args, **__kwargs) -> StatusData:
463463

464464
@_update_cache
465465
@_notify_listener(Endpoint.backup())
466-
async def backup(self, *_args, **__kwargs) -> BackupData:
466+
async def backup(self, *_args, **__kwargs) -> Backup:
467467
"""
468468
The backup function is used to create a backup of the application.
469469
470470
:param self: Refer to the class instance
471-
:return: A BackupData object
472-
:rtype: BackupData
471+
:return: A Backup object
472+
:rtype: Backup
473473
"""
474-
backup: BackupData = await self.client.backup(self.id)
474+
backup: Backup = await self.client.backup(self.id)
475475
return backup
476476

477477
async def start(self) -> Response:

squarecloud/client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from typing_extensions import deprecated
99

1010
from .app import Application
11-
from .data import (
11+
from .data import ( # BackupInfo,
1212
AppData,
13-
BackupData,
13+
Backup,
1414
DeployData,
1515
DomainAnalytics,
1616
FileInfo,
@@ -329,14 +329,14 @@ async def restart_app(self, app_id: str, **_kwargs) -> Response:
329329
return await self._http.restart_application(app_id)
330330

331331
@_notify_listener(Endpoint.backup())
332-
async def backup(self, app_id: str, **_kwargs) -> BackupData:
332+
async def backup(self, app_id: str, **_kwargs) -> Backup:
333333
"""
334334
The backup method is used to backup an application.
335335
336336
:param app_id: Specify the application id
337337
:param _kwargs: Keyword arguments
338-
:return: A BackupData object
339-
:rtype: BackupData
338+
:return: A Backup object
339+
:rtype: Backup
340340
341341
:raises NotFoundError: Raised when the request status code is 404
342342
:raises BadRequestError: Raised when the request status code is 400
@@ -347,7 +347,9 @@ async def backup(self, app_id: str, **_kwargs) -> BackupData:
347347
"""
348348
response: Response = await self._http.backup(app_id)
349349
payload: dict[str, Any] = response.response
350-
return BackupData(**payload)
350+
return Backup(**payload)
351+
352+
# async def app_backups(self) -> list[BackupInfo]:
351353

352354
@_notify_listener(Endpoint.delete_app())
353355
async def delete_app(self, app_id: str, **_kwargs) -> Response:

squarecloud/data.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
from pydantic import confloat, conint
77
from pydantic.dataclasses import dataclass
88

9-
# pylint: disable=too-many-instance-attributes
10-
# pylint: disable=invalid-name
11-
129

1310
@dataclass(frozen=True)
1411
class PlanData:
@@ -197,16 +194,27 @@ def to_dict(self):
197194

198195

199196
@dataclass(frozen=True)
200-
class BackupData:
197+
class BackupInfo:
198+
name: str
199+
size: int
200+
modified: datetime
201+
key: str
202+
203+
204+
@dataclass(frozen=True)
205+
class Backup:
201206
"""
202207
Backup data class
203208
204-
:ivar downloadURL: Url for download your backup
209+
:ivar url: Url for download your backup
210+
:ivar key: The backup's key
205211
206-
:type downloadURL: str
212+
:type url: str
213+
:type key: str
207214
"""
208215

209-
downloadURL: str
216+
url: str
217+
key: str
210218

211219
def to_dict(self):
212220
return self.__dict__.copy()
@@ -285,10 +293,17 @@ def to_dict(self):
285293
return self.__dict__.copy()
286294

287295

296+
@dataclass(frozen=True)
297+
class AnalyticsTotal:
298+
visits: int
299+
megabytes: float
300+
bytes: int
301+
302+
288303
@dataclass(frozen=True)
289304
class DomainAnalytics:
290305
hostname: str
291-
total: list[Any]
306+
total: list[AnalyticsTotal]
292307
countries: list[Any]
293308
methods: list[Any]
294309
referers: list[Any]

squarecloud/listeners/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,5 @@ def cast_to_pydantic_model(
165165
data.AppData,
166166
data.StatusData,
167167
data.LogsData,
168-
data.BackupData,
168+
data.Backup,
169169
]

squarecloud/listeners/capture_listener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
data.AppData,
1414
data.StatusData,
1515
data.LogsData,
16-
data.BackupData,
16+
data.Backup,
1717
]
1818

1919

0 commit comments

Comments
 (0)