|
| 1 | +""" |
| 2 | +lokalise.client_methods.glossary_terms |
| 3 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4 | +This module contains API client definition for glossary terms. |
| 5 | +""" |
| 6 | +from typing import Optional, Union, Dict, Any, List |
| 7 | +from lokalise.models.glossary_term import GlossaryTermModel |
| 8 | +from lokalise.collections.glossary_terms import GlossaryTermsCollection |
| 9 | +from .endpoint_provider import EndpointProviderMixin |
| 10 | + |
| 11 | + |
| 12 | +class GlossaryTermsMethods(EndpointProviderMixin): |
| 13 | + """Glossary term client methods. |
| 14 | + """ |
| 15 | + |
| 16 | + def glossary_terms(self, project_id: str, |
| 17 | + params: Optional[Dict] = None) -> GlossaryTermsCollection: |
| 18 | + """Fetches all glossary terms for the given project. |
| 19 | +
|
| 20 | + :param str project_id: ID of the project |
| 21 | + :param dict params: (optional) Request parameters |
| 22 | + :return: Collection of glossary terms |
| 23 | + """ |
| 24 | + raw_terms = self.get_endpoint("glossary_terms"). \ |
| 25 | + all(params=params, parent_id=project_id) |
| 26 | + return GlossaryTermsCollection(raw_terms) |
| 27 | + |
| 28 | + def glossary_term(self, |
| 29 | + project_id: str, |
| 30 | + glossary_term_id: Union[str, int]) -> GlossaryTermModel: |
| 31 | + """Fetches a glossary term. |
| 32 | +
|
| 33 | + :param str project_id: ID of the project |
| 34 | + :param glossary_term_id: ID of the term to fetch |
| 35 | + :return: Glossary term model |
| 36 | + """ |
| 37 | + raw_term = self.get_endpoint("glossary_terms"). \ |
| 38 | + find(parent_id=project_id, resource_id=glossary_term_id) |
| 39 | + return GlossaryTermModel(raw_term) |
| 40 | + |
| 41 | + def create_glossary_terms(self, |
| 42 | + project_id: str, |
| 43 | + params: Union[Dict[str, Any], List[Dict]] |
| 44 | + ) -> GlossaryTermsCollection: |
| 45 | + """Creates one or more glossary terms in the project |
| 46 | +
|
| 47 | + :param str project_id: ID of the project |
| 48 | + :param params: Glossary terms parameters |
| 49 | + :type params: list or dict |
| 50 | + :return: Glossary terms collection |
| 51 | + """ |
| 52 | + raw_terms = self.get_endpoint("glossary_terms"). \ |
| 53 | + create(params=params, wrapper_attr="terms", parent_id=project_id) |
| 54 | + |
| 55 | + return GlossaryTermsCollection(raw_terms) |
| 56 | + |
| 57 | + def update_glossary_terms(self, |
| 58 | + project_id: str, |
| 59 | + params: Dict[str, Any]) -> GlossaryTermsCollection: |
| 60 | + """Updates one or more glossary terms. |
| 61 | +
|
| 62 | + :param str project_id: ID of the project |
| 63 | + :param dict params: Glossary terms parameters |
| 64 | + :return: Glossary terms collection |
| 65 | + """ |
| 66 | + raw_terms = self.get_endpoint("glossary_terms"). \ |
| 67 | + update(params=params, wrapper_attr="terms", parent_id=project_id) |
| 68 | + return GlossaryTermsCollection(raw_terms) |
| 69 | + |
| 70 | + def delete_glossary_terms(self, project_id: str, |
| 71 | + glossary_terms_ids: List[Union[str, int]]) -> Dict: |
| 72 | + """Deletes one or more glossary terms. |
| 73 | +
|
| 74 | + :param str project_id: ID of the project |
| 75 | + :type glossary_terms_id: int or str |
| 76 | + :param list glossary_terms_ids: List of the term IDs to delete |
| 77 | + :return: Delete response |
| 78 | + :rtype dict: |
| 79 | + """ |
| 80 | + response = self.get_endpoint("glossary_terms"). \ |
| 81 | + delete( |
| 82 | + params=glossary_terms_ids, |
| 83 | + wrapper_attr="terms", |
| 84 | + parent_id=project_id) |
| 85 | + return response |
0 commit comments