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