manticore_openapi/apis/
index_api.rs1use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum BulkError {
20 DefaultResponse(models::ErrorResponse),
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum DeleteError {
28 DefaultResponse(models::ErrorResponse),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum InsertError {
36 DefaultResponse(models::ErrorResponse),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ReplaceError {
44 DefaultResponse(models::ErrorResponse),
45 UnknownValue(serde_json::Value),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum UpdateError {
52 DefaultResponse(models::ErrorResponse),
53 UnknownValue(serde_json::Value),
54}
55
56pub async fn bulk(
58 configuration: &configuration::Configuration,
59 body: &str,
60) -> Result<models::BulkResponse, Error<BulkError>> {
61 let local_var_configuration = configuration;
62
63 let local_var_client = &local_var_configuration.client;
64
65 let local_var_uri_str = format!("{}/bulk", local_var_configuration.base_path);
66 let mut local_var_req_builder =
67 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
68
69 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
70 local_var_req_builder =
71 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
72 }
73 local_var_req_builder = local_var_req_builder.json(&body);
74
75 let local_var_req = local_var_req_builder.build()?;
76 let local_var_resp = local_var_client.execute(local_var_req).await?;
77
78 let local_var_status = local_var_resp.status();
79 let local_var_content = local_var_resp.text().await?;
80
81 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
82 serde_json::from_str(&local_var_content).map_err(Error::from)
83 } else {
84 let local_var_entity: Option<BulkError> = serde_json::from_str(&local_var_content).ok();
85 let local_var_error = ResponseContent {
86 status: local_var_status,
87 content: local_var_content,
88 entity: local_var_entity,
89 };
90 Err(Error::ResponseError(local_var_error))
91 }
92}
93
94pub async fn delete(
96 configuration: &configuration::Configuration,
97 delete_document_request: models::DeleteDocumentRequest,
98) -> Result<models::DeleteResponse, Error<DeleteError>> {
99 let local_var_configuration = configuration;
100
101 let local_var_client = &local_var_configuration.client;
102
103 let local_var_uri_str = format!("{}/delete", local_var_configuration.base_path);
104 let mut local_var_req_builder =
105 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
106
107 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
108 local_var_req_builder =
109 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110 }
111 local_var_req_builder = local_var_req_builder.json(&delete_document_request);
112
113 let local_var_req = local_var_req_builder.build()?;
114 let local_var_resp = local_var_client.execute(local_var_req).await?;
115
116 let local_var_status = local_var_resp.status();
117 let local_var_content = local_var_resp.text().await?;
118
119 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
120 serde_json::from_str(&local_var_content).map_err(Error::from)
121 } else {
122 let local_var_entity: Option<DeleteError> = serde_json::from_str(&local_var_content).ok();
123 let local_var_error = ResponseContent {
124 status: local_var_status,
125 content: local_var_content,
126 entity: local_var_entity,
127 };
128 Err(Error::ResponseError(local_var_error))
129 }
130}
131
132pub async fn insert(
134 configuration: &configuration::Configuration,
135 insert_document_request: models::InsertDocumentRequest,
136) -> Result<models::SuccessResponse, Error<InsertError>> {
137 let local_var_configuration = configuration;
138
139 let local_var_client = &local_var_configuration.client;
140
141 let local_var_uri_str = format!("{}/insert", local_var_configuration.base_path);
142 let mut local_var_req_builder =
143 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
144
145 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146 local_var_req_builder =
147 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
148 }
149 println!(
150 "request = {}",
151 serde_json::to_string(&insert_document_request)?
152 );
153 local_var_req_builder = local_var_req_builder.json(&insert_document_request);
154
155 let local_var_req = local_var_req_builder.build()?;
156 let local_var_resp = local_var_client.execute(local_var_req).await?;
157
158 let local_var_status = local_var_resp.status();
159 let local_var_content = local_var_resp.text().await?;
160 println!("response = {}", local_var_content);
161
162 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
163 serde_json::from_str(&local_var_content).map_err(Error::from)
164 } else {
165 let local_var_entity: Option<InsertError> = serde_json::from_str(&local_var_content).ok();
166 let local_var_error = ResponseContent {
167 status: local_var_status,
168 content: local_var_content,
169 entity: local_var_entity,
170 };
171 Err(Error::ResponseError(local_var_error))
172 }
173}
174
175pub async fn replace(
177 configuration: &configuration::Configuration,
178 insert_document_request: models::InsertDocumentRequest,
179) -> Result<models::SuccessResponse, Error<ReplaceError>> {
180 let local_var_configuration = configuration;
181
182 let local_var_client = &local_var_configuration.client;
183
184 let local_var_uri_str = format!("{}/replace", local_var_configuration.base_path);
185 let mut local_var_req_builder =
186 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
187
188 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
189 local_var_req_builder =
190 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
191 }
192 local_var_req_builder = local_var_req_builder.json(&insert_document_request);
193
194 let local_var_req = local_var_req_builder.build()?;
195 let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197 let local_var_status = local_var_resp.status();
198 let local_var_content = local_var_resp.text().await?;
199
200 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201 serde_json::from_str(&local_var_content).map_err(Error::from)
202 } else {
203 let local_var_entity: Option<ReplaceError> = serde_json::from_str(&local_var_content).ok();
204 let local_var_error = ResponseContent {
205 status: local_var_status,
206 content: local_var_content,
207 entity: local_var_entity,
208 };
209 Err(Error::ResponseError(local_var_error))
210 }
211}
212
213pub async fn update(
215 configuration: &configuration::Configuration,
216 update_document_request: models::UpdateDocumentRequest,
217) -> Result<models::UpdateResponse, Error<UpdateError>> {
218 let local_var_configuration = configuration;
219
220 let local_var_client = &local_var_configuration.client;
221
222 let local_var_uri_str = format!("{}/update", local_var_configuration.base_path);
223 let mut local_var_req_builder =
224 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
225
226 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
227 local_var_req_builder =
228 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
229 }
230 local_var_req_builder = local_var_req_builder.json(&update_document_request);
231
232 let local_var_req = local_var_req_builder.build()?;
233 let local_var_resp = local_var_client.execute(local_var_req).await?;
234
235 let local_var_status = local_var_resp.status();
236 let local_var_content = local_var_resp.text().await?;
237
238 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
239 serde_json::from_str(&local_var_content).map_err(Error::from)
240 } else {
241 let local_var_entity: Option<UpdateError> = serde_json::from_str(&local_var_content).ok();
242 let local_var_error = ResponseContent {
243 status: local_var_status,
244 content: local_var_content,
245 entity: local_var_entity,
246 };
247 Err(Error::ResponseError(local_var_error))
248 }
249}