1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Events {
6 pub client: Client,
7}
8
9impl Events {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "List events\n\nLists all the detailed events which occured in the inboxes of the company ordered in reverse chronological order (newest first).\n> ⚠\u{fe0f} Deprecated field may be included\n>\n> This route return the deprecated `last_message` conversation field for conversations\n> associated with individual events. Please use the conversation's\n> `_links.related.last_message` field instead.\n\n\n**Parameters:**\n\n- `limit: Option<i64>`: Max number of results per page\n- `page_token: Option<String>`: Token to use to request the next page\n- `q: Option<String>`: Search query object with optional properties `before`, `after`, or `types`. `before` and `after` should be a timestamp in seconds with up to 3 decimal places. `types` should be a list of event types.\n\n```rust,no_run\nasync fn example_events_list() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::ListEventsResponse = client\n .events()\n .list(\n Some(4 as i64),\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
16 #[tracing::instrument]
17 pub async fn list<'a>(
18 &'a self,
19 limit: Option<i64>,
20 page_token: Option<String>,
21 q: Option<String>,
22 ) -> Result<crate::types::ListEventsResponse, crate::types::error::Error> {
23 let mut req = self.client.client.request(
24 http::Method::GET,
25 &format!("{}/{}", self.client.base_url, "events"),
26 );
27 req = req.bearer_auth(&self.client.token);
28 let mut query_params = Vec::new();
29 if let Some(p) = limit {
30 query_params.push(("limit", format!("{}", p)));
31 }
32
33 if let Some(p) = page_token {
34 query_params.push(("page_token", p));
35 }
36
37 if let Some(p) = q {
38 query_params.push(("q", p));
39 }
40
41 req = req.query(&query_params);
42 let resp = req.send().await?;
43 let status = resp.status();
44 if status.is_success() {
45 let text = resp.text().await.unwrap_or_default();
46 serde_json::from_str(&text).map_err(|err| {
47 crate::types::error::Error::from_serde_error(
48 format_serde_error::SerdeError::new(text.to_string(), err),
49 status,
50 )
51 })
52 } else {
53 Err(crate::types::error::Error::UnexpectedResponse(resp))
54 }
55 }
56
57 #[doc = "Get event\n\nFetch an event.\n> ⚠\u{fe0f} Deprecated field may be included\n>\n> This \
58 route return the deprecated `last_message` conversation field for conversations\n> \
59 associated with individual events. Please use the conversation's\n> \
60 `_links.related.last_message` field instead.\n\n\n**Parameters:**\n\n- `event_id: \
61 &'astr`: The event ID (required)\n\n```rust,no_run\nasync fn example_events_get() -> \
62 anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let \
63 result: front_api::types::EventResponse = \
64 client.events().get(\"some-string\").await?;\n println!(\"{:?}\", result);\n \
65 Ok(())\n}\n```"]
66 #[tracing::instrument]
67 pub async fn get<'a>(
68 &'a self,
69 event_id: &'a str,
70 ) -> Result<crate::types::EventResponse, crate::types::error::Error> {
71 let mut req = self.client.client.request(
72 http::Method::GET,
73 &format!(
74 "{}/{}",
75 self.client.base_url,
76 "events/{event_id}".replace("{event_id}", event_id)
77 ),
78 );
79 req = req.bearer_auth(&self.client.token);
80 let resp = req.send().await?;
81 let status = resp.status();
82 if status.is_success() {
83 let text = resp.text().await.unwrap_or_default();
84 serde_json::from_str(&text).map_err(|err| {
85 crate::types::error::Error::from_serde_error(
86 format_serde_error::SerdeError::new(text.to_string(), err),
87 status,
88 )
89 })
90 } else {
91 Err(crate::types::error::Error::UnexpectedResponse(resp))
92 }
93 }
94}