Skip to content

Commit 0e08aab

Browse files
Docstrings for classes and methods. by Piotr and Filip
1 parent 696aa57 commit 0e08aab

File tree

6 files changed

+86
-69
lines changed

6 files changed

+86
-69
lines changed

docs/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Programming Interface
1111
schedule
1212
students
1313
webapp
14+
website

pythonanywhere_core/files.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,34 @@
99

1010

1111
class Files:
12-
""" Interface for PythonAnywhere files API.
13-
14-
Uses `pythonanywhere_core.base` :method: `get_api_endpoint` to
15-
create url, which is stored in a class variable `Files.base_url`,
16-
then calls `call_api` with appropriate arguments to execute files
17-
action.
18-
19-
Covers:
20-
- GET, POST and DELETE for files path endpoint
21-
- POST, GET and DELETE for files sharing endpoint
22-
- GET for tree endpoint
23-
24-
"path" methods:
25-
- use :method: `Files.path_get` to get contents of file or
26-
directory from `path`
27-
- use :method: `Files.path_post` to upload or update file at given
28-
`dest_path` using contents from `source`
29-
- use :method: `Files.path_delete` to delete file/directory on on
30-
given `path`
31-
32-
"sharing" methods:
33-
- use :method: `Files.sharing_post` to enable sharing a file from
34-
`path` (if not shared before) and get a link to it
35-
- use :method: `Files.sharing_get` to get sharing url for `path`
36-
- use :method: `Files.sharing_delete` to disable sharing for
37-
`path`
38-
39-
"tree" method:
40-
- use :method: `Files.tree_get` to get list of regular files and
41-
subdirectories of a directory at `path` (limited to 1000 results)
4212
"""
13+
Interface for the PythonAnywhere Files API.
14+
15+
This class uses the `get_api_endpoint` function from ``pythonanywhere_core.base``
16+
to construct the API URL, which is stored in the class variable ``base_url``.
17+
It then calls the ``call_api`` method with the appropriate arguments to
18+
perform file-related actions.
19+
20+
Supported Endpoints:
21+
- `GET`, `POST`, and `DELETE` for the files path endpoint.
22+
- `POST`, `GET`, and `DELETE` for the file sharing endpoint.
23+
- `GET` for the tree endpoint.
24+
25+
Path Methods:
26+
- :meth:`Files.path_get`: Retrieve the contents of a file or directory from a specified `path`.
27+
- :meth:`Files.path_post`: Upload or update a file at the given `dest_path` using contents from `source`.
28+
- :meth:`Files.path_delete`: Delete a file or directory at the specified `path`.
29+
30+
Sharing Methods:
31+
- :meth:`Files.sharing_post`: Enable sharing of a file from the given `path` (if not already shared) and get a link to it.
32+
- :meth:`Files.sharing_get`: Retrieve the sharing URL for a specified `path`.
33+
- :meth:`Files.sharing_delete`: Disable sharing for a specified `path`.
34+
35+
Tree Method:
36+
- :meth:`Files.tree_get`: Retrieve a list of regular files and subdirectories of a directory at the specified `path`
37+
(limited to 1000 results).
38+
"""
39+
4340

4441
base_url = get_api_endpoint(username=getpass.getuser(), flavor="files")
4542
path_endpoint = urljoin(base_url, "path")

pythonanywhere_core/schedule.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@
88

99

1010
class Schedule:
11-
"""Interface for PythonAnywhere scheduled tasks API.
12-
13-
Uses `pythonanywhere_core.api` :method: `get_api_endpoint` to create url,
14-
which is stored in a class variable `Schedule.base_url`, then calls
15-
`call_api` with appropriate arguments to execute scheduled tasks tasks
16-
actions. Covers 'GET' and 'POST' methods for tasks list, as well as
17-
'GET', 'PATCH' and 'DELETE' methods for task with id.
18-
19-
Use :method: `Schedule.get_list` to get all tasks list.
20-
Use :method: `Schedule.create` to create new task.
21-
Use :method: `Schedule.get_specs` to get existing task specs.
22-
Use :method: `Schedule.delete` to delete existing task.
23-
Use :method: `Schedule.update` to update existing task."""
11+
"""
12+
Interface for the PythonAnywhere Scheduled Tasks API.
13+
14+
This class uses the `get_api_endpoint` function from ``pythonanywhere_core.api``
15+
to construct the API URL, which is stored in the class variable ``base_url``.
16+
It then calls the ``call_api`` method with appropriate arguments to perform
17+
actions related to scheduled tasks.
18+
19+
Supported HTTP Methods:
20+
- `GET` and `POST` for the tasks list.
21+
- `GET`, `PATCH`, and `DELETE` for tasks with an ID.
22+
23+
Methods:
24+
- :meth:`Schedule.get_list`: Retrieve the list of all scheduled tasks.
25+
- :meth:`Schedule.create`: Create a new scheduled task.
26+
- :meth:`Schedule.get_specs`: Retrieve the specifications of an existing task.
27+
- :meth:`Schedule.delete`: Delete an existing task.
28+
- :meth:`Schedule.update`: Update an existing task.
29+
"""
2430

2531
base_url: str = get_api_endpoint(username=getpass.getuser(), flavor="schedule")
2632

pythonanywhere_core/students.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,30 @@
55

66

77
class StudentsAPI:
8-
"""Interface for PythonAnywhere students API.
8+
"""
9+
Interface for the PythonAnywhere Students API.
910
10-
Uses `pythonanywhere.api.base` :method: `get_api_endpoint` to
11-
create url, which is stored in a class variable `StudentsAPI.base_url`,
12-
then calls `call_api` with appropriate arguments to execute student
13-
action.
11+
This class uses the `get_api_endpoint` function from
12+
``pythonanywhere.api.base`` to construct the API URL, which is stored
13+
in the class variable ``base_url``. It then calls the ``call_api`` method
14+
with the appropriate arguments to perform student-related actions.
1415
15-
Covers:
16-
- GET
17-
- DELETE
16+
Supported HTTP Methods:
17+
- `GET`
18+
- `DELETE`
1819
1920
Methods:
20-
- use :method: `StudentsAPI.get` to get list of students
21-
- use :method: `StudentsAPI.delete` to remove a student
21+
- :meth:`StudentsAPI.get`: Retrieve a list of students.
22+
- :meth:`StudentsAPI.delete`: Remove a student.
2223
"""
2324

