files_sdk/sharing/
inbox_uploads.rs

1//! Inbox Upload operations
2//!
3//! InboxUpload is a log record about upload operations that happened in an Inbox.
4
5use crate::{FilesClient, PaginationInfo, Result};
6use serde::{Deserialize, Serialize};
7
8/// An Inbox Registration entity (embedded in InboxUpload)
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct InboxRegistrationEntity {
11    /// Registration code
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub code: Option<String>,
14
15    /// Registrant name
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub name: Option<String>,
18
19    /// Registrant company
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub company: Option<String>,
22
23    /// Registrant email
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub email: Option<String>,
26
27    /// Registrant IP address
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub ip: Option<String>,
30
31    /// Clickwrap agreement body
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub clickwrap_body: Option<String>,
34
35    /// Form field set ID
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub form_field_set_id: Option<i64>,
38
39    /// Form field data
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub form_field_data: Option<serde_json::Value>,
42
43    /// Inbox ID
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub inbox_id: Option<i64>,
46
47    /// Inbox recipient ID
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub inbox_recipient_id: Option<i64>,
50
51    /// Inbox title
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub inbox_title: Option<String>,
54
55    /// Registration creation time
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub created_at: Option<String>,
58}
59
60/// An Inbox Upload entity
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct InboxUploadEntity {
63    /// Inbox registration details
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub inbox_registration: Option<InboxRegistrationEntity>,
66
67    /// Upload path
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub path: Option<String>,
70
71    /// Upload date/time
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub created_at: Option<String>,
74}
75
76/// Handler for inbox upload operations
77pub struct InboxUploadHandler {
78    client: FilesClient,
79}
80
81impl InboxUploadHandler {
82    /// Create a new inbox upload handler
83    pub fn new(client: FilesClient) -> Self {
84        Self { client }
85    }
86
87    /// List inbox uploads
88    ///
89    /// # Arguments
90    /// * `cursor` - Pagination cursor
91    /// * `per_page` - Results per page
92    /// * `sort_by` - Sort field and direction (e.g., `{"created_at": "desc"}`)
93    /// * `filter` - Filter criteria (e.g., `{"folder_behavior_id": 123}`)
94    /// * `inbox_registration_id` - Filter by inbox registration ID
95    /// * `inbox_id` - Filter by inbox ID
96    ///
97    /// # Returns
98    /// Tuple of (inbox_uploads, pagination_info)
99    ///
100    /// # Example
101    /// ```no_run
102    /// use files_sdk::{FilesClient, InboxUploadHandler};
103    ///
104    /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
105    /// let client = FilesClient::builder().api_key("key").build()?;
106    /// let handler = InboxUploadHandler::new(client);
107    /// let (uploads, _) = handler.list(None, None, None, None, None, None).await?;
108    /// # Ok(())
109    /// # }
110    /// ```
111    #[allow(clippy::too_many_arguments)]
112    pub async fn list(
113        &self,
114        cursor: Option<&str>,
115        per_page: Option<i64>,
116        sort_by: Option<serde_json::Value>,
117        filter: Option<serde_json::Value>,
118        inbox_registration_id: Option<i64>,
119        inbox_id: Option<i64>,
120    ) -> Result<(Vec<InboxUploadEntity>, PaginationInfo)> {
121        let mut params = vec![];
122        if let Some(c) = cursor {
123            params.push(("cursor", c.to_string()));
124        }
125        if let Some(pp) = per_page {
126            params.push(("per_page", pp.to_string()));
127        }
128        if let Some(sb) = sort_by {
129            params.push(("sort_by", sb.to_string()));
130        }
131        if let Some(f) = filter {
132            params.push(("filter", f.to_string()));
133        }
134        if let Some(irid) = inbox_registration_id {
135            params.push(("inbox_registration_id", irid.to_string()));
136        }
137        if let Some(iid) = inbox_id {
138            params.push(("inbox_id", iid.to_string()));
139        }
140
141        let query = if params.is_empty() {
142            String::new()
143        } else {
144            format!(
145                "?{}",
146                params
147                    .iter()
148                    .map(|(k, v)| format!("{}={}", k, v))
149                    .collect::<Vec<_>>()
150                    .join("&")
151            )
152        };
153
154        let response = self
155            .client
156            .get_raw(&format!("/inbox_uploads{}", query))
157            .await?;
158        let uploads: Vec<InboxUploadEntity> = serde_json::from_value(response)?;
159
160        let pagination = PaginationInfo {
161            cursor_next: None,
162            cursor_prev: None,
163        };
164
165        Ok((uploads, pagination))
166    }
167}
168
169#[cfg(test)]
170mod tests {
171    use super::*;
172
173    #[test]
174    fn test_handler_creation() {
175        let client = FilesClient::builder().api_key("test-key").build().unwrap();
176        let _handler = InboxUploadHandler::new(client);
177    }
178}