1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateRecordError {
22 Status401(models::ApiError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum CreateRecordTypeError {
30 Status401(models::ApiError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum DeleteRecordError {
38 Status401(models::ApiError),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetRecordError {
46 Status401(models::ApiError),
47 Status404(models::ApiError),
48 UnknownValue(serde_json::Value),
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum ListRecordTypesError {
55 Status400(models::ApiError),
56 Status401(models::ApiError),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ListRecordsError {
64 Status400(models::ApiError),
65 Status401(models::ApiError),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum UpdateRecordError {
73 Status401(models::ApiError),
74 UnknownValue(serde_json::Value),
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum UpdateRecordTypeError {
81 Status401(models::ApiError),
82 UnknownValue(serde_json::Value),
83}
84
85
86pub async fn create_record(configuration: &configuration::Configuration, create_record_request: models::CreateRecordRequest) -> Result<models::Record, Error<CreateRecordError>> {
87 let p_body_create_record_request = create_record_request;
89
90 let uri_str = format!("{}/v1/records", configuration.base_path);
91 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
92
93 if let Some(ref user_agent) = configuration.user_agent {
94 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95 }
96 if let Some(ref token) = configuration.bearer_access_token {
97 req_builder = req_builder.bearer_auth(token.to_owned());
98 };
99 req_builder = req_builder.json(&p_body_create_record_request);
100
101 let req = req_builder.build()?;
102 let resp = configuration.client.execute(req).await?;
103
104 let status = resp.status();
105 let content_type = resp
106 .headers()
107 .get("content-type")
108 .and_then(|v| v.to_str().ok())
109 .unwrap_or("application/octet-stream");
110 let content_type = super::ContentType::from(content_type);
111
112 if !status.is_client_error() && !status.is_server_error() {
113 let content = resp.text().await?;
114 match content_type {
115 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
116 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Record`"))),
117 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Record`")))),
118 }
119 } else {
120 let content = resp.text().await?;
121 let entity: Option<CreateRecordError> = serde_json::from_str(&content).ok();
122 Err(Error::ResponseError(ResponseContent { status, content, entity }))
123 }
124}
125
126pub async fn create_record_type(configuration: &configuration::Configuration, create_record_type_request: models::CreateRecordTypeRequest) -> Result<models::RecordType, Error<CreateRecordTypeError>> {
127 let p_body_create_record_type_request = create_record_type_request;
129
130 let uri_str = format!("{}/v1/records/types", configuration.base_path);
131 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
132
133 if let Some(ref user_agent) = configuration.user_agent {
134 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
135 }
136 if let Some(ref token) = configuration.bearer_access_token {
137 req_builder = req_builder.bearer_auth(token.to_owned());
138 };
139 req_builder = req_builder.json(&p_body_create_record_type_request);
140
141 let req = req_builder.build()?;
142 let resp = configuration.client.execute(req).await?;
143
144 let status = resp.status();
145 let content_type = resp
146 .headers()
147 .get("content-type")
148 .and_then(|v| v.to_str().ok())
149 .unwrap_or("application/octet-stream");
150 let content_type = super::ContentType::from(content_type);
151
152 if !status.is_client_error() && !status.is_server_error() {
153 let content = resp.text().await?;
154 match content_type {
155 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
156 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecordType`"))),
157 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RecordType`")))),
158 }
159 } else {
160 let content = resp.text().await?;
161 let entity: Option<CreateRecordTypeError> = serde_json::from_str(&content).ok();
162 Err(Error::ResponseError(ResponseContent { status, content, entity }))
163 }
164}
165
166pub async fn delete_record(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteRecordError>> {
167 let p_path_id = id;
169
170 let uri_str = format!("{}/v1/records/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
171 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
172
173 if let Some(ref user_agent) = configuration.user_agent {
174 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
175 }
176 if let Some(ref token) = configuration.bearer_access_token {
177 req_builder = req_builder.bearer_auth(token.to_owned());
178 };
179
180 let req = req_builder.build()?;
181 let resp = configuration.client.execute(req).await?;
182
183 let status = resp.status();
184
185 if !status.is_client_error() && !status.is_server_error() {
186 Ok(())
187 } else {
188 let content = resp.text().await?;
189 let entity: Option<DeleteRecordError> = serde_json::from_str(&content).ok();
190 Err(Error::ResponseError(ResponseContent { status, content, entity }))
191 }
192}
193
194pub async fn get_record(configuration: &configuration::Configuration, id: &str) -> Result<models::Record, Error<GetRecordError>> {
195 let p_path_id = id;
197
198 let uri_str = format!("{}/v1/records/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
199 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
200
201 if let Some(ref user_agent) = configuration.user_agent {
202 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
203 }
204 if let Some(ref token) = configuration.bearer_access_token {
205 req_builder = req_builder.bearer_auth(token.to_owned());
206 };
207
208 let req = req_builder.build()?;
209 let resp = configuration.client.execute(req).await?;
210
211 let status = resp.status();
212 let content_type = resp
213 .headers()
214 .get("content-type")
215 .and_then(|v| v.to_str().ok())
216 .unwrap_or("application/octet-stream");
217 let content_type = super::ContentType::from(content_type);
218
219 if !status.is_client_error() && !status.is_server_error() {
220 let content = resp.text().await?;
221 match content_type {
222 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
223 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Record`"))),
224 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Record`")))),
225 }
226 } else {
227 let content = resp.text().await?;
228 let entity: Option<GetRecordError> = serde_json::from_str(&content).ok();
229 Err(Error::ResponseError(ResponseContent { status, content, entity }))
230 }
231}
232
233pub async fn list_record_types(configuration: &configuration::Configuration, organization_id: &str) -> Result<models::RecordTypeListResponse, Error<ListRecordTypesError>> {
234 let p_query_organization_id = organization_id;
236
237 let uri_str = format!("{}/v1/records/types", configuration.base_path);
238 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
239
240 req_builder = req_builder.query(&[("organization_id", &p_query_organization_id.to_string())]);
241 if let Some(ref user_agent) = configuration.user_agent {
242 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
243 }
244 if let Some(ref token) = configuration.bearer_access_token {
245 req_builder = req_builder.bearer_auth(token.to_owned());
246 };
247
248 let req = req_builder.build()?;
249 let resp = configuration.client.execute(req).await?;
250
251 let status = resp.status();
252 let content_type = resp
253 .headers()
254 .get("content-type")
255 .and_then(|v| v.to_str().ok())
256 .unwrap_or("application/octet-stream");
257 let content_type = super::ContentType::from(content_type);
258
259 if !status.is_client_error() && !status.is_server_error() {
260 let content = resp.text().await?;
261 match content_type {
262 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
263 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecordTypeListResponse`"))),
264 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RecordTypeListResponse`")))),
265 }
266 } else {
267 let content = resp.text().await?;
268 let entity: Option<ListRecordTypesError> = serde_json::from_str(&content).ok();
269 Err(Error::ResponseError(ResponseContent { status, content, entity }))
270 }
271}
272
273pub async fn list_records(configuration: &configuration::Configuration, organization_id: &str, record_type_id: Option<&str>, limit: Option<i32>) -> Result<models::RecordListResponse, Error<ListRecordsError>> {
274 let p_query_organization_id = organization_id;
276 let p_query_record_type_id = record_type_id;
277 let p_query_limit = limit;
278
279 let uri_str = format!("{}/v1/records", configuration.base_path);
280 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
281
282 req_builder = req_builder.query(&[("organization_id", &p_query_organization_id.to_string())]);
283 if let Some(ref param_value) = p_query_record_type_id {
284 req_builder = req_builder.query(&[("record_type_id", ¶m_value.to_string())]);
285 }
286 if let Some(ref param_value) = p_query_limit {
287 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
288 }
289 if let Some(ref user_agent) = configuration.user_agent {
290 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
291 }
292 if let Some(ref token) = configuration.bearer_access_token {
293 req_builder = req_builder.bearer_auth(token.to_owned());
294 };
295
296 let req = req_builder.build()?;
297 let resp = configuration.client.execute(req).await?;
298
299 let status = resp.status();
300 let content_type = resp
301 .headers()
302 .get("content-type")
303 .and_then(|v| v.to_str().ok())
304 .unwrap_or("application/octet-stream");
305 let content_type = super::ContentType::from(content_type);
306
307 if !status.is_client_error() && !status.is_server_error() {
308 let content = resp.text().await?;
309 match content_type {
310 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
311 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecordListResponse`"))),
312 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RecordListResponse`")))),
313 }
314 } else {
315 let content = resp.text().await?;
316 let entity: Option<ListRecordsError> = serde_json::from_str(&content).ok();
317 Err(Error::ResponseError(ResponseContent { status, content, entity }))
318 }
319}
320
321pub async fn update_record(configuration: &configuration::Configuration, id: &str, update_record_request: models::UpdateRecordRequest) -> Result<models::Record, Error<UpdateRecordError>> {
322 let p_path_id = id;
324 let p_body_update_record_request = update_record_request;
325
326 let uri_str = format!("{}/v1/records/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
327 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
328
329 if let Some(ref user_agent) = configuration.user_agent {
330 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
331 }
332 if let Some(ref token) = configuration.bearer_access_token {
333 req_builder = req_builder.bearer_auth(token.to_owned());
334 };
335 req_builder = req_builder.json(&p_body_update_record_request);
336
337 let req = req_builder.build()?;
338 let resp = configuration.client.execute(req).await?;
339
340 let status = resp.status();
341 let content_type = resp
342 .headers()
343 .get("content-type")
344 .and_then(|v| v.to_str().ok())
345 .unwrap_or("application/octet-stream");
346 let content_type = super::ContentType::from(content_type);
347
348 if !status.is_client_error() && !status.is_server_error() {
349 let content = resp.text().await?;
350 match content_type {
351 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
352 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Record`"))),
353 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Record`")))),
354 }
355 } else {
356 let content = resp.text().await?;
357 let entity: Option<UpdateRecordError> = serde_json::from_str(&content).ok();
358 Err(Error::ResponseError(ResponseContent { status, content, entity }))
359 }
360}
361
362pub async fn update_record_type(configuration: &configuration::Configuration, id: &str, update_record_type_request: models::UpdateRecordTypeRequest) -> Result<models::RecordType, Error<UpdateRecordTypeError>> {
363 let p_path_id = id;
365 let p_body_update_record_type_request = update_record_type_request;
366
367 let uri_str = format!("{}/v1/records/types/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
368 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
369
370 if let Some(ref user_agent) = configuration.user_agent {
371 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
372 }
373 if let Some(ref token) = configuration.bearer_access_token {
374 req_builder = req_builder.bearer_auth(token.to_owned());
375 };
376 req_builder = req_builder.json(&p_body_update_record_type_request);
377
378 let req = req_builder.build()?;
379 let resp = configuration.client.execute(req).await?;
380
381 let status = resp.status();
382 let content_type = resp
383 .headers()
384 .get("content-type")
385 .and_then(|v| v.to_str().ok())
386 .unwrap_or("application/octet-stream");
387 let content_type = super::ContentType::from(content_type);
388
389 if !status.is_client_error() && !status.is_server_error() {
390 let content = resp.text().await?;
391 match content_type {
392 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
393 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecordType`"))),
394 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RecordType`")))),
395 }
396 } else {
397 let content = resp.text().await?;
398 let entity: Option<UpdateRecordTypeError> = serde_json::from_str(&content).ok();
399 Err(Error::ResponseError(ResponseContent { status, content, entity }))
400 }
401}
402