files_sdk/automation/
remote_mount_backends.rs1use crate::{Result, client::FilesClient, types::PaginationInfo};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize, Clone)]
5pub struct RemoteMountBackendEntity {
6 #[serde(flatten)]
7 pub data: serde_json::Map<String, serde_json::Value>,
8}
9
10pub struct RemoteMountBackendHandler {
11 client: FilesClient,
12}
13
14impl RemoteMountBackendHandler {
15 pub fn new(client: FilesClient) -> Self {
16 Self { client }
17 }
18
19 pub async fn list(
20 &self,
21 cursor: Option<String>,
22 per_page: Option<i64>,
23 ) -> Result<(Vec<RemoteMountBackendEntity>, PaginationInfo)> {
24 let mut endpoint = "/remote_mount_backends".to_string();
25 let mut query_params = Vec::new();
26
27 if let Some(cursor) = cursor {
28 query_params.push(format!("cursor={}", cursor));
29 }
30
31 if let Some(per_page) = per_page {
32 query_params.push(format!("per_page={}", per_page));
33 }
34
35 if !query_params.is_empty() {
36 endpoint.push('?');
37 endpoint.push_str(&query_params.join("&"));
38 }
39
40 let url = format!("{}{}", self.client.inner.base_url, endpoint);
41 let response = reqwest::Client::new()
42 .get(&url)
43 .header("X-FilesAPI-Key", &self.client.inner.api_key)
44 .send()
45 .await?;
46
47 let headers = response.headers().clone();
48 let pagination = PaginationInfo::from_headers(&headers);
49
50 let status = response.status();
51 if !status.is_success() {
52 return Err(crate::FilesError::ApiError {
53 code: status.as_u16(),
54 message: response.text().await.unwrap_or_default(),
55 });
56 }
57
58 let entities: Vec<RemoteMountBackendEntity> = response.json().await?;
59 Ok((entities, pagination))
60 }
61
62 pub async fn get(&self, id: i64) -> Result<RemoteMountBackendEntity> {
63 let endpoint = format!("/remote_mount_backends/{}", 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<RemoteMountBackendEntity> {
69 let response = self
70 .client
71 .post_raw("/remote_mount_backends", 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<RemoteMountBackendEntity> {
81 let endpoint = format!("/remote_mount_backends/{}", 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!("/remote_mount_backends/{}", id);
88 self.client.delete_raw(&endpoint).await?;
89 Ok(())
90 }
91
92 pub async fn test_configuration(
93 &self,
94 id: i64,
95 params: serde_json::Value,
96 ) -> Result<RemoteMountBackendEntity> {
97 let endpoint = format!("/remote_mount_backends/{}/test_configuration", id);
98 let response = self.client.post_raw(&endpoint, params).await?;
99 Ok(serde_json::from_value(response)?)
100 }
101}