-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathevents_api_client.py
More file actions
24 lines (18 loc) · 924 Bytes
/
events_api_client.py
File metadata and controls
24 lines (18 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from contextvars import ContextVar
from flask import current_app
from notifications_utils.local_vars import LazyLocalGetter
from werkzeug.local import LocalProxy
from app import memo_resetters
from app.notify_client import NotifyAdminAPIClient, api_client_request_session
class EventsApiClient(NotifyAdminAPIClient):
def create_event(self, event_type, event_data):
data = {"event_type": event_type, "data": event_data}
resp = self.post(url="/events", data=data)
return resp["data"]
_events_api_client_context_var: ContextVar[EventsApiClient] = ContextVar("events_api_client")
get_events_api_client: LazyLocalGetter[EventsApiClient] = LazyLocalGetter(
_events_api_client_context_var,
lambda: EventsApiClient(current_app, request_session=api_client_request_session),
)
memo_resetters.append(lambda: get_events_api_client.clear())
events_api_client = LocalProxy(get_events_api_client)