files_sdk/sharing/
bundle_notifications.rs1use crate::{FilesClient, PaginationInfo, Result};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Serialize, Deserialize, Clone)]
7pub struct BundleNotificationEntity {
8 pub id: Option<i64>,
9 #[serde(flatten)]
10 pub data: serde_json::Map<String, serde_json::Value>,
11}
12
13#[derive(Debug, Clone)]
14pub struct BundleNotificationHandler {
15 client: FilesClient,
16}
17
18impl BundleNotificationHandler {
19 pub fn new(client: FilesClient) -> Self {
20 Self { client }
21 }
22
23 pub async fn list(
24 &self,
25 cursor: Option<String>,
26 per_page: Option<i64>,
27 ) -> Result<(Vec<BundleNotificationEntity>, PaginationInfo)> {
28 let mut endpoint = "/bundle_notifications".to_string();
29 let mut params = Vec::new();
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 if !params.is_empty() {
37 endpoint.push('?');
38 endpoint.push_str(¶ms.join("&"));
39 }
40
41 let url = format!("{}{}", self.client.inner.base_url, endpoint);
42 let response = reqwest::Client::new()
43 .get(&url)
44 .header("X-FilesAPI-Key", &self.client.inner.api_key)
45 .send()
46 .await?;
47
48 let headers = response.headers().clone();
49 let pagination = PaginationInfo::from_headers(&headers);
50 let status = response.status();
51 if !status.is_success() {
52 return Err(crate::FilesError::ApiError {
53 endpoint: None,
54 code: status.as_u16(),
55 message: response.text().await.unwrap_or_default(),
56 });
57 }
58 let items: Vec<BundleNotificationEntity> = response.json().await?;
59 Ok((items, pagination))
60 }
61
62 pub async fn get(&self, id: i64) -> Result<BundleNotificationEntity> {
63 let endpoint = format!("/bundle_notifications/{}", id);
64 let response = self.client.get_raw(&endpoint).await?;
65 Ok(serde_json::from_value(response)?)
66 }
67
68 pub async fn create(&self, params: serde_json::Value) -> Result<BundleNotificationEntity> {
69 let response = self
70 .client
71 .post_raw("/bundle_notifications", params)
72 .await?;
73 Ok(serde_json::from_value(response)?)
74 }
75
76 pub async fn update(
77 &self,
78 id: i64,
79 params: serde_json::Value,
80 ) -> Result<BundleNotificationEntity> {
81 let endpoint = format!("/bundle_notifications/{}", id);
82 let response = self.client.patch_raw(&endpoint, params).await?;
83 Ok(serde_json::from_value(response)?)
84 }
85
86 pub async fn delete(&self, id: i64) -> Result<()> {
87 let endpoint = format!("/bundle_notifications/{}", id);
88 self.client.delete_raw(&endpoint).await?;
89 Ok(())
90 }
91}
92
93#[cfg(test)]
94mod tests {
95 use super::*;
96 #[test]
97 fn test_handler_creation() {
98 let client = FilesClient::builder().api_key("test-key").build().unwrap();
99 let _handler = BundleNotificationHandler::new(client);
100 }
101}