Skip to content

Commit 07da53f

Browse files
docs: Adding docstring to some functions
1 parent 56b2dae commit 07da53f

File tree

3 files changed

+214
-2
lines changed

3 files changed

+214
-2
lines changed

squarecloud/app.py

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,28 @@ async def github_integration(self, access_token: str) -> str:
655655
return webhook
656656

657657
async def domain_analytics(self) -> DomainAnalytics:
658+
"""
659+
Retrieve analytics data for the application's domain.
660+
661+
:param self: Refer to the instance of the class.
662+
:returns: An instance of :class:`DomainAnalytics` containing analytics data for the domain.
663+
:rtype: DomainAnalytics
664+
:raises Exception: If the analytics data could not be retrieved.
665+
"""
658666
analytics: DomainAnalytics = await self.client.domain_analytics(
659667
self.id, avoid_listener=True
660668
)
661-
return analytics # TODO:
669+
return analytics
662670

663671
async def set_custom_domain(self, custom_domain: str) -> Response:
672+
"""
673+
Sets a custom domain for the application.
674+
675+
:param custom_domain: The custom domain to be assigned to the application.
676+
:type custom_domain: str
677+
:return: The response from the domain assignment operation.
678+
:rtype: Response
679+
"""
664680
response: Response = await self.client.set_custom_domain(
665681
self.id, custom_domain, avoid_listener=True
666682
)
@@ -672,28 +688,82 @@ async def all_backups(self) -> list[SnapshotInfo]:
672688
return backups
673689

674690
async def all_snapshots(self) -> list[SnapshotInfo]:
691+
"""
692+
Retrieve all snapshots of the application.
693+
694+
:return: A list of SnapshotInfo objects representing all snapshots of the application.
695+
:rtype: list[SnapshotInfo]
696+
"""
675697
snapshots: list[SnapshotInfo] = await self.client.all_app_snapshots(self.id)
676698
return snapshots
677699

678700
@validate
679701
async def move_file(self, origin: str, dest: str) -> Response:
702+
"""
703+
Moves a file from the origin path to the destination path within the application.
704+
705+
:param origin: The source path of the file to be moved.
706+
:type origin: str
707+
:param dest: The destination path where the file should be moved.
708+
:type dest: str
709+
:return: A Response object containing the result of the file move operation.
710+
:rtype: Response
711+
"""
712+
680713
return await self.client.move_app_file(self.id, origin, dest)
681714

682715
async def current_integration(self) -> Response:
683716
return await self.client.current_app_integration(self.id)
684717

685718
@_notify_listener(Endpoint.dns_records())
686719
async def dns_records(self) -> list[DNSRecord]:
720+
"""
721+
Retrieve the DNS records associated with the application.
722+
723+
:returns: A list of DNSRecord objects representing the DNS records.
724+
:rtype: list[DNSRecord]
725+
"""
726+
687727
return await self.client.dns_records(self.id)
688728

689729
async def get_envs(self) -> dict[str, str]:
730+
"""
731+
Get environment variables of the application.
732+
733+
:return: A dictionary of the environment variables that were set.
734+
:rtype: dict[str, str]
735+
"""
690736
return await self.client.get_app_envs(self.id)
691737

692738
async def set_envs(self, envs: dict[str, str]) -> dict[str,str]:
739+
"""
740+
Set environment variables or edits for the application.
741+
742+
:param envs: A dictionary containing environment variable names and their corresponding values.
743+
:type envs: dict[str, str]
744+
:return: A dictionary of the environment variables that were set.
745+
:rtype: dict[str, str]
746+
"""
693747
return await self.client.set_app_envs(self.id, envs)
694748

695749
async def delete_envs(self, keys: list[str]) -> dict[str,str]:
750+
"""
751+
Deletes environment variables from the application.
752+
753+
:param keys: A list of environment variable keys to be deleted.
754+
:type keys: list[str]
755+
:returns: A dictionary containing the remaining variables.
756+
:rtype: dict[str, str]
757+
"""
696758
return await self.client.delete_app_envs(self.id, keys)
697759

698760
async def overwrite_env(self, envs: dict[str, str]) -> dict[str,str]:
761+
"""
762+
Overwrites the environment variables for the application.
763+
764+
:param envs: A dictionary containing the environment variables to set, where keys are variable names and values are their corresponding values.
765+
:type envs: dict[str, str]
766+
:return: A dictionary of the environment variables.
767+
:rtype: dict[str, str]
768+
"""
699769
return await self.client.overwrite_app_envs(self.id, envs)

