files_sdk/logs/
email_logs.rs1use crate::{FilesClient, PaginationInfo, Result};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Serialize, Deserialize, Clone)]
7pub struct EmailLogEntity {
8 #[serde(flatten)]
9 pub data: serde_json::Map<String, serde_json::Value>,
10}
11
12#[derive(Debug, Clone)]
13pub struct EmailLogHandler {
14 client: FilesClient,
15}
16
17impl EmailLogHandler {
18 pub fn new(client: FilesClient) -> Self {
19 Self { client }
20 }
21
22 pub async fn list(
23 &self,
24 cursor: Option<String>,
25 per_page: Option<i64>,
26 ) -> Result<(Vec<EmailLogEntity>, PaginationInfo)> {
27 let mut endpoint = "/email_logs".to_string();
28 let mut params = Vec::new();
29
30 if let Some(c) = cursor {
31 params.push(format!("cursor={}", c));
32 }
33 if let Some(pp) = per_page {
34 params.push(format!("per_page={}", pp));
35 }
36
37 if !params.is_empty() {
38 endpoint.push('?');
39 endpoint.push_str(¶ms.join("&"));
40 }
41
42 let url = format!("{}{}", self.client.inner.base_url, endpoint);
43 let response = reqwest::Client::new()
44 .get(&url)
45 .header("X-FilesAPI-Key", &self.client.inner.api_key)
46 .send()
47 .await?;
48
49 let headers = response.headers().clone();
50 let pagination = PaginationInfo::from_headers(&headers);
51 let status = response.status();
52
53 if !status.is_success() {
54 return Err(crate::FilesError::ApiError {
55 endpoint: None,
56 code: status.as_u16(),
57 message: response.text().await.unwrap_or_default(),
58 });
59 }
60
61 let logs: Vec<EmailLogEntity> = response.json().await?;
62 Ok((logs, pagination))
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_handler_creation() {
72 let client = FilesClient::builder().api_key("test-key").build().unwrap();
73 let _handler = EmailLogHandler::new(client);
74 }
75}