forked from typesense/typesense-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics_events.py
More file actions
73 lines (61 loc) · 2 KB
/
analytics_events.py
File metadata and controls
73 lines (61 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Client for Analytics events and status operations."""
import sys
if sys.version_info >= (3, 11):
import typing
else:
import typing_extensions as typing
from typesense.api_call import ApiCall
from typesense.types.analytics import (
AnalyticsEvent as AnalyticsEventSchema,
AnalyticsEventCreateResponse,
AnalyticsEventsResponse,
AnalyticsStatus,
)
class AnalyticsEvents:
events_path: typing.Final[str] = "/analytics/events"
flush_path: typing.Final[str] = "/analytics/flush"
status_path: typing.Final[str] = "/analytics/status"
def __init__(self, api_call: ApiCall) -> None:
self.api_call = api_call
def create(self, event: AnalyticsEventSchema) -> AnalyticsEventCreateResponse:
response: AnalyticsEventCreateResponse = self.api_call.post(
AnalyticsEvents.events_path,
body=event,
as_json=True,
entity_type=AnalyticsEventCreateResponse,
)
return response
def retrieve(
self,
*,
user_id: str,
name: str,
n: int,
) -> AnalyticsEventsResponse:
params: typing.Dict[str, typing.Union[str, int]] = {
"user_id": user_id,
"name": name,
"n": n,
}
response: AnalyticsEventsResponse = self.api_call.get(
AnalyticsEvents.events_path,
params=params,
as_json=True,
entity_type=AnalyticsEventsResponse,
)
return response
def flush(self) -> AnalyticsEventCreateResponse:
response: AnalyticsEventCreateResponse = self.api_call.post(
AnalyticsEvents.flush_path,
body={},
as_json=True,
entity_type=AnalyticsEventCreateResponse,
)
return response
def status(self) -> AnalyticsStatus:
response: AnalyticsStatus = self.api_call.get(
AnalyticsEvents.status_path,
as_json=True,
entity_type=AnalyticsStatus,
)
return response