|
| 1 | +from mpt_api_client.models import ResourceData |
| 2 | + |
| 3 | + |
| 4 | +class PublishableMixin[Model]: |
| 5 | + """Publishable mixin adds the ability to review, publish and unpublish.""" |
| 6 | + |
| 7 | + def review(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 8 | + """Update state to Pending. |
| 9 | +
|
| 10 | + Args: |
| 11 | + resource_id: Resource ID |
| 12 | + resource_data: Resource data will be updated |
| 13 | + """ |
| 14 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 15 | + resource_id, "POST", "review", json=resource_data |
| 16 | + ) |
| 17 | + |
| 18 | + def publish(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 19 | + """Update state to Published. |
| 20 | +
|
| 21 | + Args: |
| 22 | + resource_id: Resource ID |
| 23 | + resource_data: Resource data will be updated |
| 24 | + """ |
| 25 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 26 | + resource_id, "POST", "publish", json=resource_data |
| 27 | + ) |
| 28 | + |
| 29 | + def unpublish(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 30 | + """Update state to Unpublished. |
| 31 | +
|
| 32 | + Args: |
| 33 | + resource_id: Resource ID |
| 34 | + resource_data: Resource data will be updated |
| 35 | + """ |
| 36 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 37 | + resource_id, "POST", "unpublish", json=resource_data |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +class AsyncPublishableMixin[Model]: |
| 42 | + """Publishable mixin adds the ability to review, publish and unpublish.""" |
| 43 | + |
| 44 | + async def review(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 45 | + """Update state to reviewing. |
| 46 | +
|
| 47 | + Args: |
| 48 | + resource_id: Resource ID |
| 49 | + resource_data: Resource data will be updated |
| 50 | + """ |
| 51 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 52 | + resource_id, "POST", "review", json=resource_data |
| 53 | + ) |
| 54 | + |
| 55 | + async def publish(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 56 | + """Update state to Published. |
| 57 | +
|
| 58 | + Args: |
| 59 | + resource_id: Resource ID |
| 60 | + resource_data: Resource data will be updated |
| 61 | + """ |
| 62 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 63 | + resource_id, "POST", "publish", json=resource_data |
| 64 | + ) |
| 65 | + |
| 66 | + async def unpublish(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 67 | + """Update state to Unpublished. |
| 68 | +
|
| 69 | + Args: |
| 70 | + resource_id: Resource ID |
| 71 | + resource_data: Resource data will be updated |
| 72 | + """ |
| 73 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 74 | + resource_id, "POST", "unpublish", json=resource_data |
| 75 | + ) |
0 commit comments