box_open_sdk/managers/
shield_lists.rs1use crate::internal::path_escape;
4use crate::runtime::{self, Error};
5
6pub struct ShieldListsManager {
8 session: std::sync::Arc<runtime::Client>,
9}
10
11impl ShieldListsManager {
12 pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
13 Self { session }
14 }
15
16 pub async fn list(&self) -> Result<crate::models::schemas::ShieldLists, Error> {
17 let mut url = self.session.base_url("api");
18 url.push_str("/shield_lists");
19 let mut req = self.session.new_request("GET", &url);
20 req = runtime::with_header(req, "box-version", "2025.0");
21 let resp = self.session.fetch(req).await?;
22 let data = runtime::response_bytes(&resp)?;
23 Ok(serde_json::from_slice(&data)?)
24 }
25
26 pub async fn create(
27 &self,
28 body: crate::models::schemas::ShieldListsCreate,
29 ) -> Result<crate::models::schemas::ShieldList, Error> {
30 let mut url = self.session.base_url("api");
31 url.push_str("/shield_lists");
32 let mut req = self.session.new_request("POST", &url);
33 req = runtime::with_header(req, "box-version", "2025.0");
34 let payload = serde_json::to_vec(&body)?;
35 req = runtime::with_json_body(req, &payload);
36 let resp = self.session.fetch(req).await?;
37 let data = runtime::response_bytes(&resp)?;
38 Ok(serde_json::from_slice(&data)?)
39 }
40
41 pub async fn get(
42 &self,
43 shield_list_id: String,
44 ) -> Result<crate::models::schemas::ShieldList, Error> {
45 let mut url = self.session.base_url("api");
46 url.push_str("/shield_lists");
47 url.push('/');
48 let seg = path_escape(&shield_list_id);
49 url.push_str(&seg);
50 let mut req = self.session.new_request("GET", &url);
51 req = runtime::with_header(req, "box-version", "2025.0");
52 let resp = self.session.fetch(req).await?;
53 let data = runtime::response_bytes(&resp)?;
54 Ok(serde_json::from_slice(&data)?)
55 }
56
57 pub async fn update(
58 &self,
59 shield_list_id: String,
60 body: crate::models::schemas::ShieldListsUpdate,
61 ) -> Result<crate::models::schemas::ShieldList, Error> {
62 let mut url = self.session.base_url("api");
63 url.push_str("/shield_lists");
64 url.push('/');
65 let seg = path_escape(&shield_list_id);
66 url.push_str(&seg);
67 let mut req = self.session.new_request("PUT", &url);
68 req = runtime::with_header(req, "box-version", "2025.0");
69 let payload = serde_json::to_vec(&body)?;
70 req = runtime::with_json_body(req, &payload);
71 let resp = self.session.fetch(req).await?;
72 let data = runtime::response_bytes(&resp)?;
73 Ok(serde_json::from_slice(&data)?)
74 }
75
76 pub async fn delete(&self, shield_list_id: String) -> Result<(), Error> {
77 let mut url = self.session.base_url("api");
78 url.push_str("/shield_lists");
79 url.push('/');
80 let seg = path_escape(&shield_list_id);
81 url.push_str(&seg);
82 let mut req = self.session.new_request("DELETE", &url);
83 req = runtime::with_header(req, "box-version", "2025.0");
84 let _ = self.session.fetch(req).await?;
85 Ok(())
86 }
87}