|
1 | | -""" |
2 | | -This module provides functionality for managing individual analytics rules in Typesense. |
3 | | -
|
4 | | -Classes: |
5 | | - - AnalyticsRule: Handles operations related to a specific analytics rule. |
6 | | -
|
7 | | -Methods: |
8 | | - - __init__: Initializes the AnalyticsRule object. |
9 | | - - _endpoint_path: Constructs the API endpoint path for this specific analytics rule. |
10 | | - - retrieve: Retrieves the details of this specific analytics rule. |
11 | | - - delete: Deletes this specific analytics rule. |
12 | | -
|
13 | | -The AnalyticsRule class interacts with the Typesense API to manage operations on a |
14 | | -specific analytics rule. It provides methods to retrieve and delete individual rules. |
15 | | -
|
16 | | -For more information on analytics, refer to the Analytics & Query Suggestion |
17 | | -[documentation](https://typesense.org/docs/27.0/api/analytics-query-suggestions.html) |
18 | | -
|
19 | | -This module uses type hinting and is compatible with Python 3.11+ as well as earlier |
20 | | -versions through the use of the typing_extensions library. |
21 | | -""" |
| 1 | +"""Per-rule client for Analytics rules operations.""" |
22 | 2 |
|
23 | 3 | import sys |
24 | 4 |
|
|
28 | 8 | import typing_extensions as typing |
29 | 9 |
|
30 | 10 | from typesense.api_call import ApiCall |
31 | | -from typesense.types.analytics_rule import ( |
32 | | - RuleDeleteSchema, |
33 | | - RuleSchemaForCounters, |
34 | | - RuleSchemaForQueries, |
35 | | -) |
| 11 | +from typesense.types.analytics import AnalyticsRule |
36 | 12 |
|
37 | 13 |
|
38 | 14 | class AnalyticsRule: |
39 | | - """ |
40 | | - Class for managing individual analytics rules in Typesense. |
41 | | -
|
42 | | - This class provides methods to interact with a specific analytics rule, |
43 | | - including retrieving and deleting it. |
44 | | -
|
45 | | - Attributes: |
46 | | - api_call (ApiCall): The API call object for making requests. |
47 | | - rule_id (str): The ID of the analytics rule. |
48 | | - """ |
49 | | - |
50 | | - def __init__(self, api_call: ApiCall, rule_id: str): |
51 | | - """ |
52 | | - Initialize the AnalyticsRule object. |
53 | | -
|
54 | | - Args: |
55 | | - api_call (ApiCall): The API call object for making requests. |
56 | | - rule_id (str): The ID of the analytics rule. |
57 | | - """ |
| 15 | + def __init__(self, api_call: ApiCall, rule_name: str) -> None: |
58 | 16 | self.api_call = api_call |
59 | | - self.rule_id = rule_id |
| 17 | + self.rule_name = rule_name |
| 18 | + |
| 19 | + @property |
| 20 | + def _endpoint_path(self) -> str: |
| 21 | + from typesense.analytics_rules import AnalyticsRules |
60 | 22 |
|
61 | | - def retrieve( |
62 | | - self, |
63 | | - ) -> typing.Union[RuleSchemaForQueries, RuleSchemaForCounters]: |
64 | | - """ |
65 | | - Retrieve this specific analytics rule. |
| 23 | + return "/".join([AnalyticsRules.resource_path, self.rule_name]) |
66 | 24 |
|
67 | | - Returns: |
68 | | - Union[RuleSchemaForQueries, RuleSchemaForCounters]: |
69 | | - The schema containing the rule details. |
70 | | - """ |
71 | | - response: typing.Union[RuleSchemaForQueries, RuleSchemaForCounters] = ( |
72 | | - self.api_call.get( |
73 | | - self._endpoint_path, |
74 | | - entity_type=typing.Union[RuleSchemaForQueries, RuleSchemaForCounters], |
75 | | - as_json=True, |
76 | | - ) |
| 25 | + def retrieve(self) -> AnalyticsRule: |
| 26 | + response: AnalyticsRule = self.api_call.get( |
| 27 | + self._endpoint_path, |
| 28 | + as_json=True, |
| 29 | + entity_type=AnalyticsRule, |
77 | 30 | ) |
78 | 31 | return response |
79 | 32 |
|
80 | | - def delete(self) -> RuleDeleteSchema: |
81 | | - """ |
82 | | - Delete this specific analytics rule. |
83 | | -
|
84 | | - Returns: |
85 | | - RuleDeleteSchema: The schema containing the deletion response. |
86 | | - """ |
87 | | - response: RuleDeleteSchema = self.api_call.delete( |
| 33 | + def delete(self) -> AnalyticsRule: |
| 34 | + response: AnalyticsRule = self.api_call.delete( |
88 | 35 | self._endpoint_path, |
89 | | - entity_type=RuleDeleteSchema, |
| 36 | + entity_type=AnalyticsRule, |
90 | 37 | ) |
91 | | - |
92 | 38 | return response |
93 | 39 |
|
94 | | - @property |
95 | | - def _endpoint_path(self) -> str: |
96 | | - """ |
97 | | - Construct the API endpoint path for this specific analytics rule. |
98 | | -
|
99 | | - Returns: |
100 | | - str: The constructed endpoint path. |
101 | | - """ |
102 | | - from typesense.analytics_rules import AnalyticsRules |
103 | 40 |
|
104 | | - return "/".join([AnalyticsRules.resource_path, self.rule_id]) |
0 commit comments