-
Notifications
You must be signed in to change notification settings - Fork 1
2. Space
The Space
class is used to interact with and manage objects, types, and other elements within a specific Space
. It provides methods to retrieve objects, types, and perform search operations within the space. Additionally, it allows creating new objects associated with specific types.
-
name
: The name of the space. -
id
: The ID of the space.
Retrieves a specific object by its ID.
def get_object(self, objectId: str, offset=0, limit=100) -> Object:
-
Parameters:
-
objectId
(str): The ID of the object to retrieve. -
offset
(int, optional): The offset for pagination (default: 0). -
limit
(int, optional): The limit for the number of results (default: 100).
-
-
Returns:
- An
Object
instance representing the retrieved object.
- An
-
Raises:
- Raises an error if the request to the API fails.
Retrieves a list of objects associated with the space.
def get_objects(self, offset=0, limit=100) -> list[Object]:
-
Parameters:
-
offset
(int, optional): The offset for pagination (default: 0). -
limit
(int, optional): The limit for the number of results (default: 100).
-
-
Returns:
- A list of
Object
instances.
- A list of
-
Raises:
- Raises an error if the request to the API fails.
Retrieves a list of members associated with the space.
def get_members(self, offset=0, limit=100) -> list[Member]:
-
Parameters:
-
offset
(int, optional): The offset for pagination (default: 0). -
limit
(int, optional): The limit for the number of results (default: 100).
-
-
Returns:
- A list of
Member
instances.
- A list of
-
Raises:
- Raises an error if the request to the API fails.
Retrieves a list of types associated with the space.
def get_types(self, offset=0, limit=100) -> list[Type]:
-
Parameters:
-
offset
(int, optional): The offset for pagination (default: 0). -
limit
(int, optional): The limit for the number of results (default: 100).
-
-
Returns:
- A list of
Type
instances.
- A list of
-
Raises:
- Raises an error if the request to the API fails.
Retrieves a specific type by its name.
def get_type(self, type_name: str) -> Type:
-
Parameters:
-
type_name
(str): The name of the type to retrieve.
-
-
Returns:
- A
Type
instance representing the type.
- A
-
Raises:
-
ValueError
: If the type with the specified name is not found.
-
Performs a search for objects in the space using a query string.
def search(self, query, offset=0, limit=10) -> list[Object]:
-
Parameters:
-
query
(str): The search query string. -
offset
(int, optional): The offset for pagination (default: 0). -
limit
(int, optional): The limit for the number of results (default: 10).
-
-
Returns:
- A list of
Object
instances that match the search query.
- A list of
-
Raises:
-
ValueError
: If the space ID is not set.
-
Creates a new object within the space, associated with a specified type.
def create_object(self, obj: Object, type: Type) -> Object:
-
Parameters:
-
obj
(Object): TheObject
instance to create. -
type
(Type): TheType
instance to associate the object with.
-
-
Returns:
- A new
Object
instance representing the created object.
- A new
-
Raises:
- Raises an error if the request to the API fails.
# Create a new Space instance
space = Space()
# Retrieve all objects in the space
objects = space.get_objects()
# Retrieve a specific object by ID
obj = space.get_object("object_id")
# Search for objects in the space
search_results = space.search("query")
# Retrieve all types in the space
types = space.get_types()
# Create a new object within the space
new_obj = Object()
new_obj.name = "New Object"
new_obj.icon = "📄"
type_instance = space.get_type("Page")
created_obj = space.create_object(new_obj, type_instance)
# Print the string representation of the space
print(space) # Output: <Space(name={self.name})>