feat: Bump version to 0.7.0 and update media file upload functionality
This commit is contained in:
parent
9eb1f4a641
commit
e723356c75
3 changed files with 74 additions and 31 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
"""Elytra PIM Client - A Pythonic client for the Elytra PIM API"""
|
"""Elytra PIM Client - A Pythonic client for the Elytra PIM API"""
|
||||||
|
|
||||||
__version__ = "0.6.0"
|
__version__ = "0.7.0"
|
||||||
__author__ = "Your Name"
|
__author__ = "Your Name"
|
||||||
|
|
||||||
from . import rest_api
|
from . import rest_api
|
||||||
|
|
@ -8,27 +8,47 @@ from .client import ElytraClient
|
||||||
from .exceptions import ElytraAPIError, ElytraAuthenticationError
|
from .exceptions import ElytraAPIError, ElytraAuthenticationError
|
||||||
from .models import (
|
from .models import (
|
||||||
ProductAttributeResponse,
|
ProductAttributeResponse,
|
||||||
|
SingleMediaResponse,
|
||||||
|
SingleNewMediaRequestBody,
|
||||||
SingleNewProductGroupRequestBody,
|
SingleNewProductGroupRequestBody,
|
||||||
SingleNewProductRequestBody,
|
SingleNewProductRequestBody,
|
||||||
|
SingleNewTextRequestBody,
|
||||||
|
SingleNewTreeGroupRequestBody,
|
||||||
SingleProductGroupResponse,
|
SingleProductGroupResponse,
|
||||||
SingleProductResponse,
|
SingleProductResponse,
|
||||||
|
SingleTextResponse,
|
||||||
|
SingleTreeGroupResponse,
|
||||||
|
SingleUpdateMediaRequestBody,
|
||||||
SingleUpdateProductGroupRequestBody,
|
SingleUpdateProductGroupRequestBody,
|
||||||
SingleUpdateProductRequestBody,
|
SingleUpdateProductRequestBody,
|
||||||
|
SingleUpdateTextRequestBody,
|
||||||
|
SingleUpdateTreeGroupRequestBody,
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"ElytraClient",
|
"ElytraClient",
|
||||||
"ElytraAPIError",
|
"ElytraAPIError",
|
||||||
"ElytraAuthenticationError",
|
"ElytraAuthenticationError",
|
||||||
# Response models
|
# Product models
|
||||||
"SingleProductResponse",
|
"SingleProductResponse",
|
||||||
"SingleProductGroupResponse",
|
"SingleProductGroupResponse",
|
||||||
"ProductAttributeResponse",
|
"ProductAttributeResponse",
|
||||||
# Request models
|
|
||||||
"SingleNewProductRequestBody",
|
"SingleNewProductRequestBody",
|
||||||
"SingleUpdateProductRequestBody",
|
"SingleUpdateProductRequestBody",
|
||||||
"SingleNewProductGroupRequestBody",
|
"SingleNewProductGroupRequestBody",
|
||||||
"SingleUpdateProductGroupRequestBody",
|
"SingleUpdateProductGroupRequestBody",
|
||||||
|
# Media models
|
||||||
|
"SingleMediaResponse",
|
||||||
|
"SingleNewMediaRequestBody",
|
||||||
|
"SingleUpdateMediaRequestBody",
|
||||||
|
# Text models
|
||||||
|
"SingleTextResponse",
|
||||||
|
"SingleNewTextRequestBody",
|
||||||
|
"SingleUpdateTextRequestBody",
|
||||||
|
# Tree group models
|
||||||
|
"SingleTreeGroupResponse",
|
||||||
|
"SingleNewTreeGroupRequestBody",
|
||||||
|
"SingleUpdateTreeGroupRequestBody",
|
||||||
# Legacy REST API subpackage
|
# Legacy REST API subpackage
|
||||||
"rest_api",
|
"rest_api",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -646,51 +646,74 @@ class ElytraClient:
|
||||||
|
|
||||||
def upload_media_file(
|
def upload_media_file(
|
||||||
self,
|
self,
|
||||||
|
file_bytes: bytes,
|
||||||
media_id: int,
|
media_id: int,
|
||||||
file_path: str,
|
mam_system: str,
|
||||||
language_code: str = "en",
|
language_code: Optional[str] = None,
|
||||||
|
filename: str = "upload",
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Upload a file for a media item.
|
Upload a file for a media item using multipart/form-data.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
media_id: The media ID
|
file_bytes: Raw file content as bytes
|
||||||
file_path: Path to the file to upload
|
media_id: The Elytra media ID to attach the file to
|
||||||
language_code: Language code for the file
|
mam_system: MAM system identifier (e.g. 'fs', 'sixomc', 'cumulus')
|
||||||
|
language_code: Optional language code for the file
|
||||||
|
filename: Filename hint sent with the upload
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Upload response
|
Upload response dict
|
||||||
|
|
||||||
Note:
|
|
||||||
This method uses multipart/form-data encoding for file upload.
|
|
||||||
The actual file upload implementation may require custom handling
|
|
||||||
outside of the standard JSON request pattern.
|
|
||||||
"""
|
"""
|
||||||
# Note: This is a placeholder for file upload functionality
|
url = urljoin(self.base_url, "/media/file")
|
||||||
# Actual implementation would need to handle multipart/form-data
|
|
||||||
raise NotImplementedError(
|
form_data: Dict[str, Any] = {
|
||||||
"File upload requires special multipart/form-data handling. "
|
"mediaId": str(media_id),
|
||||||
"Please use direct requests session or a specialized file upload method."
|
"mamSystem": mam_system,
|
||||||
|
}
|
||||||
|
if language_code:
|
||||||
|
form_data["languageCode"] = language_code
|
||||||
|
|
||||||
|
# Build request manually so requests can set the multipart Content-Type boundary
|
||||||
|
# without being overridden by the session-level Content-Type: application/json header.
|
||||||
|
req = requests.Request(
|
||||||
|
"POST",
|
||||||
|
url,
|
||||||
|
headers={"Authorization": f"Bearer {self.api_key}", "Accept": "application/json"},
|
||||||
|
files={"file": (filename, file_bytes)},
|
||||||
|
data=form_data,
|
||||||
)
|
)
|
||||||
|
prepared = req.prepare()
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = self.session.send(prepared, timeout=self.timeout)
|
||||||
|
response.raise_for_status()
|
||||||
|
except requests.exceptions.HTTPError as e:
|
||||||
|
self._handle_http_error(e)
|
||||||
|
raise
|
||||||
|
|
||||||
|
return response.json()
|
||||||
|
|
||||||
def download_media_file(self, media_file_id: int) -> bytes:
|
def download_media_file(self, media_file_id: int) -> bytes:
|
||||||
"""
|
"""
|
||||||
Download a media file.
|
Download a media file by its file ID.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
media_file_id: The media file ID
|
media_file_id: The media file ID
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
File content as bytes
|
File content as raw bytes
|
||||||
|
|
||||||
Note:
|
|
||||||
This method returns raw binary data and should be handled differently
|
|
||||||
from typical JSON API responses.
|
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError(
|
url = urljoin(self.base_url, f"/media/file/{media_file_id}")
|
||||||
"File download requires special binary data handling. "
|
|
||||||
"Please use direct requests session or a specialized file download method."
|
try:
|
||||||
)
|
response = self.session.get(url, timeout=self.timeout)
|
||||||
|
response.raise_for_status()
|
||||||
|
except requests.exceptions.HTTPError as e:
|
||||||
|
self._handle_http_error(e)
|
||||||
|
raise
|
||||||
|
|
||||||
|
return response.content
|
||||||
|
|
||||||
def delete_media_file(self, media_file_id: int) -> Dict[str, Any]:
|
def delete_media_file(self, media_file_id: int) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "elytra-pim-client"
|
name = "elytra-pim-client"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
description = "A Pythonic client for the Elytra PIM API"
|
description = "A Pythonic client for the Elytra PIM API"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.9"
|
requires-python = ">=3.9"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue