files_sdk/users/
user_sftp_client_uses.rs

1//! User SFTP Client Uses Handler
2//!
3//! Track SFTP client usage by users.
4
5use crate::{FilesClient, PaginationInfo, Result};
6use serde::{Deserialize, Serialize};
7
8/// Represents a user's SFTP client usage
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct UserSftpClientUseEntity {
11    /// UserSftpClientUse ID
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub id: Option<i64>,
14
15    /// The SFTP client used
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub sftp_client: Option<String>,
18
19    /// The earliest recorded use of this SFTP client (for this user)
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub created_at: Option<String>,
22
23    /// The most recent use of this SFTP client (for this user)
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub updated_at: Option<String>,
26
27    /// ID of the user who performed this access
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub user_id: Option<i64>,
30}
31
32/// Handler for User SFTP Client Use operations
33pub struct UserSftpClientUseHandler {
34    client: FilesClient,
35}
36
37impl UserSftpClientUseHandler {
38    /// Creates a new UserSftpClientUseHandler
39    ///
40    /// # Example
41    /// ```no_run
42    /// # use files_sdk::{FilesClient, UserSftpClientUseHandler};
43    /// let client = FilesClient::builder().api_key("key").build().unwrap();
44    /// let handler = UserSftpClientUseHandler::new(client);
45    /// ```
46    pub fn new(client: FilesClient) -> Self {
47        Self { client }
48    }
49
50    /// List User SFTP Client Uses
51    ///
52    /// # Arguments
53    /// * `user_id` - Optional user ID to filter by
54    /// * `cursor` - Pagination cursor
55    /// * `per_page` - Number of records per page
56    ///
57    /// # Example
58    /// ```no_run
59    /// # use files_sdk::{FilesClient, UserSftpClientUseHandler};
60    /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
61    /// let client = FilesClient::builder().api_key("key").build()?;
62    /// let handler = UserSftpClientUseHandler::new(client);
63    ///
64    /// let (uses, pagination) = handler.list(None, None, Some(100)).await?;
65    /// # Ok(())
66    /// # }
67    /// ```
68    pub async fn list(
69        &self,
70        user_id: Option<i64>,
71        cursor: Option<String>,
72        per_page: Option<i32>,
73    ) -> Result<(Vec<UserSftpClientUseEntity>, PaginationInfo)> {
74        let mut endpoint = "/user_sftp_client_uses".to_string();
75        let mut query_params = Vec::new();
76
77        if let Some(user_id) = user_id {
78            query_params.push(format!("user_id={}", user_id));
79        }
80
81        if let Some(cursor) = cursor {
82            query_params.push(format!("cursor={}", cursor));
83        }
84
85        if let Some(per_page) = per_page {
86            query_params.push(format!("per_page={}", per_page));
87        }
88
89        if !query_params.is_empty() {
90            endpoint.push('?');
91            endpoint.push_str(&query_params.join("&"));
92        }
93
94        let response = self.client.get_raw(&endpoint).await?;
95        let items: Vec<UserSftpClientUseEntity> = serde_json::from_value(response)?;
96
97        // TODO: Extract pagination from response headers
98        let pagination = PaginationInfo {
99            cursor_next: None,
100            cursor_prev: None,
101        };
102
103        Ok((items, pagination))
104    }
105}
106
107#[cfg(test)]
108mod tests {
109    use super::*;
110
111    #[test]
112    fn test_handler_creation() {
113        let client = FilesClient::builder()
114            .api_key("test-key")
115            .build()
116            .expect("Client build failed");
117        let _handler = UserSftpClientUseHandler::new(client);
118    }
119}