|
| 1 | +# coding: utf-8 |
| 2 | +# |
| 3 | +# This code was auto generated by AfterShip SDK Generator. |
| 4 | +# Do not edit the class manually. |
| 5 | + |
| 6 | +import json |
| 7 | +from typing import Union, Annotated |
| 8 | + |
| 9 | +from pydantic import Field |
| 10 | + |
| 11 | +from tracking.models import ( |
| 12 | + DeleteCourierConnectionsByIdResponse, |
| 13 | + GetCourierConnectionsResponse, |
| 14 | + GetCourierConnectionsByIdResponse, |
| 15 | + PostCourierConnectionsRequest, |
| 16 | + PostCourierConnectionsResponse, |
| 17 | + PutCourierConnectionsByIdRequest, |
| 18 | + PutCourierConnectionsByIdResponse, |
| 19 | +) |
| 20 | +from tracking.request import ApiClient, validate_params |
| 21 | + |
| 22 | + |
| 23 | +class CourierConnectionApi(ApiClient): |
| 24 | + """CourierConnectionApi api implements""" |
| 25 | + |
| 26 | + @validate_params |
| 27 | + def delete_courier_connections_by_id( |
| 28 | + self, courier_connection_id: Annotated[str, Field(min_length=1)], **kwargs |
| 29 | + ) -> DeleteCourierConnectionsByIdResponse: |
| 30 | + """ |
| 31 | + Delete a courier connection. |
| 32 | + :param courier_connection_id: str. |
| 33 | + :param kwargs: |
| 34 | + request options: |
| 35 | + **headers** (dict): support custom headers. |
| 36 | + **verify** bool|str|SSLContext: SSL certificates (a.k.a CA bundle) used to |
| 37 | + verify the identity of requested hosts. Either `True` (default CA bundle), |
| 38 | + a path to an SSL certificate file, an `ssl.SSLContext`, or `False` |
| 39 | + (which will disable verification). |
| 40 | + """ |
| 41 | + url = f"/tracking/2025-04/courier-connections/{courier_connection_id}" |
| 42 | + |
| 43 | + result = self._request("DELETE", url=url, **kwargs) |
| 44 | + return DeleteCourierConnectionsByIdResponse().from_dict(result) |
| 45 | + |
| 46 | + @validate_params |
| 47 | + def get_courier_connections(self, **kwargs) -> GetCourierConnectionsResponse: |
| 48 | + """ |
| 49 | + Get courier connection results of multiple courier connections. |
| 50 | + :param kwargs: |
| 51 | + request options: |
| 52 | + **headers** (dict): support custom headers. |
| 53 | + **verify** bool|str|SSLContext: SSL certificates (a.k.a CA bundle) used to |
| 54 | + verify the identity of requested hosts. Either `True` (default CA bundle), |
| 55 | + a path to an SSL certificate file, an `ssl.SSLContext`, or `False` |
| 56 | + (which will disable verification). |
| 57 | + query params: |
| 58 | + **courier_slug**: str. Unique courier code.(Example: dhl-api) |
| 59 | + **cursor**: str. A string representing the cursor value for the current page of results. |
| 60 | + **limit**: str. Number of courier connections each page contain. (Default: 100, Max: 200) |
| 61 | + """ |
| 62 | + url = "/tracking/2025-04/courier-connections" |
| 63 | + params_keys = { |
| 64 | + "courier_slug", |
| 65 | + "cursor", |
| 66 | + "limit", |
| 67 | + } |
| 68 | + params = {key: kwargs.pop(key) for key in params_keys if key in kwargs} |
| 69 | + |
| 70 | + result = self._request("GET", url=url, params=params, **kwargs) |
| 71 | + return GetCourierConnectionsResponse().from_dict( |
| 72 | + { |
| 73 | + "pagination": result.get("pagination"), |
| 74 | + "courier_connections": result.get("courier_connections"), |
| 75 | + } |
| 76 | + ) |
| 77 | + |
| 78 | + @validate_params |
| 79 | + def get_courier_connections_by_id( |
| 80 | + self, courier_connection_id: Annotated[str, Field(min_length=1)], **kwargs |
| 81 | + ) -> GetCourierConnectionsByIdResponse: |
| 82 | + """ |
| 83 | + Get courier connection results of a single courier connection. |
| 84 | + :param courier_connection_id: str. |
| 85 | + :param kwargs: |
| 86 | + request options: |
| 87 | + **headers** (dict): support custom headers. |
| 88 | + **verify** bool|str|SSLContext: SSL certificates (a.k.a CA bundle) used to |
| 89 | + verify the identity of requested hosts. Either `True` (default CA bundle), |
| 90 | + a path to an SSL certificate file, an `ssl.SSLContext`, or `False` |
| 91 | + (which will disable verification). |
| 92 | + """ |
| 93 | + url = f"/tracking/2025-04/courier-connections/{courier_connection_id}" |
| 94 | + |
| 95 | + result = self._request("GET", url=url, **kwargs) |
| 96 | + return GetCourierConnectionsByIdResponse().from_dict(result) |
| 97 | + |
| 98 | + @validate_params |
| 99 | + def post_courier_connections( |
| 100 | + self, post_courier_connections_request: Union[PostCourierConnectionsRequest, dict], **kwargs |
| 101 | + ) -> PostCourierConnectionsResponse: |
| 102 | + """ |
| 103 | +
|
| 104 | + :param post_courier_connections_request: |
| 105 | + :param kwargs: |
| 106 | + request options: |
| 107 | + **headers** (dict): support custom headers. |
| 108 | + **verify** bool|str|SSLContext: SSL certificates (a.k.a CA bundle) used to |
| 109 | + verify the identity of requested hosts. Either `True` (default CA bundle), |
| 110 | + a path to an SSL certificate file, an `ssl.SSLContext`, or `False` |
| 111 | + (which will disable verification). |
| 112 | + """ |
| 113 | + url = "/tracking/2025-04/courier-connections" |
| 114 | + |
| 115 | + body = post_courier_connections_request |
| 116 | + if not isinstance(body, dict): |
| 117 | + body = post_courier_connections_request.model_dump(exclude_none=True) |
| 118 | + body = json.dumps(body) |
| 119 | + |
| 120 | + result = self._request("POST", url=url, body=body, **kwargs) |
| 121 | + return PostCourierConnectionsResponse().from_dict(result) |
| 122 | + |
| 123 | + @validate_params |
| 124 | + def put_courier_connections_by_id( |
| 125 | + self, |
| 126 | + courier_connection_id: Annotated[str, Field(min_length=1)], |
| 127 | + put_courier_connections_by_id_request: Union[PutCourierConnectionsByIdRequest, dict], |
| 128 | + **kwargs, |
| 129 | + ) -> PutCourierConnectionsByIdResponse: |
| 130 | + """ |
| 131 | + Update a courier connection. |
| 132 | + :param courier_connection_id: str. |
| 133 | + :param put_courier_connections_by_id_request: |
| 134 | + :param kwargs: |
| 135 | + request options: |
| 136 | + **headers** (dict): support custom headers. |
| 137 | + **verify** bool|str|SSLContext: SSL certificates (a.k.a CA bundle) used to |
| 138 | + verify the identity of requested hosts. Either `True` (default CA bundle), |
| 139 | + a path to an SSL certificate file, an `ssl.SSLContext`, or `False` |
| 140 | + (which will disable verification). |
| 141 | + """ |
| 142 | + url = f"/tracking/2025-04/courier-connections/{courier_connection_id}" |
| 143 | + |
| 144 | + body = put_courier_connections_by_id_request |
| 145 | + if not isinstance(body, dict): |
| 146 | + body = put_courier_connections_by_id_request.model_dump(exclude_none=True) |
| 147 | + body = json.dumps(body) |
| 148 | + |
| 149 | + result = self._request("PATCH", url=url, body=body, **kwargs) |
| 150 | + return PutCourierConnectionsByIdResponse().from_dict(result) |
0 commit comments