Skip to content

Commit d0ebb2d

Browse files
📝 docs: update docstrings and endpoint paths in endpoints.py
- Improved docstrings for better clarity and consistency in `squarecloud/http/endpoints.py`.
1 parent 1fbb3ce commit d0ebb2d

File tree

1 file changed

+51
-36
lines changed

1 file changed

+51
-36
lines changed

squarecloud/http/endpoints.py

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class Endpoint:
5-
"""Endpoint"""
5+
"""Class representing an API endpoint."""
66

77
ENDPOINTS_V2 = {
88
'USER': {'METHOD': 'GET', 'PATH': '/users/me'},
@@ -58,55 +58,47 @@ class Endpoint:
5858

5959
def __init__(self, name: str) -> None:
6060
"""
61-
The __init__ function is called when the class is instantiated.
62-
It sets up the instance of the class, and defines its attributes.
63-
The __init__ function takes in a name parameter, which it uses to look
64-
up an endpoint from ENDPOINTS_V2.
65-
ENDPOINTS_V2 is a dictionary that contains all of our endpoints for
66-
version 2 of our API.
61+
Initialize an Endpoint instance with the given name.
6762
68-
:param self: Represent the instance of the class
69-
:param name: str: Set the name of the endpoint
70-
:return: None
63+
:param name: The name of the endpoint.
64+
:raises ValueError: If the endpoint name is invalid.
7165
"""
7266
if not (endpoint := self.ENDPOINTS_V2.get(name)):
7367
raise ValueError(f"Invalid endpoint: '{name}'")
7468
self.name: str = name
7569
self.method: str = endpoint['METHOD']
7670
self.path: str = endpoint['PATH']
7771

78-
def __eq__(self, other: Endpoint):
72+
def __eq__(self, other: object) -> bool:
7973
"""
80-
The __eq__ function is used to compare two objects of the same class.
81-
It returns True if they are equal, and False otherwise.
74+
Compare two Endpoint instances for equality.
8275
83-
:param self: Refer to the current instance of the class
84-
:param other: Endpoint: Check if the other object is an instance of
85-
endpoint
86-
:return: A boolean value
76+
:param other: The other Endpoint instance to compare.
77+
:return: True if both instances have the same name, otherwise False.
8778
"""
8879
return isinstance(other, Endpoint) and self.name == other.name
8980

90-
def __repr__(self):
81+
def __repr__(self) -> str:
9182
"""
92-
The __repr__ function is used to compute the "official"
93-
string representation of an object.
94-
This is how you would make an object of the class. The goal of
83+
Return the official string representation of the Endpoint instance.
9584
96-
:param self: Represent the instance of the class
97-
:return: A string that is the representation of an object
85+
:return: A string representation of the Endpoint instance.
9886
"""
9987
return f"{Endpoint.__name__}('{self.name}')"
10088

10189
@classmethod
10290
def user(cls) -> Endpoint:
103-
"""Returns an Endpoint object that represents the /user endpoint."""
91+
"""
92+
Returns an Endpoint object that represents the
93+
/user endpoint.
94+
"""
10495
return cls('USER')
10596

10697
@classmethod
10798
def app_data(cls) -> Endpoint:
10899
"""
109-
Returns an Endpoint object that represents the /apps/{app_id} endpoint.
100+
Returns an Endpoint object that represents the
101+
/apps/{app_id} endpoint.
110102
"""
111103
return cls('APP_DATA')
112104

@@ -154,7 +146,7 @@ def restart(cls) -> Endpoint:
154146
def backup(cls) -> Endpoint:
155147
"""
156148
Returns an Endpoint object that represents the
157-
/apps/{app_id}/backup endpoint.
149+
/apps/{app_id}/backups endpoint.
158150
"""
159151
return cls('BACKUP')
160152

@@ -170,15 +162,15 @@ def commit(cls) -> Endpoint:
170162
def delete_app(cls) -> Endpoint:
171163
"""
172164
Returns an Endpoint object that represents the
173-
/apps/{app_id}/delete endpoint.
165+
/apps/{app_id} endpoint.
174166
"""
175167
return cls('DELETE_APP')
176168

177169
@classmethod
178170
def upload(cls) -> Endpoint:
179171
"""
180172
Returns an Endpoint object that represents the
181-
/apps/upload endpoint.
173+
/apps endpoint.
182174
"""
183175
return cls('UPLOAD_APP')
184176

@@ -215,38 +207,61 @@ def files_delete(cls) -> Endpoint:
215207
return cls('FILES_DELETE')
216208

217209
@classmethod
218-
def last_deploys(cls):
210+
def last_deploys(cls) -> Endpoint:
219211
"""
220212
Returns an Endpoint object that represents the
221-
/apps/{app_id}/deploy/list endpoint.
213+
/apps/{app_id}/deployments endpoint.
222214
"""
223-
224215
return cls('LAST_DEPLOYS')
225216

226217
@classmethod
227-
def github_integration(cls):
218+
def github_integration(cls) -> Endpoint:
228219
"""
229220
Returns an Endpoint object that represents the
230-
/apps/{app_id}/deploy/git-webhook endpoint.
221+
/apps/{app_id}/deploy/webhook endpoint.
231222
"""
232223
return cls('GITHUB_INTEGRATION')
233224

234225
@classmethod
235-
def domain_analytics(cls):
226+
def domain_analytics(cls) -> Endpoint:
236227
"""
237228
Returns an Endpoint object that represents the
238229
/apps/{app_id}/network/analytics endpoint.
239230
"""
240231
return cls('DOMAIN_ANALYTICS')
241232

242233
@classmethod
243-
def custom_domain(cls):
234+
def custom_domain(cls) -> Endpoint:
244235
"""
245236
Returns an Endpoint object that represents the
246-
/apps/{app_id}/network/custom/{custom_domain} endpoint.
237+
/apps/{app_id}/network/custom endpoint.
247238
"""
248239
return cls('CUSTOM_DOMAIN')
249240

241+
@classmethod
242+
def all_backups(cls) -> Endpoint:
243+
"""
244+
Returns an Endpoint object that represents the
245+
/apps/{app_id}/backups endpoint.
246+
"""
247+
return cls('ALL_BACKUPS')
248+
249+
@classmethod
250+
def all_app_status(cls) -> Endpoint:
251+
"""
252+
Returns an Endpoint object that represents the
253+
/apps/status endpoint.
254+
"""
255+
return cls('ALL_APP_STATUS')
256+
257+
@classmethod
258+
def current_webhook(cls) -> Endpoint:
259+
"""
260+
Returns an Endpoint object that represents the
261+
/apps/{app_id}/deployments/current endpoint.
262+
"""
263+
return cls('CURRENT_WEBHOOK')
264+
250265

251266
# pylint: disable=too-few-public-methods
252267
class Router:

0 commit comments

Comments
 (0)