squarecloud/client.py

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,36 @@ async def all_app_backups(
714714
async def all_app_snapshots(
715715
self, app_id: str, **_kwargs
716716
) -> list[SnapshotInfo]:
717+
"""
718+
Retrieve all snapshots for a specific application.
719+
This method fetches a list of snapshots associated with the
720+
given application ID and returns them as a list of `SnapshotInfo` objects.
721+
:param app_id: Specify the application by id.
722+
:type app_id: str
723+
:param _kwargs: Additional keyword arguments.
724+
:type _kwargs: dict
725+
:return: A list of `SnapshotInfo` objects representing the snapshots of
726+
the specified application.
727+
:rtype: list[SnapshotInfo]
728+
"""
717729
response: Response = await self._http.get_all_app_snapshots(
718730
app_id=app_id
719731
)
720-
return [SnapshotInfo(**backup_data) for backup_data in response.response]
732+
return [SnapshotInfo(**snapshot_data) for snapshot_data in response.response]
721733

722734
@_notify_listener(Endpoint.all_apps_status())
723735
async def all_apps_status(self, **_kwargs) -> list[ResumedStatus]:
736+
"""
737+
Retrieve the status of all applications.
738+
This method fetches the status of all applications
739+
and returns a list of `ResumedStatus` objects for applications
740+
that are currently running.
741+
:param _kwargs: Additional keyword arguments.
742+
:type _kwargs: dict
743+
:return: A list of `ResumedStatus` objects representing the status
744+
of running applications.
745+
:rtype: list[ResumedStatus]
746+
"""
724747
response: Response = await self._http.all_apps_status()
725748
all_status = []
726749
for status in response.response:
@@ -733,6 +756,19 @@ async def all_apps_status(self, **_kwargs) -> list[ResumedStatus]:
733756
async def move_app_file(
734757
self, app_id: str, origin: str, dest: str, **_kwargs
735758
) -> Response:
759+
"""
760+
Moves a file within an application from the origin path to the destination path.
761+
:param app_id: Specify the application by id.
762+
:type app_id: str
763+
:param origin: The current path of the file to be moved.
764+
:type origin: str
765+
:param dest: The target path where the file should be moved.
766+
:type dest: str
767+
:param _kwargs: Additional keyword arguments.
768+
:type _kwargs: dict
769+
:return: The response object containing the result of the move operation.
770+
:rtype: Response
771+
"""
736772
response: Response = await self._http.move_app_file(
737773
app_id=app_id, origin=origin, dest=dest
738774
)
@@ -741,6 +777,14 @@ async def move_app_file(
741777
@validate
742778
@_notify_listener(Endpoint.dns_records())
743779
async def dns_records(self, app_id: str) -> list[DNSRecord]:
780+
"""
781+
Retrieve DNS records for a specific application.
782+
:param app_id: Specify the application by id.
783+
:type app_id: str
784+
:return: A list of DNSRecord objects representing the DNS records of the application.
785+
:rtype: list[DNSRecord]
786+
"""
787+
744788
response: Response = await self._http.dns_records(app_id)
745789
return [DNSRecord(**data) for data in response.response]
746790

@@ -753,21 +797,74 @@ async def current_app_integration(self, app_id: str) -> str | None:
753797
return response.response["webhook"]
754798

755799
async def get_app_envs(self, app_id: str) -> dict[str, str]:
800+
"""
801+
Retrieve the environment variables of a specific application.
802+
:param app_id: Specify the application by id.
803+
:type app_id: str
804+
:return: A dictionary containing the environment variables as key-value pairs.
805+
:rtype: dict[str, str]
806+
"""
756807
response: Response = await self._http.get_environment_variables(app_id)
757808
return response.response
758809

759810
async def set_app_envs(self, app_id: str, envs: dict[str, str]) -> dict[str, str]:
811+
"""
812+
Sets or edits environment variables for a specific application.
813+
This method sends a request to update the environment variables of the
814+
specified application with the provided key-value pairs.
815+
:param app_id: Specify the application by id.
816+
:type app_id: str
817+
:param envs: A dictionary containing the environment variables to set,
818+
where the keys are variable names and the values are their
819+
corresponding values.
820+
:type envs: dict[str, str]
821+
:return: A dictionary containing the updated environment with all variables.
822+
:rtype: dict[str, str]
823+
:raises HTTPException: If the HTTP request fails or returns an error response.
824+
"""
825+
760826
response: Response = await self._http.set_environment_variable(app_id, envs)
761827
return response.response
762828

763829
async def delete_app_envs(self, app_id: str, keys: list[str]) -> dict[str, str]:
830+
"""
831+
Deletes specified environment variables for a given application.
832+
:param app_id: Specify the application by id.
833+
:type app_id: str
834+
:param keys: A list of keys representing the environment variables to be deleted.
835+
:type keys: list[str]
836+
:return: A dictionary containing the remaining variables.
837+
:rtype: dict[str, str]
838+
"""
764839
response: Response = await self._http.delete_environment_variable(app_id, keys)
765840
return response.response
766841

767842
async def overwrite_app_envs(self, app_id: str, envs: dict[str, str]) -> dict[str, str]:
843+
"""
844+
Overwrite the environment variables of a specific application.
845+
This method sets the dictionary provided as the new environment for the application.
846+
:param app_id: Specify the application by id.
847+
:type app_id: str
848+
:param envs: A dictionary containing the new environment variables to set
849+
for the application. Keys and values must both be strings.
850+
:type envs: dict[str, str]
851+
:return: A dictionary containing the new environment after overwriting the
852+
environment variables.
853+
:rtype: dict[str, str]
854+
"""
768855
response: Response = await self._http.overwrite_environment_variables(app_id, envs)
769856
return response.response
770857

771858
async def clear_app_envs(self, app_id: str) -> dict[str, str]:
859+
"""
860+
Clears all environment variables for the specified application.
861+
This method overwrites the application's environment variables with an empty dictionary,
862+
effectively removing all existing environment variables.
863+
864+
:param app_id: Specify the application by id.
865+
:type app_id: str
866+
:return: A dictionary containing the response from the server.
867+
:rtype: dict[str, str]
868+
"""
772869
response: Response = await self._http.overwrite_environment_variables(app_id, {})
773870
return response.response

squarecloud/http/http_client.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,21 +759,66 @@ def last_response(self) -> Response | None:
759759
return self._last_response
760760

761761
async def get_environment_variables(self, app_id: str) -> Response:
762+
"""
763+
Retrieve the environment variables for a specific application.
764+
765+
:param app_id: The unique identifier of the application.
766+
:type app_id: str
767+
:return: The response containing the environment variables.
768+
:rtype: Response
769+
"""
762770
route: Router = Router(Endpoint.envs_get(), app_id=app_id)
763771
response: Response = await self.request(route)
764772
return response
765773

766774
async def set_environment_variable(self, app_id: str, keys: dict[str, str]) -> Response:
775+
"""
776+
Sets environment variables for a specific application.
777+
This method sends a request to set the specified environment variables
778+
for the application identified by the given `app_id`.
779+
:param app_id: The ID of the application for which the environment
780+
variables will be set.
781+
:type app_id: str
782+
:param keys: A dictionary containing the environment variable names
783+
as keys and their corresponding values.
784+
:type keys: dict[str, str]
785+
:return: The response object containing the result of the operation.
786+
:rtype: Response
787+
"""
788+
767789
route: Router = Router(Endpoint.envs_post(), app_id=app_id)
768790
response: Response = await self.request(route, json={"envs": keys})
769791
return response
770792

771793
async def delete_environment_variable(self, app_id: str, keys: list[str]) -> Response:
794+
"""
795+
Deletes one or more environment variables for a specific application.
796+
:param app_id: The ID of the application whose environment variables are to be deleted.
797+
:type app_id: str
798+
:param keys: A list of environment variable keys to be deleted.
799+
:type keys: list[str]
800+
:return: The response object containing the result of the deletion operation.
801+
:rtype: Response
802+
"""
772803
route: Router = Router(Endpoint.envs_delete(), app_id=app_id)
773804
response: Response = await self.request(route, json={"envs": keys})
774805
return response
775806

776807
async def overwrite_environment_variables(self, app_id: str, keys: dict[str, str]) -> Response:
808+
"""
809+
Overwrites the environment variables for a specific application.
810+
This method sends a request to update the environment variables of the
811+
specified application with the provided key-value pairs.
812+
:param app_id: The ID of the application whose environment variables
813+
are to be overwritten.
814+
:type app_id: str
815+
:param keys: A dictionary containing the environment variable keys and
816+
their corresponding values to be set.
817+
:type keys: dict[str, str]
818+
:return: The response object containing the result of the operation.
819+
:rtype: Response
820+
"""
821+
777822
route: Router = Router(Endpoint.envs_put(), app_id=app_id)
778823
response: Response = await self.request(route, json={"envs": keys})
779824
return response

0 commit comments

Comments
 (0)