|
| 1 | +from typing import AsyncIterator, Iterator, Optional |
| 2 | +import re |
| 3 | + |
| 4 | +from httpx import Response |
| 5 | +from httpx._types import RequestFiles |
| 6 | + |
| 7 | +from mpt_api_client.http import AsyncService, Service |
| 8 | +from mpt_api_client.models import File, Model, ResourceData |
| 9 | + |
| 10 | + |
| 11 | +class AgreementAttachment(Model): |
| 12 | + """Agreement attachment resource.""" |
| 13 | + |
| 14 | + |
| 15 | +class AgreementsAttachmentServiceConfig: |
| 16 | + """Orders service config.""" |
| 17 | + |
| 18 | + _endpoint = "/public/v1/commerce/agreements/{agreement_id}/attachments" |
| 19 | + _model_class = AgreementAttachment |
| 20 | + _collection_key = "data" |
| 21 | + |
| 22 | + |
| 23 | +class AgreementsAttachmentService(Service[AgreementAttachment], AgreementsAttachmentServiceConfig): |
| 24 | + """Attachments service.""" |
| 25 | + |
| 26 | + def create( |
| 27 | + self, resource_data: ResourceData, files: RequestFiles | None = None |
| 28 | + ) -> AgreementAttachment: |
| 29 | + response = self.http_client.post(self.endpoint, json=resource_data, files=files) |
| 30 | + response.raise_for_status() |
| 31 | + return AgreementAttachment.from_response(response) |
| 32 | + |
| 33 | + def download(self, agreement_id: str) -> File: |
| 34 | + """Renders the template for the given Agreement id. |
| 35 | +
|
| 36 | + Args: |
| 37 | + agreement_id: Agreement ID. |
| 38 | +
|
| 39 | + Returns: |
| 40 | + Agreement template. |
| 41 | + """ |
| 42 | + response: Response = self._resource_do_request( |
| 43 | + agreement_id, |
| 44 | + method="GET", |
| 45 | + ) |
| 46 | + return File(response) |
| 47 | + |
| 48 | + |
| 49 | +class AsyncAgreementsAttachmentService( |
| 50 | + AsyncService[AgreementAttachment], AgreementsAttachmentServiceConfig |
| 51 | +): |
| 52 | + """Attachments service.""" |
| 53 | + |
| 54 | + async def download(self, agreement_id: str) -> File: |
| 55 | + """Renders the template for the given Agreement id. |
| 56 | +
|
| 57 | + Args: |
| 58 | + agreement_id: Agreement ID. |
| 59 | +
|
| 60 | + Returns: |
| 61 | + Agreement template. |
| 62 | + """ |
| 63 | + response = await self._resource_do_request( |
| 64 | + agreement_id, method="GET", headers={"Accept": "*"} |
| 65 | + ) |
| 66 | + return File(response) |
0 commit comments