2425
base_url: str = get_api_endpoint(username=getpass.getuser(), flavor="students")
2526

2627
def get(self) -> Optional[dict]:
27-
"""Returns list of PythonAnywhere students related with user's account."""
28+
"""Returns list of PythonAnywhere students related with user's account.
29+
30+
:returns: dictionary with students info
31+
"""
2832

2933
result = call_api(self.base_url, "GET")
3034

@@ -34,7 +38,11 @@ def get(self) -> Optional[dict]:
3438
raise Exception(f"GET to list students failed, got {result.text}")
3539

3640
def delete(self, student_username: str) -> Optional[int]:
37-
"""Returns 204 if student has been successfully removed, raises otherwise."""
41+
"""Returns 204 if student has been successfully removed, raises otherwise.
42+
43+
:param student_username: student username to be removed
44+
:returns: 204 if student has been successfully removed
45+
"""
3846

3947
url = f"{self.base_url}{student_username}"
4048

pythonanywhere_core/webapp.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ class Webapp:
1919
then calls `call_api` with appropriate arguments to execute webapps
2020
action.
2121
22-
Use :method: `Webapp.create` to create new webapp.
23-
Use :method: `Webapp.reload` to reload webapp.
24-
Use :method: `Webapp.set_ssl` to set SSL certificate and private key.
25-
Use :method: `Webapp.get_ssl_info` to get SSL certificate info.
26-
Use :method: `Webapp.delete_log` to delete log file.
27-
Use :method: `Webapp.get_log_info` to get log files info.
28-
22+
Methods:
23+
- :meth:`Webapp.create`: Create a new webapp.
24+
- :meth:`Webapp.reload`: Reload the webapp.
25+
- :meth:`Webapp.set_ssl`: Set the SSL certificate and private key.
26+
- :meth:`Webapp.get_ssl_info`: Retrieve SSL certificate information.
27+
- :meth:`Webapp.delete_log`: Delete a log file.
28+
- :meth:`Webapp.get_log_info`: Retrieve log file information.
2929
"""
3030
def __init__(self, domain: str) -> None:
3131
self.username = getpass.getuser()

pythonanywhere_core/website.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
class Website:
99
""" Interface for PythonAnywhere websites API.
1010
11-
Uses ``pythonanywhere_core.base`` :method: ``get_api_endpoint`` to
11+
Uses ``pythonanywhere_core.base`` function ``get_api_endpoint`` to
1212
create url, which is stored in a class variable ``Website.api_endpoint``,
1313
then calls ``call_api`` with appropriate arguments to execute websites
1414
action.
1515
16-
Use :method: ``Website.create`` to create new website.
17-
Use :method: ``Website.get`` to get website info.
18-
Use :method: ``Website.list`` to get all websites list.
19-
Use :method: ``Website.reload`` to reload website.
20-
Use :method: ``Website.delete`` to delete website.
16+
Methods:
17+
- :meth:`Website.create`: Create a new website.
18+
- :meth:`Website.get`: Retrieve information about a specific website.
19+
- :meth:`Website.list`: Get a list of all websites.
20+
- :meth:`Website.reload`: Reload the website.
21+
- :meth:`Website.auto_ssl`: Create and apply a Let's Encrypt SSL certificate.
22+
- :meth:`Website.get_ssl_info`: Get SSL certificate information.
23+
- :meth:`Website.delete`: Delete a website.
2124
"""
2225

2326
def __init__(self) -> None:
@@ -86,7 +89,9 @@ def auto_ssl(self, domain_name: str) -> dict:
8689
return response.json()
8790

8891
def get_ssl_info(self, domain_name) -> dict:
89-
"""Get SSL certificate info"""
92+
"""Get SSL certificate info
93+
:param domain_name: domain name for website to get SSL info
94+
:return: dictionary with SSL certificate info"""
9095
url = f"{self.domains_base_url}{domain_name}/ssl/"
9196
response = call_api(url, "get")
9297
if not response.ok:

0 commit comments

Comments
 (0)