|
| 1 | +import json |
| 2 | +from .base import BaseResource |
| 3 | + |
| 4 | + |
| 5 | +class ProductsResource(BaseResource): |
| 6 | + """ Allows listing and obtaining several types of objects. |
| 7 | + :param Config config: Config object or ``None`` to use environment config (default). |
| 8 | + """ |
| 9 | + resource = 'products' |
| 10 | + |
| 11 | + def list_parameters(self, product_id): |
| 12 | + """ List parameters for a product. |
| 13 | + :param str product_id: Primary key of the product to search for. |
| 14 | + :return: response object with templates contents. |
| 15 | + """ |
| 16 | + """ |
| 17 | + # type: (Dict[str, Any]) -> List[Any] |
| 18 | + """ |
| 19 | + response, _ = self._api.get( |
| 20 | + '/public/v1/products/' + product_id + '/parameters/' |
| 21 | + ) |
| 22 | + response = json.loads(response) |
| 23 | + return response |
| 24 | + |
| 25 | + def create_parameter(self, product_id, body): |
| 26 | + """ Create parameter for a product. |
| 27 | + :param str product_id: Primary key of the product to create parameter. |
| 28 | + :param str body: Body of the parameter to create. |
| 29 | + :return: response object with templates contents. |
| 30 | + """ |
| 31 | + """ |
| 32 | + # type: (Dict[str, Any]) -> List[Any] |
| 33 | + """ |
| 34 | + if not product_id: |
| 35 | + raise ValueError('Invalid ID') |
| 36 | + path = '/public/v1/products/' + product_id + '/parameters/' |
| 37 | + response = self._api.post( |
| 38 | + path=path, |
| 39 | + json=body |
| 40 | + ) |
| 41 | + return response |
| 42 | + |
| 43 | + def update_parameter(self, product_id, parameter_id, body): |
| 44 | + """ Update parameter for a product. |
| 45 | + :param str product_id: Primary key of the product to update parameter. |
| 46 | + :param str parameter_id: Primary key of the parameter to update. |
| 47 | + :param str body: Body of the parameter to update. |
| 48 | + :return: response object with templates contents. |
| 49 | + """ |
| 50 | + """ |
| 51 | + # type: (Dict[str, Any]) -> List[Any] |
| 52 | + """ |
| 53 | + if not product_id: |
| 54 | + raise ValueError('Invalid ID') |
| 55 | + path = '/public/v1/products/' + product_id + '/parameters/' + parameter_id |
| 56 | + response = self._api.put( |
| 57 | + path=path, |
| 58 | + json=body |
| 59 | + ) |
| 60 | + return response |
| 61 | + |
| 62 | + def delete_parameter(self, product_id, parameter_id): |
| 63 | + """ Delete parameter for a product. |
| 64 | + :param str product_id: Primary key of the product to delete parameter. |
| 65 | + :param str parameter_id: Primary key of the parameter to delete. |
| 66 | + :return: response object with templates contents. |
| 67 | + """ |
| 68 | + """ |
| 69 | + # type: (Dict[str, Any]) -> List[Any] |
| 70 | + """ |
| 71 | + if not product_id: |
| 72 | + raise ValueError('Invalid ID') |
| 73 | + path = '/public/v1/products/' + product_id + '/parameters/' + parameter_id |
| 74 | + response = self._api.delete( |
| 75 | + path=path |
| 76 | + ) |
| 77 | + return response |
0 commit comments