files_sdk/security/
ip_addresses.rs1use crate::{Result, client::FilesClient, types::PaginationInfo};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize, Clone)]
5pub struct IpAddressEntity {
6 #[serde(flatten)]
7 pub data: serde_json::Map<String, serde_json::Value>,
8}
9
10pub struct IpAddressHandler {
11 client: FilesClient,
12}
13
14impl IpAddressHandler {
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<IpAddressEntity>, PaginationInfo)> {
24 let mut endpoint = "/ip_addresses".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<IpAddressEntity> = response.json().await?;
59 Ok((entities, pagination))
60 }
61
62 pub async fn get_reserved(&self) -> Result<Vec<IpAddressEntity>> {
63 let response = self.client.get_raw("/ip_addresses/reserved").await?;
64 Ok(serde_json::from_value(response)?)
65 }
66
67 pub async fn get_exavault_reserved(&self) -> Result<Vec<IpAddressEntity>> {
68 let response = self
69 .client
70 .get_raw("/ip_addresses/exavault-reserved")
71 .await?;
72 Ok(serde_json::from_value(response)?)
73 }
74
75 pub async fn get_smartfile_reserved(&self) -> Result<Vec<IpAddressEntity>> {
76 let response = self
77 .client
78 .get_raw("/ip_addresses/smartfile-reserved")
79 .await?;
80 Ok(serde_json::from_value(response)?)
81 }
82}