Skip to main content

box_open_sdk/managers/
search.rs

1// Code generated by box-gantry. DO NOT EDIT.
2
3use crate::runtime::{self, Error};
4
5/// Optional parameters for [`SearchManager::get`].
6#[derive(Clone, Debug, Default)]
7pub struct SearchGetOptions {
8    pub query: Option<String>,
9    pub scope: Option<crate::models::schemas::GetScope>,
10    pub file_extensions: Option<Vec<String>>,
11    pub created_at_range: Option<Vec<String>>,
12    pub updated_at_range: Option<Vec<String>>,
13    pub size_range: Option<Vec<i64>>,
14    pub owner_user_ids: Option<Vec<String>>,
15    pub recent_updater_user_ids: Option<Vec<String>>,
16    pub ancestor_folder_ids: Option<Vec<String>>,
17    pub content_types: Option<Vec<crate::models::schemas::GetContentTypes>>,
18    pub r#type: Option<crate::models::schemas::GetType>,
19    pub trash_content: Option<crate::models::schemas::GetTrashContent>,
20    pub mdfilters: Option<Vec<crate::models::schemas::MetadataFilter>>,
21    pub sort: Option<crate::models::schemas::GetSort>,
22    pub direction: Option<crate::models::schemas::GetDirection>,
23    pub limit: Option<i64>,
24    pub include_recent_shared_links: Option<bool>,
25    pub fields: Option<Vec<String>>,
26    pub offset: Option<i64>,
27    pub deleted_user_ids: Option<Vec<String>>,
28    pub deleted_at_range: Option<Vec<String>>,
29}
30
31/// Operations for the "search" API area.
32pub struct SearchManager {
33    session: std::sync::Arc<runtime::Client>,
34}
35
36impl SearchManager {
37    pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
38        Self { session }
39    }
40
41    pub async fn query_by_metadata(
42        &self,
43        body: crate::models::schemas::MetadataQuery,
44    ) -> Result<crate::models::schemas::MetadataQueryResults, Error> {
45        let mut url = self.session.base_url("api");
46        url.push_str("/metadata_queries");
47        url.push_str("/execute_read");
48        let mut req = self.session.new_request("POST", &url);
49        let payload = serde_json::to_vec(&body)?;
50        req = runtime::with_json_body(req, &payload);
51        let resp = self.session.fetch(req).await?;
52        let data = runtime::response_bytes(&resp)?;
53        Ok(serde_json::from_slice(&data)?)
54    }
55
56    pub async fn get(
57        &self,
58        opts: Option<SearchGetOptions>,
59    ) -> Result<crate::models::schemas::SearchResultsResponse, Error> {
60        let mut url = self.session.base_url("api");
61        url.push_str("/search");
62        let mut req = self.session.new_request("GET", &url);
63        let opts = opts.unwrap_or_default();
64        if let Some(value) = opts.query {
65            req = runtime::with_query(req, "query", &value);
66        }
67        if let Some(value) = opts.scope {
68            req = runtime::with_query(req, "scope", &value.0);
69        }
70        if let Some(value) = opts.file_extensions {
71            req = runtime::with_query(req, "file_extensions", &value.join(","));
72        }
73        if let Some(value) = opts.created_at_range {
74            req = runtime::with_query(req, "created_at_range", &value.join(","));
75        }
76        if let Some(value) = opts.updated_at_range {
77            req = runtime::with_query(req, "updated_at_range", &value.join(","));
78        }
79        if let Some(value) = opts.size_range {
80            let arg = crate::internal::join(&value, |v| v.to_string());
81            req = runtime::with_query(req, "size_range", &arg);
82        }
83        if let Some(value) = opts.owner_user_ids {
84            req = runtime::with_query(req, "owner_user_ids", &value.join(","));
85        }
86        if let Some(value) = opts.recent_updater_user_ids {
87            req = runtime::with_query(req, "recent_updater_user_ids", &value.join(","));
88        }
89        if let Some(value) = opts.ancestor_folder_ids {
90            req = runtime::with_query(req, "ancestor_folder_ids", &value.join(","));
91        }
92        if let Some(value) = opts.content_types {
93            let arg = crate::internal::join(&value, |v| v.0.clone());
94            req = runtime::with_query(req, "content_types", &arg);
95        }
96        if let Some(value) = opts.r#type {
97            req = runtime::with_query(req, "type", &value.0);
98        }
99        if let Some(value) = opts.trash_content {
100            req = runtime::with_query(req, "trash_content", &value.0);
101        }
102        if let Some(value) = opts.mdfilters {
103            let arg = serde_json::to_string(&value).unwrap_or_default();
104            req = runtime::with_query(req, "mdfilters", &arg);
105        }
106        if let Some(value) = opts.sort {
107            req = runtime::with_query(req, "sort", &value.0);
108        }
109        if let Some(value) = opts.direction {
110            req = runtime::with_query(req, "direction", &value.0);
111        }
112        if let Some(value) = opts.limit {
113            req = runtime::with_query(req, "limit", &value.to_string());
114        }
115        if let Some(value) = opts.include_recent_shared_links {
116            req = runtime::with_query(req, "include_recent_shared_links", &value.to_string());
117        }
118        if let Some(value) = opts.fields {
119            req = runtime::with_query(req, "fields", &value.join(","));
120        }
121        if let Some(value) = opts.offset {
122            req = runtime::with_query(req, "offset", &value.to_string());
123        }
124        if let Some(value) = opts.deleted_user_ids {
125            req = runtime::with_query(req, "deleted_user_ids", &value.join(","));
126        }
127        if let Some(value) = opts.deleted_at_range {
128            req = runtime::with_query(req, "deleted_at_range", &value.join(","));
129        }
130        let resp = self.session.fetch(req).await?;
131        let data = runtime::response_bytes(&resp)?;
132        Ok(serde_json::from_slice(&data)?)
133    }
134}