-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from pieces-app/feat-3.1.0
Feat 3.1.0
- Loading branch information
Showing
20 changed files
with
720 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "pieces_os_client" | ||
version = "3.0.1" | ||
version = "3.1.0" | ||
description = "A powerful code engine package for writing applications on top of Pieces OS" | ||
authors = ["Pieces <[email protected]>"] | ||
license = "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .asset import BasicAsset | ||
from .chat import BasicChat | ||
from .message import BasicMessage | ||
from .user import BasicUser | ||
|
||
__all__ = ["BasicAsset","BasicChat","BasicMessage"] | ||
__all__ = ["BasicAsset","BasicChat","BasicMessage","BasicUser"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import threading | ||
from pieces_os_client import UserProfile,AllocationStatusEnum | ||
from typing import Optional | ||
|
||
## TODO: Modify the Basic class to be able to fit in the BasicUser | ||
class BasicUser: | ||
""" | ||
A class to represent a basic user and manage their connection to the cloud. | ||
Attributes: | ||
user_profile: The profile of the user. | ||
pieces_client: The client used to interact with the pieces OS API. | ||
""" | ||
|
||
user_profile: Optional[UserProfile] = None | ||
|
||
def __init__(self, pieces_client) -> None: | ||
""" | ||
Initializes the BasicUser with a pieces client. | ||
Args: | ||
pieces_client: The client used to interact with the pieces OS API. | ||
""" | ||
self.pieces_client = pieces_client | ||
|
||
def on_user_callback(self, user: Optional[UserProfile], connecting=False): | ||
""" | ||
Callback function to set the user profile. | ||
Args: | ||
user: The profile of the user. | ||
connecting: A flag indicating if the user is connecting to the cloud (default is False). | ||
""" | ||
self.user_profile = user | ||
|
||
def _on_login_connect(self, thread, timeout): | ||
""" | ||
Waits for the user to login and then connects to the cloud. | ||
Args: | ||
thread: The thread handling the login process. | ||
timeout: The maximum time to wait for the login process. | ||
""" | ||
thread.get(timeout) # Wait for the user to login | ||
self.connect() | ||
|
||
def login(self, connect_after_login=True, timeout=120): | ||
""" | ||
Logs the user into the OS and optionally connects to the cloud. | ||
Args: | ||
connect_after_login: A flag indicating if the user should connect to the cloud after login (default is True). | ||
timeout: The maximum time to wait for the login process (default is 120 seconds). | ||
""" | ||
thread = self.pieces_client.os_api.sign_into_os(async_req=True) | ||
if connect_after_login: | ||
threading.Thread(target=lambda: self._on_login_connect(thread, timeout)) | ||
|
||
def logout(self): | ||
""" | ||
Logs the user out of the OS. | ||
""" | ||
self.pieces_client.api_client.os_api.sign_out_of_os() | ||
|
||
def connect(self): | ||
""" | ||
Connects the user to the cloud. | ||
Raises: | ||
PermissionError: If the user is not logged in. | ||
""" | ||
if not self.user_profile: | ||
raise PermissionError("You must be logged in to use this feature") | ||
self.on_user_callback(self.user_profile, True) # Set the connecting to cloud bool to true | ||
self.pieces_client.allocations_api.allocations_connect_new_cloud(self.user_profile) | ||
|
||
def disconnect(self): | ||
""" | ||
Disconnects the user from the cloud. | ||
Raises: | ||
PermissionError: If the user is not logged in. | ||
""" | ||
if not self.user_profile: | ||
raise PermissionError("You must be logged in to use this feature") | ||
if self.user_profile.allocation: # Check if there is an allocation iterable | ||
self.pieces_client.api_client.allocations_api.allocations_disconnect_cloud(self.user_profile.allocation) | ||
|
||
@property | ||
def picture(self) -> Optional[str]: | ||
""" | ||
Returns the user's profile picture URL. | ||
Returns: | ||
The URL of the user's profile picture, or None if not available. | ||
""" | ||
if self.user_profile: | ||
return self.user_profile.picture | ||
|
||
|
||
@property | ||
def name(self) -> Optional[str]: | ||
""" | ||
Returns the name of the user. | ||
Returns: | ||
Optional[str]: The name of the user if the user logged in, otherwise None. | ||
""" | ||
if self.user_profile: | ||
return self.user_profile.name | ||
|
||
@property | ||
def email(self) -> Optional[str]: | ||
""" | ||
Returns the email of the user. | ||
Returns: | ||
Optional[str]: The email of the user if the user logged in, otherwise None. | ||
""" | ||
if self.user_profile: | ||
return self.user_profile.email | ||
|
||
@property | ||
def vanity_name(self) -> Optional[str]: # TODO: implements the setter object | ||
""" | ||
Returns the vanity name of the user which is the base name of the cloud url. | ||
For example, if the cloud URL is 'bishoyatpieces.pieces.cloud', this method returns 'bishoyatpieces'. | ||
Returns: | ||
Optional[str]: The vanity name of the user if the user user logged in and connected to the cloud, otherwise None. | ||
""" | ||
if self.user_profile: | ||
return self.user_profile.vanityname | ||
|
||
@property | ||
def cloud_status(self) -> Optional[AllocationStatusEnum]: | ||
""" | ||
Returns the cloud status of the user's cloud. | ||
Returns: | ||
Optional[AllocationStatusEnum]: The cloud status of the user's cloud. | ||
""" | ||
if self.user_profile and self.user_profile.allocation: | ||
return self.user_profile.allocation.status.cloud |
Oops, something went wrong.