1use crate::datadog;
5use flate2::{
6 write::{GzEncoder, ZlibEncoder},
7 Compression,
8};
9use log::warn;
10use reqwest::header::{HeaderMap, HeaderValue};
11use serde::{Deserialize, Serialize};
12use std::io::Write;
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(untagged)]
17pub enum CreateDatasetError {
18 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
19 UnknownValue(serde_json::Value),
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
24#[serde(untagged)]
25pub enum DeleteDatasetError {
26 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum GetAllDatasetsError {
34 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetDatasetError {
42 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum UpdateDatasetError {
50 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
51 UnknownValue(serde_json::Value),
52}
53
54#[derive(Debug, Clone)]
58pub struct DatasetsAPI {
59 config: datadog::Configuration,
60 client: reqwest_middleware::ClientWithMiddleware,
61}
62
63impl Default for DatasetsAPI {
64 fn default() -> Self {
65 Self::with_config(datadog::Configuration::default())
66 }
67}
68
69impl DatasetsAPI {
70 pub fn new() -> Self {
71 Self::default()
72 }
73 pub fn with_config(config: datadog::Configuration) -> Self {
74 let mut reqwest_client_builder = reqwest::Client::builder();
75
76 if let Some(proxy_url) = &config.proxy_url {
77 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
78 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
79 }
80
81 let mut middleware_client_builder =
82 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
83
84 if config.enable_retry {
85 struct RetryableStatus;
86 impl reqwest_retry::RetryableStrategy for RetryableStatus {
87 fn handle(
88 &self,
89 res: &Result<reqwest::Response, reqwest_middleware::Error>,
90 ) -> Option<reqwest_retry::Retryable> {
91 match res {
92 Ok(success) => reqwest_retry::default_on_request_success(success),
93 Err(_) => None,
94 }
95 }
96 }
97 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
98 .build_with_max_retries(config.max_retries);
99
100 let retry_middleware =
101 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
102 backoff_policy,
103 RetryableStatus,
104 );
105
106 middleware_client_builder = middleware_client_builder.with(retry_middleware);
107 }
108
109 let client = middleware_client_builder.build();
110
111 Self { config, client }
112 }
113
114 pub fn with_client_and_config(
115 config: datadog::Configuration,
116 client: reqwest_middleware::ClientWithMiddleware,
117 ) -> Self {
118 Self { config, client }
119 }
120
121 pub async fn create_dataset(
123 &self,
124 body: crate::datadogV2::model::DatasetCreateRequest,
125 ) -> Result<crate::datadogV2::model::DatasetResponseSingle, datadog::Error<CreateDatasetError>>
126 {
127 match self.create_dataset_with_http_info(body).await {
128 Ok(response_content) => {
129 if let Some(e) = response_content.entity {
130 Ok(e)
131 } else {
132 Err(datadog::Error::Serde(serde::de::Error::custom(
133 "response content was None",
134 )))
135 }
136 }
137 Err(err) => Err(err),
138 }
139 }
140
141 pub async fn create_dataset_with_http_info(
143 &self,
144 body: crate::datadogV2::model::DatasetCreateRequest,
145 ) -> Result<
146 datadog::ResponseContent<crate::datadogV2::model::DatasetResponseSingle>,
147 datadog::Error<CreateDatasetError>,
148 > {
149 let local_configuration = &self.config;
150 let operation_id = "v2.create_dataset";
151 if local_configuration.is_unstable_operation_enabled(operation_id) {
152 warn!("Using unstable operation {operation_id}");
153 } else {
154 let local_error = datadog::UnstableOperationDisabledError {
155 msg: "Operation 'v2.create_dataset' is not enabled".to_string(),
156 };
157 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
158 }
159
160 let local_client = &self.client;
161
162 let local_uri_str = format!(
163 "{}/api/v2/datasets",
164 local_configuration.get_operation_host(operation_id)
165 );
166 let mut local_req_builder =
167 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
168
169 let mut headers = HeaderMap::new();
171 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
172 headers.insert("Accept", HeaderValue::from_static("application/json"));
173
174 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
176 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
177 Err(e) => {
178 log::warn!("Failed to parse user agent header: {e}, falling back to default");
179 headers.insert(
180 reqwest::header::USER_AGENT,
181 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
182 )
183 }
184 };
185
186 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
188 headers.insert(
189 "DD-API-KEY",
190 HeaderValue::from_str(local_key.key.as_str())
191 .expect("failed to parse DD-API-KEY header"),
192 );
193 };
194 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
195 headers.insert(
196 "DD-APPLICATION-KEY",
197 HeaderValue::from_str(local_key.key.as_str())
198 .expect("failed to parse DD-APPLICATION-KEY header"),
199 );
200 };
201
202 let output = Vec::new();
204 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
205 if body.serialize(&mut ser).is_ok() {
206 if let Some(content_encoding) = headers.get("Content-Encoding") {
207 match content_encoding.to_str().unwrap_or_default() {
208 "gzip" => {
209 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
210 let _ = enc.write_all(ser.into_inner().as_slice());
211 match enc.finish() {
212 Ok(buf) => {
213 local_req_builder = local_req_builder.body(buf);
214 }
215 Err(e) => return Err(datadog::Error::Io(e)),
216 }
217 }
218 "deflate" => {
219 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
220 let _ = enc.write_all(ser.into_inner().as_slice());
221 match enc.finish() {
222 Ok(buf) => {
223 local_req_builder = local_req_builder.body(buf);
224 }
225 Err(e) => return Err(datadog::Error::Io(e)),
226 }
227 }
228 "zstd1" => {
229 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
230 let _ = enc.write_all(ser.into_inner().as_slice());
231 match enc.finish() {
232 Ok(buf) => {
233 local_req_builder = local_req_builder.body(buf);
234 }
235 Err(e) => return Err(datadog::Error::Io(e)),
236 }
237 }
238 _ => {
239 local_req_builder = local_req_builder.body(ser.into_inner());
240 }
241 }
242 } else {
243 local_req_builder = local_req_builder.body(ser.into_inner());
244 }
245 }
246
247 local_req_builder = local_req_builder.headers(headers);
248 let local_req = local_req_builder.build()?;
249 log::debug!("request content: {:?}", local_req.body());
250 let local_resp = local_client.execute(local_req).await?;
251
252 let local_status = local_resp.status();
253 let local_content = local_resp.text().await?;
254 log::debug!("response content: {}", local_content);
255
256 if !local_status.is_client_error() && !local_status.is_server_error() {
257 match serde_json::from_str::<crate::datadogV2::model::DatasetResponseSingle>(
258 &local_content,
259 ) {
260 Ok(e) => {
261 return Ok(datadog::ResponseContent {
262 status: local_status,
263 content: local_content,
264 entity: Some(e),
265 })
266 }
267 Err(e) => return Err(datadog::Error::Serde(e)),
268 };
269 } else {
270 let local_entity: Option<CreateDatasetError> =
271 serde_json::from_str(&local_content).ok();
272 let local_error = datadog::ResponseContent {
273 status: local_status,
274 content: local_content,
275 entity: local_entity,
276 };
277 Err(datadog::Error::ResponseError(local_error))
278 }
279 }
280
281 pub async fn delete_dataset(
283 &self,
284 dataset_id: String,
285 ) -> Result<(), datadog::Error<DeleteDatasetError>> {
286 match self.delete_dataset_with_http_info(dataset_id).await {
287 Ok(_) => Ok(()),
288 Err(err) => Err(err),
289 }
290 }
291
292 pub async fn delete_dataset_with_http_info(
294 &self,
295 dataset_id: String,
296 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteDatasetError>> {
297 let local_configuration = &self.config;
298 let operation_id = "v2.delete_dataset";
299 if local_configuration.is_unstable_operation_enabled(operation_id) {
300 warn!("Using unstable operation {operation_id}");
301 } else {
302 let local_error = datadog::UnstableOperationDisabledError {
303 msg: "Operation 'v2.delete_dataset' is not enabled".to_string(),
304 };
305 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
306 }
307
308 let local_client = &self.client;
309
310 let local_uri_str = format!(
311 "{}/api/v2/datasets/{dataset_id}",
312 local_configuration.get_operation_host(operation_id),
313 dataset_id = datadog::urlencode(dataset_id)
314 );
315 let mut local_req_builder =
316 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
317
318 let mut headers = HeaderMap::new();
320 headers.insert("Accept", HeaderValue::from_static("*/*"));
321
322 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
324 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
325 Err(e) => {
326 log::warn!("Failed to parse user agent header: {e}, falling back to default");
327 headers.insert(
328 reqwest::header::USER_AGENT,
329 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
330 )
331 }
332 };
333
334 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
336 headers.insert(
337 "DD-API-KEY",
338 HeaderValue::from_str(local_key.key.as_str())
339 .expect("failed to parse DD-API-KEY header"),
340 );
341 };
342 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
343 headers.insert(
344 "DD-APPLICATION-KEY",
345 HeaderValue::from_str(local_key.key.as_str())
346 .expect("failed to parse DD-APPLICATION-KEY header"),
347 );
348 };
349
350 local_req_builder = local_req_builder.headers(headers);
351 let local_req = local_req_builder.build()?;
352 log::debug!("request content: {:?}", local_req.body());
353 let local_resp = local_client.execute(local_req).await?;
354
355 let local_status = local_resp.status();
356 let local_content = local_resp.text().await?;
357 log::debug!("response content: {}", local_content);
358
359 if !local_status.is_client_error() && !local_status.is_server_error() {
360 Ok(datadog::ResponseContent {
361 status: local_status,
362 content: local_content,
363 entity: None,
364 })
365 } else {
366 let local_entity: Option<DeleteDatasetError> =
367 serde_json::from_str(&local_content).ok();
368 let local_error = datadog::ResponseContent {
369 status: local_status,
370 content: local_content,
371 entity: local_entity,
372 };
373 Err(datadog::Error::ResponseError(local_error))
374 }
375 }
376
377 pub async fn get_all_datasets(
379 &self,
380 ) -> Result<crate::datadogV2::model::DatasetResponseMulti, datadog::Error<GetAllDatasetsError>>
381 {
382 match self.get_all_datasets_with_http_info().await {
383 Ok(response_content) => {
384 if let Some(e) = response_content.entity {
385 Ok(e)
386 } else {
387 Err(datadog::Error::Serde(serde::de::Error::custom(
388 "response content was None",
389 )))
390 }
391 }
392 Err(err) => Err(err),
393 }
394 }
395
396 pub async fn get_all_datasets_with_http_info(
398 &self,
399 ) -> Result<
400 datadog::ResponseContent<crate::datadogV2::model::DatasetResponseMulti>,
401 datadog::Error<GetAllDatasetsError>,
402 > {
403 let local_configuration = &self.config;
404 let operation_id = "v2.get_all_datasets";
405 if local_configuration.is_unstable_operation_enabled(operation_id) {
406 warn!("Using unstable operation {operation_id}");
407 } else {
408 let local_error = datadog::UnstableOperationDisabledError {
409 msg: "Operation 'v2.get_all_datasets' is not enabled".to_string(),
410 };
411 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
412 }
413
414 let local_client = &self.client;
415
416 let local_uri_str = format!(
417 "{}/api/v2/datasets",
418 local_configuration.get_operation_host(operation_id)
419 );
420 let mut local_req_builder =
421 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
422
423 let mut headers = HeaderMap::new();
425 headers.insert("Accept", HeaderValue::from_static("application/json"));
426
427 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
429 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
430 Err(e) => {
431 log::warn!("Failed to parse user agent header: {e}, falling back to default");
432 headers.insert(
433 reqwest::header::USER_AGENT,
434 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
435 )
436 }
437 };
438
439 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
441 headers.insert(
442 "DD-API-KEY",
443 HeaderValue::from_str(local_key.key.as_str())
444 .expect("failed to parse DD-API-KEY header"),
445 );
446 };
447 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
448 headers.insert(
449 "DD-APPLICATION-KEY",
450 HeaderValue::from_str(local_key.key.as_str())
451 .expect("failed to parse DD-APPLICATION-KEY header"),
452 );
453 };
454
455 local_req_builder = local_req_builder.headers(headers);
456 let local_req = local_req_builder.build()?;
457 log::debug!("request content: {:?}", local_req.body());
458 let local_resp = local_client.execute(local_req).await?;
459
460 let local_status = local_resp.status();
461 let local_content = local_resp.text().await?;
462 log::debug!("response content: {}", local_content);
463
464 if !local_status.is_client_error() && !local_status.is_server_error() {
465 match serde_json::from_str::<crate::datadogV2::model::DatasetResponseMulti>(
466 &local_content,
467 ) {
468 Ok(e) => {
469 return Ok(datadog::ResponseContent {
470 status: local_status,
471 content: local_content,
472 entity: Some(e),
473 })
474 }
475 Err(e) => return Err(datadog::Error::Serde(e)),
476 };
477 } else {
478 let local_entity: Option<GetAllDatasetsError> =
479 serde_json::from_str(&local_content).ok();
480 let local_error = datadog::ResponseContent {
481 status: local_status,
482 content: local_content,
483 entity: local_entity,
484 };
485 Err(datadog::Error::ResponseError(local_error))
486 }
487 }
488
489 pub async fn get_dataset(
491 &self,
492 dataset_id: String,
493 ) -> Result<crate::datadogV2::model::DatasetResponseSingle, datadog::Error<GetDatasetError>>
494 {
495 match self.get_dataset_with_http_info(dataset_id).await {
496 Ok(response_content) => {
497 if let Some(e) = response_content.entity {
498 Ok(e)
499 } else {
500 Err(datadog::Error::Serde(serde::de::Error::custom(
501 "response content was None",
502 )))
503 }
504 }
505 Err(err) => Err(err),
506 }
507 }
508
509 pub async fn get_dataset_with_http_info(
511 &self,
512 dataset_id: String,
513 ) -> Result<
514 datadog::ResponseContent<crate::datadogV2::model::DatasetResponseSingle>,
515 datadog::Error<GetDatasetError>,
516 > {
517 let local_configuration = &self.config;
518 let operation_id = "v2.get_dataset";
519 if local_configuration.is_unstable_operation_enabled(operation_id) {
520 warn!("Using unstable operation {operation_id}");
521 } else {
522 let local_error = datadog::UnstableOperationDisabledError {
523 msg: "Operation 'v2.get_dataset' is not enabled".to_string(),
524 };
525 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
526 }
527
528 let local_client = &self.client;
529
530 let local_uri_str = format!(
531 "{}/api/v2/datasets/{dataset_id}",
532 local_configuration.get_operation_host(operation_id),
533 dataset_id = datadog::urlencode(dataset_id)
534 );
535 let mut local_req_builder =
536 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
537
538 let mut headers = HeaderMap::new();
540 headers.insert("Accept", HeaderValue::from_static("application/json"));
541
542 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
544 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
545 Err(e) => {
546 log::warn!("Failed to parse user agent header: {e}, falling back to default");
547 headers.insert(
548 reqwest::header::USER_AGENT,
549 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
550 )
551 }
552 };
553
554 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
556 headers.insert(
557 "DD-API-KEY",
558 HeaderValue::from_str(local_key.key.as_str())
559 .expect("failed to parse DD-API-KEY header"),
560 );
561 };
562 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
563 headers.insert(
564 "DD-APPLICATION-KEY",
565 HeaderValue::from_str(local_key.key.as_str())
566 .expect("failed to parse DD-APPLICATION-KEY header"),
567 );
568 };
569
570 local_req_builder = local_req_builder.headers(headers);
571 let local_req = local_req_builder.build()?;
572 log::debug!("request content: {:?}", local_req.body());
573 let local_resp = local_client.execute(local_req).await?;
574
575 let local_status = local_resp.status();
576 let local_content = local_resp.text().await?;
577 log::debug!("response content: {}", local_content);
578
579 if !local_status.is_client_error() && !local_status.is_server_error() {
580 match serde_json::from_str::<crate::datadogV2::model::DatasetResponseSingle>(
581 &local_content,
582 ) {
583 Ok(e) => {
584 return Ok(datadog::ResponseContent {
585 status: local_status,
586 content: local_content,
587 entity: Some(e),
588 })
589 }
590 Err(e) => return Err(datadog::Error::Serde(e)),
591 };
592 } else {
593 let local_entity: Option<GetDatasetError> = serde_json::from_str(&local_content).ok();
594 let local_error = datadog::ResponseContent {
595 status: local_status,
596 content: local_content,
597 entity: local_entity,
598 };
599 Err(datadog::Error::ResponseError(local_error))
600 }
601 }
602
603 pub async fn update_dataset(
605 &self,
606 dataset_id: String,
607 body: crate::datadogV2::model::DatasetUpdateRequest,
608 ) -> Result<crate::datadogV2::model::DatasetResponseSingle, datadog::Error<UpdateDatasetError>>
609 {
610 match self.update_dataset_with_http_info(dataset_id, body).await {
611 Ok(response_content) => {
612 if let Some(e) = response_content.entity {
613 Ok(e)
614 } else {
615 Err(datadog::Error::Serde(serde::de::Error::custom(
616 "response content was None",
617 )))
618 }
619 }
620 Err(err) => Err(err),
621 }
622 }
623
624 pub async fn update_dataset_with_http_info(
626 &self,
627 dataset_id: String,
628 body: crate::datadogV2::model::DatasetUpdateRequest,
629 ) -> Result<
630 datadog::ResponseContent<crate::datadogV2::model::DatasetResponseSingle>,
631 datadog::Error<UpdateDatasetError>,
632 > {
633 let local_configuration = &self.config;
634 let operation_id = "v2.update_dataset";
635 if local_configuration.is_unstable_operation_enabled(operation_id) {
636 warn!("Using unstable operation {operation_id}");
637 } else {
638 let local_error = datadog::UnstableOperationDisabledError {
639 msg: "Operation 'v2.update_dataset' is not enabled".to_string(),
640 };
641 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
642 }
643
644 let local_client = &self.client;
645
646 let local_uri_str = format!(
647 "{}/api/v2/datasets/{dataset_id}",
648 local_configuration.get_operation_host(operation_id),
649 dataset_id = datadog::urlencode(dataset_id)
650 );
651 let mut local_req_builder =
652 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
653
654 let mut headers = HeaderMap::new();
656 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
657 headers.insert("Accept", HeaderValue::from_static("application/json"));
658
659 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
661 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
662 Err(e) => {
663 log::warn!("Failed to parse user agent header: {e}, falling back to default");
664 headers.insert(
665 reqwest::header::USER_AGENT,
666 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
667 )
668 }
669 };
670
671 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
673 headers.insert(
674 "DD-API-KEY",
675 HeaderValue::from_str(local_key.key.as_str())
676 .expect("failed to parse DD-API-KEY header"),
677 );
678 };
679 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
680 headers.insert(
681 "DD-APPLICATION-KEY",
682 HeaderValue::from_str(local_key.key.as_str())
683 .expect("failed to parse DD-APPLICATION-KEY header"),
684 );
685 };
686
687 let output = Vec::new();
689 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
690 if body.serialize(&mut ser).is_ok() {
691 if let Some(content_encoding) = headers.get("Content-Encoding") {
692 match content_encoding.to_str().unwrap_or_default() {
693 "gzip" => {
694 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
695 let _ = enc.write_all(ser.into_inner().as_slice());
696 match enc.finish() {
697 Ok(buf) => {
698 local_req_builder = local_req_builder.body(buf);
699 }
700 Err(e) => return Err(datadog::Error::Io(e)),
701 }
702 }
703 "deflate" => {
704 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
705 let _ = enc.write_all(ser.into_inner().as_slice());
706 match enc.finish() {
707 Ok(buf) => {
708 local_req_builder = local_req_builder.body(buf);
709 }
710 Err(e) => return Err(datadog::Error::Io(e)),
711 }
712 }
713 "zstd1" => {
714 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
715 let _ = enc.write_all(ser.into_inner().as_slice());
716 match enc.finish() {
717 Ok(buf) => {
718 local_req_builder = local_req_builder.body(buf);
719 }
720 Err(e) => return Err(datadog::Error::Io(e)),
721 }
722 }
723 _ => {
724 local_req_builder = local_req_builder.body(ser.into_inner());
725 }
726 }
727 } else {
728 local_req_builder = local_req_builder.body(ser.into_inner());
729 }
730 }
731
732 local_req_builder = local_req_builder.headers(headers);
733 let local_req = local_req_builder.build()?;
734 log::debug!("request content: {:?}", local_req.body());
735 let local_resp = local_client.execute(local_req).await?;
736
737 let local_status = local_resp.status();
738 let local_content = local_resp.text().await?;
739 log::debug!("response content: {}", local_content);
740
741 if !local_status.is_client_error() && !local_status.is_server_error() {
742 match serde_json::from_str::<crate::datadogV2::model::DatasetResponseSingle>(
743 &local_content,
744 ) {
745 Ok(e) => {
746 return Ok(datadog::ResponseContent {
747 status: local_status,
748 content: local_content,
749 entity: Some(e),
750 })
751 }
752 Err(e) => return Err(datadog::Error::Serde(e)),
753 };
754 } else {
755 let local_entity: Option<UpdateDatasetError> =
756 serde_json::from_str(&local_content).ok();
757 let local_error = datadog::ResponseContent {
758 status: local_status,
759 content: local_content,
760 entity: local_entity,
761 };
762 Err(datadog::Error::ResponseError(local_error))
763 }
764 }
765}