datadog_api/apis/
events.rs

1use crate::{
2    client::DatadogClient,
3    models::{EventCreateRequest, EventResponse, EventsResponse},
4    Result,
5};
6use serde::Serialize;
7
8/// API client for Datadog events endpoints.
9pub struct EventsApi {
10    client: DatadogClient,
11}
12
13impl EventsApi {
14    /// Creates a new API client.
15    #[must_use]
16    pub const fn new(client: DatadogClient) -> Self {
17        Self { client }
18    }
19
20    pub async fn list_events(
21        &self,
22        start: i64,
23        end: i64,
24        priority: Option<&str>,
25        sources: Option<&str>,
26    ) -> Result<EventsResponse> {
27        #[derive(Serialize)]
28        struct QueryParams<'a> {
29            start: i64,
30            end: i64,
31            #[serde(skip_serializing_if = "Option::is_none")]
32            priority: Option<&'a str>,
33            #[serde(skip_serializing_if = "Option::is_none")]
34            sources: Option<&'a str>,
35        }
36
37        let params = QueryParams {
38            start,
39            end,
40            priority,
41            sources,
42        };
43
44        self.client.get_with_query("/api/v1/events", &params).await
45    }
46
47    pub async fn post_event(&self, request: &EventCreateRequest) -> Result<EventResponse> {
48        self.client.post("/api/v1/events", request).await
49    }
50
51    pub async fn get_event(&self, event_id: i64) -> Result<EventResponse> {
52        let endpoint = format!("/api/v1/events/{}", event_id);
53        self.client.get(&endpoint).await
54    }
55}