|
| 1 | +"""Implementation of Product Client""" |
| 2 | + |
| 3 | +from typing import List, Optional |
| 4 | + |
| 5 | +from nisystemlink.clients import core |
| 6 | +from nisystemlink.clients.core._uplink._base_client import BaseClient |
| 7 | +from nisystemlink.clients.core._uplink._methods import delete, get, post |
| 8 | +from nisystemlink.clients.product.models import Product |
| 9 | +from uplink import Field, Query, returns |
| 10 | + |
| 11 | +from . import models |
| 12 | + |
| 13 | + |
| 14 | +class ProductClient(BaseClient): |
| 15 | + def __init__(self, configuration: Optional[core.HttpConfiguration] = None): |
| 16 | + """Initialize an instance. |
| 17 | +
|
| 18 | + Args: |
| 19 | + configuration: Defines the web server to connect to and information about |
| 20 | + how to connect. If not provided, the |
| 21 | + :class:`HttpConfigurationManager <nisystemlink.clients.core.HttpConfigurationManager>` |
| 22 | + is used to obtain the configuration. |
| 23 | +
|
| 24 | + Raises: |
| 25 | + ApiException: if unable to communicate with the Product Service. |
| 26 | + """ |
| 27 | + if configuration is None: |
| 28 | + configuration = core.HttpConfigurationManager.get_configuration() |
| 29 | + super().__init__(configuration, base_path="/nitestmonitor/v2/") |
| 30 | + |
| 31 | + @post("products", args=[Field("products")]) |
| 32 | + def create_products( |
| 33 | + self, products: List[Product] |
| 34 | + ) -> models.CreateProductsPartialSuccess: |
| 35 | + """Creates one or more products and returns errors for failed creations. |
| 36 | +
|
| 37 | + Args: |
| 38 | + products: A list of products to attempt to create. |
| 39 | +
|
| 40 | + Returns: A list of created products, products that failed to create, and errors for |
| 41 | + failures. |
| 42 | +
|
| 43 | + Raises: |
| 44 | + ApiException: if unable to communicate with the ``/nitestmonitor`` service of provided invalid |
| 45 | + arguments. |
| 46 | + """ |
| 47 | + ... |
| 48 | + |
| 49 | + @get( |
| 50 | + "products", |
| 51 | + args=[Query("continuationToken"), Query("take"), Query("returnCount")], |
| 52 | + ) |
| 53 | + def get_products_paged( |
| 54 | + self, |
| 55 | + continuation_token: Optional[str] = None, |
| 56 | + take: Optional[int] = None, |
| 57 | + return_count: Optional[bool] = None, |
| 58 | + ) -> models.PagedProducts: |
| 59 | + """Reads a list of products. |
| 60 | +
|
| 61 | + Args: |
| 62 | + continuation_token: The token used to paginate results. |
| 63 | + take: The number of products to get in this request. |
| 64 | + return_count: Whether or not to return the total number of products available. |
| 65 | +
|
| 66 | + Returns: |
| 67 | + A list of products. |
| 68 | +
|
| 69 | + Raises: |
| 70 | + ApiException: if unable to communicate with the ``/nitestmonitor`` Service |
| 71 | + or provided an invalid argument. |
| 72 | + """ |
| 73 | + ... |
| 74 | + |
| 75 | + @get("products/{id}") |
| 76 | + def get_product(self, id: str) -> models.Product: |
| 77 | + """Retrieves a single product by id. |
| 78 | +
|
| 79 | + Args: |
| 80 | + id (str): Unique ID of a products. |
| 81 | +
|
| 82 | + Returns: |
| 83 | + The single product matching `id` |
| 84 | +
|
| 85 | + Raises: |
| 86 | + ApiException: if unable to communicate with the ``/nitestmonitor`` Service |
| 87 | + or provided an invalid argument. |
| 88 | + """ |
| 89 | + ... |
| 90 | + |
| 91 | + @post("query-products") |
| 92 | + def query_products_paged( |
| 93 | + self, query: models.QueryProductsRequest |
| 94 | + ) -> models.PagedProducts: |
| 95 | + """Queries for products that match the filter. |
| 96 | +
|
| 97 | + Args: |
| 98 | + query : The query contains a DynamicLINQ query string in addition to other details |
| 99 | + about how to filter and return the list of products. |
| 100 | +
|
| 101 | + Returns: |
| 102 | + A paged list of products with a continuation token to get the next page. |
| 103 | +
|
| 104 | + Raises: |
| 105 | + ApiException: if unable to communicate with the ``/nitestmonitor`` Service or provided invalid |
| 106 | + arguments. |
| 107 | + """ |
| 108 | + ... |
| 109 | + |
| 110 | + @returns.json # type: ignore |
| 111 | + @post("query-product-values") |
| 112 | + def query_product_values( |
| 113 | + self, query: models.QueryProductValuesRequest |
| 114 | + ) -> List[str]: |
| 115 | + """Queries for products that match the query and returns a list of the requested field. |
| 116 | +
|
| 117 | + Args: |
| 118 | + query : The query for the fields you want. |
| 119 | +
|
| 120 | + Returns: |
| 121 | + A list of the values of the field you requested. |
| 122 | +
|
| 123 | + Raises: |
| 124 | + ApiException: if unable to communicate with the ``/nitestmonitor`` Service or provided |
| 125 | + invalid arguments. |
| 126 | + """ |
| 127 | + ... |
| 128 | + |
| 129 | + @post("update-products", args=[Field("products"), Field("replace")]) |
| 130 | + def update_products( |
| 131 | + self, products: List[Product], replace: bool = False |
| 132 | + ) -> models.CreateProductsPartialSuccess: |
| 133 | + """Updates a list of products with optional field replacement. |
| 134 | +
|
| 135 | + Args: |
| 136 | + `products`: A list of products to update. Products are matched for update by id. |
| 137 | + `replace`: Replace the existing fields instead of merging them. Defaults to `False`. |
| 138 | + If this is `True`, then `keywords` and `properties` for the product will be |
| 139 | + replaced by what is in the `products` provided in this request. |
| 140 | + If this is `False`, then the `keywords` and `properties` in this request will |
| 141 | + merge with what is already present in the server resource. |
| 142 | +
|
| 143 | + Returns: A list of updates products, products that failed to update, and errors for |
| 144 | + failures. |
| 145 | +
|
| 146 | + Raises: |
| 147 | + ApiException: if unable to communicate with the ``/nitestmonitor`` Service |
| 148 | + or provided an invalid argument. |
| 149 | + """ |
| 150 | + ... |
| 151 | + |
| 152 | + @delete("products/{id}") |
| 153 | + def delete_product(self, id: str) -> None: |
| 154 | + """Deletes a single product by id. |
| 155 | +
|
| 156 | + Args: |
| 157 | + id (str): Unique ID of a product. |
| 158 | +
|
| 159 | + Raises: |
| 160 | + ApiException: if unable to communicate with the ``/nitestmonitor`` Service |
| 161 | + or provided an invalid argument. |
| 162 | + """ |
| 163 | + ... |
| 164 | + |
| 165 | + @post("delete-products", args=[Field("ids")]) |
| 166 | + def delete_products( |
| 167 | + self, ids: List[str] |
| 168 | + ) -> Optional[models.DeleteProductsPartialSuccess]: |
| 169 | + """Deletes multiple products. |
| 170 | +
|
| 171 | + Args: |
| 172 | + ids (List[str]): List of unique IDs of products. |
| 173 | +
|
| 174 | + Returns: |
| 175 | + A partial success if any products failed to delete, or None if all |
| 176 | + products were deleted successfully. |
| 177 | +
|
| 178 | + Raises: |
| 179 | + ApiException: if unable to communicate with the ``/nitestmonitor`` Service |
| 180 | + or provided an invalid argument. |
| 181 | + """ |
| 182 | + ... |
0 commit comments