|
| 1 | +from collections.abc import Iterable, Mapping |
| 2 | +from typing import Any |
| 3 | + |
| 4 | +from ...models.initiatives import ( |
| 5 | + CreateInitiativeLabel, |
| 6 | + InitiativeLabel, |
| 7 | + PaginatedInitiativeLabelResponse, |
| 8 | + UpdateInitiativeLabel, |
| 9 | +) |
| 10 | +from ..base_resource import BaseResource |
| 11 | + |
| 12 | + |
| 13 | +class InitiativeLabels(BaseResource): |
| 14 | + """API client for managing labels associated with initiatives.""" |
| 15 | + |
| 16 | + def __init__(self, config: Any) -> None: |
| 17 | + super().__init__(config, "/workspaces/") |
| 18 | + |
| 19 | + def create(self, workspace_slug: str, data: CreateInitiativeLabel) -> InitiativeLabel: |
| 20 | + """Create a new initiative label in the workspace. |
| 21 | +
|
| 22 | + Args: |
| 23 | + workspace_slug: The workspace slug identifier |
| 24 | + data: Initiative label data |
| 25 | +
|
| 26 | + Returns: |
| 27 | + The created initiative label |
| 28 | + """ |
| 29 | + response = self._post( |
| 30 | + f"{workspace_slug}/initiatives/labels", |
| 31 | + data.model_dump(exclude_none=True), |
| 32 | + ) |
| 33 | + return InitiativeLabel.model_validate(response) |
| 34 | + |
| 35 | + def retrieve(self, workspace_slug: str, label_id: str) -> InitiativeLabel: |
| 36 | + """Retrieve an initiative label by ID. |
| 37 | +
|
| 38 | + Args: |
| 39 | + workspace_slug: The workspace slug identifier |
| 40 | + label_id: UUID of the initiative label |
| 41 | +
|
| 42 | + Returns: |
| 43 | + The requested initiative label |
| 44 | + """ |
| 45 | + response = self._get(f"{workspace_slug}/initiatives/labels/{label_id}") |
| 46 | + return InitiativeLabel.model_validate(response) |
| 47 | + |
| 48 | + def update( |
| 49 | + self, workspace_slug: str, label_id: str, data: UpdateInitiativeLabel |
| 50 | + ) -> InitiativeLabel: |
| 51 | + """Update an initiative label by ID. |
| 52 | +
|
| 53 | + Args: |
| 54 | + workspace_slug: The workspace slug identifier |
| 55 | + label_id: UUID of the initiative label |
| 56 | + data: Updated initiative label data |
| 57 | +
|
| 58 | + Returns: |
| 59 | + The updated initiative label |
| 60 | + """ |
| 61 | + response = self._patch( |
| 62 | + f"{workspace_slug}/initiatives/labels/{label_id}", |
| 63 | + data.model_dump(exclude_none=True), |
| 64 | + ) |
| 65 | + return InitiativeLabel.model_validate(response) |
| 66 | + |
| 67 | + def delete(self, workspace_slug: str, label_id: str) -> None: |
| 68 | + """Delete an initiative label by ID. |
| 69 | +
|
| 70 | + Args: |
| 71 | + workspace_slug: The workspace slug identifier |
| 72 | + label_id: UUID of the initiative label |
| 73 | + """ |
| 74 | + return self._delete(f"{workspace_slug}/initiatives/labels/{label_id}") |
| 75 | + |
| 76 | + def list( |
| 77 | + self, workspace_slug: str, params: Mapping[str, Any] | None = None |
| 78 | + ) -> PaginatedInitiativeLabelResponse: |
| 79 | + """List initiative labels in the workspace with optional filtering. |
| 80 | +
|
| 81 | + Args: |
| 82 | + workspace_slug: The workspace slug identifier |
| 83 | + params: Optional query parameters (e.g., per_page, cursor) |
| 84 | +
|
| 85 | + Returns: |
| 86 | + Paginated list of initiative labels |
| 87 | + """ |
| 88 | + response = self._get(f"{workspace_slug}/initiatives/labels", params=params) |
| 89 | + return PaginatedInitiativeLabelResponse.model_validate(response) |
| 90 | + |
| 91 | + def list_labels( |
| 92 | + self, workspace_slug: str, initiative_id: str, params: Mapping[str, Any] | None = None |
| 93 | + ) -> PaginatedInitiativeLabelResponse: |
| 94 | + """List labels associated with an initiative. |
| 95 | +
|
| 96 | + Args: |
| 97 | + workspace_slug: The workspace slug identifier |
| 98 | + initiative_id: UUID of the initiative |
| 99 | + params: Optional query parameters (e.g., per_page, cursor) |
| 100 | +
|
| 101 | + Returns: |
| 102 | + Paginated list of initiative labels |
| 103 | + """ |
| 104 | + response = self._get(f"{workspace_slug}/initiatives/{initiative_id}/labels", params=params) |
| 105 | + return PaginatedInitiativeLabelResponse.model_validate(response) |
| 106 | + |
| 107 | + def add_labels( |
| 108 | + self, workspace_slug: str, initiative_id: str, label_ids: Iterable[str] |
| 109 | + ) -> Iterable[InitiativeLabel]: |
| 110 | + """Add labels to an initiative. |
| 111 | +
|
| 112 | + Args: |
| 113 | + workspace_slug: The workspace slug identifier |
| 114 | + initiative_id: UUID of the initiative |
| 115 | + label_ids: List of label UUIDs to add |
| 116 | +
|
| 117 | + Returns: |
| 118 | + List of added initiative labels |
| 119 | + """ |
| 120 | + response = self._post( |
| 121 | + f"{workspace_slug}/initiatives/{initiative_id}/labels", |
| 122 | + {"label_ids": label_ids}, |
| 123 | + ) |
| 124 | + return [InitiativeLabel.model_validate(label) for label in response] |
| 125 | + |
| 126 | + def remove_labels( |
| 127 | + self, workspace_slug: str, initiative_id: str, label_ids: Iterable[str] |
| 128 | + ) -> None: |
| 129 | + """Remove labels from an initiative. |
| 130 | +
|
| 131 | + Args: |
| 132 | + workspace_slug: The workspace slug identifier |
| 133 | + initiative_id: UUID of the initiative |
| 134 | + label_ids: List of label UUIDs to remove |
| 135 | + """ |
| 136 | + return self._delete( |
| 137 | + f"{workspace_slug}/initiatives/{initiative_id}/labels", |
| 138 | + {"label_ids": label_ids}, |
| 139 | + ) |
0 commit comments