Skip to content

Commit e13f017

Browse files
authored
Merge pull request #90 from NorthShoreAutomation/feature/metatadata-fields-get
feat: implement metadata field management with get_field and get_fiel…
2 parents 9b8af4c + c8efe8d commit e13f017

4 files changed

Lines changed: 441 additions & 5 deletions

File tree

docs/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Changelog
22

3+
## 2025-05-30 "Metadata Enhancements & SDK Improvements" - version 1.13.0
4+
5+
### Added
6+
- Implemented `get_field(field_name: str)` method in `pythonik.specs.metadata.MetadataSpec` to retrieve a specific metadata field by its name.
7+
- Added corresponding unit tests for `get_field` covering success (200), not found (404), and unauthorized (401) scenarios.
8+
- Implemented `list_fields` method in `pythonik.specs.metadata.MetadataSpec` to retrieve a list of all metadata fields.
9+
- Added corresponding unit tests for `list_fields`
10+
- Implemented methods for retrieving metadata for specific object types (e.g., assets, collections, segments) and generic object metadata retrieval in `MetadataSpec` (PR #78).
11+
12+
### Changed
13+
- Updated `.gitignore` to include macOS-specific patterns (e.g., `.DS_Store`) for improved repository hygiene (PR #82).
14+
15+
### Fixed
16+
- N/A
17+
18+
### Technical Details
19+
This release introduces the ability to fetch individual metadata fields by name, adds comprehensive integration testing capabilities for metadata fields, and enhances object metadata retrieval. It also includes improvements to the development environment with an updated .gitignore.
20+
321
## 2025-05-09 "IconikFieldType Update" - version 1.12.2
422

523
### Fixed

pythonik/models/metadata/fields.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,22 @@ class FieldResponse(BaseModel):
111111

112112
class Config:
113113
use_enum_values = True
114+
115+
116+
class FieldListResponse(BaseModel):
117+
"""Response model for a paginated list of metadata fields.
118+
119+
This follows the standard pagination format used by the Iconik API.
120+
"""
121+
first_url: Optional[str] = None
122+
last_url: Optional[str] = None
123+
next_url: Optional[str] = None
124+
objects: List[FieldResponse] = []
125+
page: Optional[int] = None
126+
pages: Optional[int] = None
127+
per_page: Optional[int] = None
128+
prev_url: Optional[str] = None
129+
total: Optional[int] = None
130+
131+
class Config:
132+
use_enum_values = True

pythonik/specs/metadata.py

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
UpdateMetadata,
1414
UpdateMetadataResponse,
1515
)
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+
)
1722
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
1924

2025

2126
# Asset metadata paths
@@ -634,6 +639,33 @@ def create_field(
634639
resp = self._post(FIELDS_BASE_PATH, json=json_data, **kwargs)
635640
return self.parse_response(resp, FieldResponse)
636641

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+
637669
def update_field(
638670
self,
639671
field_name: str,
@@ -678,8 +710,38 @@ def delete_field(
678710
resp = self._delete(endpoint, **kwargs)
679711
return self.parse_response(resp)
680712

681-
# Backward compatibility aliases
682-
# ------------------------------
713+
def list_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)
683745

684746
def create_metadata_field(
685747
self,

0 commit comments

Comments
 (0)