|
13 | 13 | UpdateMetadata, |
14 | 14 | UpdateMetadataResponse, |
15 | 15 | ) |
16 | | -from pythonik.models.metadata.fields import FieldCreate, FieldUpdate, FieldResponse |
| 16 | +from pythonik.models.metadata.fields import ( |
| 17 | + FieldCreate, |
| 18 | + FieldUpdate, |
| 19 | + FieldResponse, |
| 20 | + FieldListResponse, |
| 21 | +) |
17 | 22 | from pythonik.specs.base import Spec |
18 | | -from typing import Literal, Union, Dict, Any, List |
| 23 | +from typing import Literal, Union, Dict, Any, List, Optional |
19 | 24 |
|
20 | 25 |
|
21 | 26 | # Asset metadata paths |
@@ -634,6 +639,33 @@ def create_field( |
634 | 639 | resp = self._post(FIELDS_BASE_PATH, json=json_data, **kwargs) |
635 | 640 | return self.parse_response(resp, FieldResponse) |
636 | 641 |
|
| 642 | + def get_field( |
| 643 | + self, |
| 644 | + field_name: str, |
| 645 | + **kwargs, |
| 646 | + ) -> Response: |
| 647 | + """Retrieve a specific metadata field by its name. |
| 648 | +
|
| 649 | + Args: |
| 650 | + field_name: The name of the field to retrieve. |
| 651 | + **kwargs: Additional kwargs to pass to the request. |
| 652 | +
|
| 653 | + Required roles: |
| 654 | + - can_read_metadata_fields |
| 655 | +
|
| 656 | + Returns: |
| 657 | + Response: An object containing the HTTP response and a `data` attribute |
| 658 | + with a `FieldResponse` model instance on success, or `None` on error. |
| 659 | +
|
| 660 | + Raises: |
| 661 | + - 400 Bad request |
| 662 | + - 401 Token is invalid |
| 663 | + - 404 Metadata field doesn't exist |
| 664 | + """ |
| 665 | + endpoint = FIELD_BY_NAME_PATH.format(field_name=field_name) |
| 666 | + resp = self._get(endpoint, **kwargs) |
| 667 | + return self.parse_response(resp, FieldResponse) |
| 668 | + |
637 | 669 | def update_field( |
638 | 670 | self, |
639 | 671 | field_name: str, |
@@ -678,8 +710,38 @@ def delete_field( |
678 | 710 | resp = self._delete(endpoint, **kwargs) |
679 | 711 | return self.parse_response(resp) |
680 | 712 |
|
681 | | - # Backward compatibility aliases |
682 | | - # ------------------------------ |
| 713 | + def get_fields( |
| 714 | + self, |
| 715 | + per_page: Optional[int] = None, |
| 716 | + last_field_name: Optional[str] = None, |
| 717 | + filter: Optional[str] = None, |
| 718 | + **kwargs, |
| 719 | + ) -> Response: |
| 720 | + """List all metadata fields. |
| 721 | +
|
| 722 | + Args: |
| 723 | + per_page: Optional The number of items for each page (Default 500). |
| 724 | + last_field_name: Optional If your request returns per_page entries, |
| 725 | + send the last value of "name" to fetch next page. |
| 726 | + filter: Optional A comma separated list of fieldnames to filter by. |
| 727 | + **kwargs: Additional query parameters to pass to the request. |
| 728 | +
|
| 729 | + Returns: |
| 730 | + Response: A paginated response containing a list of FieldResponse objects. |
| 731 | + """ |
| 732 | + params = {} |
| 733 | + if per_page is not None: |
| 734 | + params["per_page"] = per_page |
| 735 | + if last_field_name: |
| 736 | + params["last_field_name"] = last_field_name |
| 737 | + if filter: |
| 738 | + params["filter"] = filter |
| 739 | + |
| 740 | + # Add any additional params from kwargs |
| 741 | + params.update(kwargs) |
| 742 | + |
| 743 | + resp = self._get(FIELDS_BASE_PATH, params=params) |
| 744 | + return self.parse_response(resp, FieldListResponse) |
683 | 745 |
|
684 | 746 | def create_metadata_field( |
685 | 747 | self, |
|
0 commit comments