datadog_api_client/datadogV2/api/
api_opsgenie_integration.rs

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