|
1 | 1 | import json |
2 | | -from typing import TYPE_CHECKING, Union, List, Tuple, Optional, IO, Dict, Any |
| 2 | +from typing import TYPE_CHECKING, Optional, Union, List, Tuple |
3 | 3 | from pydantic import EmailStr |
4 | 4 | from uuid import UUID |
5 | 5 | from datetime import datetime |
@@ -160,98 +160,6 @@ def create_api_key( |
160 | 160 | client=self.client, **response |
161 | 161 | ), response["key"] |
162 | 162 |
|
163 | | - @staticmethod |
164 | | - def _normalize_file_attachment(payload: dict) -> Dict[str, Any]: |
165 | | - return { |
166 | | - "id": payload.get("id"), |
167 | | - "type": payload.get("type"), |
168 | | - "name": payload.get("name"), |
169 | | - "description": payload.get("description", ""), |
170 | | - "content_type": payload.get("contentType") |
171 | | - or payload.get("content_type") |
172 | | - or "", |
173 | | - "size_bytes": payload.get("sizeBytes") or payload.get("size_bytes") or 0, |
174 | | - "link": payload.get("link"), |
175 | | - "created_at": payload.get("createdAt") or payload.get("created_at"), |
176 | | - "updated_at": payload.get("updatedAt") or payload.get("updated_at"), |
177 | | - } |
178 | | - |
179 | | - def list_file_attachments( |
180 | | - self, uid: Union[UUID, str], attachment_type: Optional[str] = None |
181 | | - ) -> List[Dict[str, Any]]: |
182 | | - """List file attachments associated with a workspace.""" |
183 | | - |
184 | | - path = f"/{self.client.base_route}/{self.model.get_route()}/{str(uid)}/file-attachments" |
185 | | - params = {"type": attachment_type} if attachment_type else None |
186 | | - response = self.client.request("get", path, params=params).json() |
187 | | - if not isinstance(response, list): |
188 | | - return [] |
189 | | - return [ |
190 | | - self._normalize_file_attachment(item) |
191 | | - for item in response |
192 | | - if isinstance(item, dict) |
193 | | - ] |
194 | | - |
195 | | - def add_file_attachment( |
196 | | - self, |
197 | | - uid: Union[UUID, str], |
198 | | - file: IO[bytes], |
199 | | - attachment_type: str, |
200 | | - name: Optional[str] = None, |
201 | | - description: Optional[str] = None, |
202 | | - ) -> Dict[str, Any]: |
203 | | - """Add a file attachment to a workspace.""" |
204 | | - |
205 | | - path = f"/{self.client.base_route}/{self.model.get_route()}/{str(uid)}/file-attachments" |
206 | | - data = {"type": attachment_type} |
207 | | - if name is not None: |
208 | | - data["name"] = name |
209 | | - if description is not None: |
210 | | - data["description"] = description |
211 | | - |
212 | | - response = self.client.request("post", path, data=data, files={"file": file}).json() |
213 | | - return self._normalize_file_attachment(response) |
214 | | - |
215 | | - def update_file_attachment( |
216 | | - self, |
217 | | - uid: Union[UUID, str], |
218 | | - file_attachment_id: Union[UUID, str], |
219 | | - attachment_type: str = ..., |
220 | | - name: str = ..., |
221 | | - description: Optional[str] = ..., |
222 | | - ) -> Dict[str, Any]: |
223 | | - """Update workspace file attachment metadata.""" |
224 | | - |
225 | | - path = ( |
226 | | - f"/{self.client.base_route}/{self.model.get_route()}/" |
227 | | - f"{str(uid)}/file-attachments/{str(file_attachment_id)}" |
228 | | - ) |
229 | | - body = { |
230 | | - "type": attachment_type, |
231 | | - "name": name, |
232 | | - "description": description, |
233 | | - } |
234 | | - body = {k: v for k, v in body.items() if v is not ...} |
235 | | - headers = {"Content-type": "application/json"} |
236 | | - response = self.client.request( |
237 | | - "patch", |
238 | | - path, |
239 | | - headers=headers, |
240 | | - data=json.dumps(body, default=self.default_serializer), |
241 | | - ).json() |
242 | | - return self._normalize_file_attachment(response) |
243 | | - |
244 | | - def delete_file_attachment( |
245 | | - self, uid: Union[UUID, str], file_attachment_id: Union[UUID, str] |
246 | | - ) -> None: |
247 | | - """Delete a file attachment from a workspace.""" |
248 | | - |
249 | | - path = ( |
250 | | - f"/{self.client.base_route}/{self.model.get_route()}/" |
251 | | - f"{str(uid)}/file-attachments/{str(file_attachment_id)}" |
252 | | - ) |
253 | | - self.client.request("delete", path) |
254 | | - |
255 | 163 | def update_api_key( |
256 | 164 | self, |
257 | 165 | uid: Union[UUID, str], |
|
0 commit comments