datadog_api_client/datadogV2/api/
api_fastly_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/// CreateFastlyAccountError is a struct for typed errors of method [`FastlyIntegrationAPI::create_fastly_account`]
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum CreateFastlyAccountError {
17    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
18    UnknownValue(serde_json::Value),
19}
20
21/// CreateFastlyServiceError is a struct for typed errors of method [`FastlyIntegrationAPI::create_fastly_service`]
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum CreateFastlyServiceError {
25    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
26    UnknownValue(serde_json::Value),
27}
28
29/// DeleteFastlyAccountError is a struct for typed errors of method [`FastlyIntegrationAPI::delete_fastly_account`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DeleteFastlyAccountError {
33    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
34    UnknownValue(serde_json::Value),
35}
36
37/// DeleteFastlyServiceError is a struct for typed errors of method [`FastlyIntegrationAPI::delete_fastly_service`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum DeleteFastlyServiceError {
41    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45/// GetFastlyAccountError is a struct for typed errors of method [`FastlyIntegrationAPI::get_fastly_account`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetFastlyAccountError {
49    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
50    UnknownValue(serde_json::Value),
51}
52
53/// GetFastlyServiceError is a struct for typed errors of method [`FastlyIntegrationAPI::get_fastly_service`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetFastlyServiceError {
57    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
58    UnknownValue(serde_json::Value),
59}
60
61/// ListFastlyAccountsError is a struct for typed errors of method [`FastlyIntegrationAPI::list_fastly_accounts`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum ListFastlyAccountsError {
65    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
66    UnknownValue(serde_json::Value),
67}
68
69/// ListFastlyServicesError is a struct for typed errors of method [`FastlyIntegrationAPI::list_fastly_services`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum ListFastlyServicesError {
73    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
74    UnknownValue(serde_json::Value),
75}
76
77/// UpdateFastlyAccountError is a struct for typed errors of method [`FastlyIntegrationAPI::update_fastly_account`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum UpdateFastlyAccountError {
81    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
82    UnknownValue(serde_json::Value),
83}
84
85/// UpdateFastlyServiceError is a struct for typed errors of method [`FastlyIntegrationAPI::update_fastly_service`]
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum UpdateFastlyServiceError {
89    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
90    UnknownValue(serde_json::Value),
91}
92
93/// Manage your Datadog Fastly integration accounts and services directly through the Datadog API. See the [Fastly integration page](<https://docs.datadoghq.com/integrations/fastly/>) for more information.
94#[derive(Debug, Clone)]
95pub struct FastlyIntegrationAPI {
96    config: datadog::Configuration,
97    client: reqwest_middleware::ClientWithMiddleware,
98}
99
100impl Default for FastlyIntegrationAPI {
101    fn default() -> Self {
102        Self::with_config(datadog::Configuration::default())
103    }
104}
105
106impl FastlyIntegrationAPI {
107    pub fn new() -> Self {
108        Self::default()
109    }
110    pub fn with_config(config: datadog::Configuration) -> Self {
111        let mut reqwest_client_builder = reqwest::Client::builder();
112
113        if let Some(proxy_url) = &config.proxy_url {
114            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
115            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
116        }
117
118        let mut middleware_client_builder =
119            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
120
121        if config.enable_retry {
122            struct RetryableStatus;
123            impl reqwest_retry::RetryableStrategy for RetryableStatus {
124                fn handle(
125                    &self,
126                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
127                ) -> Option<reqwest_retry::Retryable> {
128                    match res {
129                        Ok(success) => reqwest_retry::default_on_request_success(success),
130                        Err(_) => None,
131                    }
132                }
133            }
134            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
135                .build_with_max_retries(config.max_retries);
136
137            let retry_middleware =
138                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
139                    backoff_policy,
140                    RetryableStatus,
141                );
142
143            middleware_client_builder = middleware_client_builder.with(retry_middleware);
144        }
145
146        let client = middleware_client_builder.build();
147
148        Self { config, client }
149    }
150
151    pub fn with_client_and_config(
152        config: datadog::Configuration,
153        client: reqwest_middleware::ClientWithMiddleware,
154    ) -> Self {
155        Self { config, client }
156    }
157
158    /// Create a Fastly account.
159    pub async fn create_fastly_account(
160        &self,
161        body: crate::datadogV2::model::FastlyAccountCreateRequest,
162    ) -> Result<
163        crate::datadogV2::model::FastlyAccountResponse,
164        datadog::Error<CreateFastlyAccountError>,
165    > {
166        match self.create_fastly_account_with_http_info(body).await {
167            Ok(response_content) => {
168                if let Some(e) = response_content.entity {
169                    Ok(e)
170                } else {
171                    Err(datadog::Error::Serde(serde::de::Error::custom(
172                        "response content was None",
173                    )))
174                }
175            }
176            Err(err) => Err(err),
177        }
178    }
179
180    /// Create a Fastly account.
181    pub async fn create_fastly_account_with_http_info(
182        &self,
183        body: crate::datadogV2::model::FastlyAccountCreateRequest,
184    ) -> Result<
185        datadog::ResponseContent<crate::datadogV2::model::FastlyAccountResponse>,
186        datadog::Error<CreateFastlyAccountError>,
187    > {
188        let local_configuration = &self.config;
189        let operation_id = "v2.create_fastly_account";
190
191        let local_client = &self.client;
192
193        let local_uri_str = format!(
194            "{}/api/v2/integrations/fastly/accounts",
195            local_configuration.get_operation_host(operation_id)
196        );
197        let mut local_req_builder =
198            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
199
200        // build headers
201        let mut headers = HeaderMap::new();
202        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
203        headers.insert("Accept", HeaderValue::from_static("application/json"));
204
205        // build user agent
206        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
207            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
208            Err(e) => {
209                log::warn!("Failed to parse user agent header: {e}, falling back to default");
210                headers.insert(
211                    reqwest::header::USER_AGENT,
212                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
213                )
214            }
215        };
216
217        // build auth
218        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
219            headers.insert(
220                "DD-API-KEY",
221                HeaderValue::from_str(local_key.key.as_str())
222                    .expect("failed to parse DD-API-KEY header"),
223            );
224        };
225        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
226            headers.insert(
227                "DD-APPLICATION-KEY",
228                HeaderValue::from_str(local_key.key.as_str())
229                    .expect("failed to parse DD-APPLICATION-KEY header"),
230            );
231        };
232
233        // build body parameters
234        let output = Vec::new();
235        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
236        if body.serialize(&mut ser).is_ok() {
237            if let Some(content_encoding) = headers.get("Content-Encoding") {
238                match content_encoding.to_str().unwrap_or_default() {
239                    "gzip" => {
240                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
241                        let _ = enc.write_all(ser.into_inner().as_slice());
242                        match enc.finish() {
243                            Ok(buf) => {
244                                local_req_builder = local_req_builder.body(buf);
245                            }
246                            Err(e) => return Err(datadog::Error::Io(e)),
247                        }
248                    }
249                    "deflate" => {
250                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
251                        let _ = enc.write_all(ser.into_inner().as_slice());
252                        match enc.finish() {
253                            Ok(buf) => {
254                                local_req_builder = local_req_builder.body(buf);
255                            }
256                            Err(e) => return Err(datadog::Error::Io(e)),
257                        }
258                    }
259                    "zstd1" => {
260                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
261                        let _ = enc.write_all(ser.into_inner().as_slice());
262                        match enc.finish() {
263                            Ok(buf) => {
264                                local_req_builder = local_req_builder.body(buf);
265                            }
266                            Err(e) => return Err(datadog::Error::Io(e)),
267                        }
268                    }
269                    _ => {
270                        local_req_builder = local_req_builder.body(ser.into_inner());
271                    }
272                }
273            } else {
274                local_req_builder = local_req_builder.body(ser.into_inner());
275            }
276        }
277
278        local_req_builder = local_req_builder.headers(headers);
279        let local_req = local_req_builder.build()?;
280        log::debug!("request content: {:?}", local_req.body());
281        let local_resp = local_client.execute(local_req).await?;
282
283        let local_status = local_resp.status();
284        let local_content = local_resp.text().await?;
285        log::debug!("response content: {}", local_content);
286
287        if !local_status.is_client_error() && !local_status.is_server_error() {
288            match serde_json::from_str::<crate::datadogV2::model::FastlyAccountResponse>(
289                &local_content,
290            ) {
291                Ok(e) => {
292                    return Ok(datadog::ResponseContent {
293                        status: local_status,
294                        content: local_content,
295                        entity: Some(e),
296                    })
297                }
298                Err(e) => return Err(datadog::Error::Serde(e)),
299            };
300        } else {
301            let local_entity: Option<CreateFastlyAccountError> =
302                serde_json::from_str(&local_content).ok();
303            let local_error = datadog::ResponseContent {
304                status: local_status,
305                content: local_content,
306                entity: local_entity,
307            };
308            Err(datadog::Error::ResponseError(local_error))
309        }
310    }
311
312    /// Create a Fastly service for an account.
313    pub async fn create_fastly_service(
314        &self,
315        account_id: String,
316        body: crate::datadogV2::model::FastlyServiceRequest,
317    ) -> Result<
318        crate::datadogV2::model::FastlyServiceResponse,
319        datadog::Error<CreateFastlyServiceError>,
320    > {
321        match self
322            .create_fastly_service_with_http_info(account_id, body)
323            .await
324        {
325            Ok(response_content) => {
326                if let Some(e) = response_content.entity {
327                    Ok(e)
328                } else {
329                    Err(datadog::Error::Serde(serde::de::Error::custom(
330                        "response content was None",
331                    )))
332                }
333            }
334            Err(err) => Err(err),
335        }
336    }
337
338    /// Create a Fastly service for an account.
339    pub async fn create_fastly_service_with_http_info(
340        &self,
341        account_id: String,
342        body: crate::datadogV2::model::FastlyServiceRequest,
343    ) -> Result<
344        datadog::ResponseContent<crate::datadogV2::model::FastlyServiceResponse>,
345        datadog::Error<CreateFastlyServiceError>,
346    > {
347        let local_configuration = &self.config;
348        let operation_id = "v2.create_fastly_service";
349
350        let local_client = &self.client;
351
352        let local_uri_str = format!(
353            "{}/api/v2/integrations/fastly/accounts/{account_id}/services",
354            local_configuration.get_operation_host(operation_id),
355            account_id = datadog::urlencode(account_id)
356        );
357        let mut local_req_builder =
358            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
359
360        // build headers
361        let mut headers = HeaderMap::new();
362        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
363        headers.insert("Accept", HeaderValue::from_static("application/json"));
364
365        // build user agent
366        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
367            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
368            Err(e) => {
369                log::warn!("Failed to parse user agent header: {e}, falling back to default");
370                headers.insert(
371                    reqwest::header::USER_AGENT,
372                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
373                )
374            }
375        };
376
377        // build auth
378        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
379            headers.insert(
380                "DD-API-KEY",
381                HeaderValue::from_str(local_key.key.as_str())
382                    .expect("failed to parse DD-API-KEY header"),
383            );
384        };
385        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
386            headers.insert(
387                "DD-APPLICATION-KEY",
388                HeaderValue::from_str(local_key.key.as_str())
389                    .expect("failed to parse DD-APPLICATION-KEY header"),
390            );
391        };
392
393        // build body parameters
394        let output = Vec::new();
395        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
396        if body.serialize(&mut ser).is_ok() {
397            if let Some(content_encoding) = headers.get("Content-Encoding") {
398                match content_encoding.to_str().unwrap_or_default() {
399                    "gzip" => {
400                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
401                        let _ = enc.write_all(ser.into_inner().as_slice());
402                        match enc.finish() {
403                            Ok(buf) => {
404                                local_req_builder = local_req_builder.body(buf);
405                            }
406                            Err(e) => return Err(datadog::Error::Io(e)),
407                        }
408                    }
409                    "deflate" => {
410                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
411                        let _ = enc.write_all(ser.into_inner().as_slice());
412                        match enc.finish() {
413                            Ok(buf) => {
414                                local_req_builder = local_req_builder.body(buf);
415                            }
416                            Err(e) => return Err(datadog::Error::Io(e)),
417                        }
418                    }
419                    "zstd1" => {
420                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
421                        let _ = enc.write_all(ser.into_inner().as_slice());
422                        match enc.finish() {
423                            Ok(buf) => {
424                                local_req_builder = local_req_builder.body(buf);
425                            }
426                            Err(e) => return Err(datadog::Error::Io(e)),
427                        }
428                    }
429                    _ => {
430                        local_req_builder = local_req_builder.body(ser.into_inner());
431                    }
432                }
433            } else {
434                local_req_builder = local_req_builder.body(ser.into_inner());
435            }
436        }
437
438        local_req_builder = local_req_builder.headers(headers);
439        let local_req = local_req_builder.build()?;
440        log::debug!("request content: {:?}", local_req.body());
441        let local_resp = local_client.execute(local_req).await?;
442
443        let local_status = local_resp.status();
444        let local_content = local_resp.text().await?;
445        log::debug!("response content: {}", local_content);
446
447        if !local_status.is_client_error() && !local_status.is_server_error() {
448            match serde_json::from_str::<crate::datadogV2::model::FastlyServiceResponse>(
449                &local_content,
450            ) {
451                Ok(e) => {
452                    return Ok(datadog::ResponseContent {
453                        status: local_status,
454                        content: local_content,
455                        entity: Some(e),
456                    })
457                }
458                Err(e) => return Err(datadog::Error::Serde(e)),
459            };
460        } else {
461            let local_entity: Option<CreateFastlyServiceError> =
462                serde_json::from_str(&local_content).ok();
463            let local_error = datadog::ResponseContent {
464                status: local_status,
465                content: local_content,
466                entity: local_entity,
467            };
468            Err(datadog::Error::ResponseError(local_error))
469        }
470    }
471
472    /// Delete a Fastly account.
473    pub async fn delete_fastly_account(
474        &self,
475        account_id: String,
476    ) -> Result<(), datadog::Error<DeleteFastlyAccountError>> {
477        match self.delete_fastly_account_with_http_info(account_id).await {
478            Ok(_) => Ok(()),
479            Err(err) => Err(err),
480        }
481    }
482
483    /// Delete a Fastly account.
484    pub async fn delete_fastly_account_with_http_info(
485        &self,
486        account_id: String,
487    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteFastlyAccountError>> {
488        let local_configuration = &self.config;
489        let operation_id = "v2.delete_fastly_account";
490
491        let local_client = &self.client;
492
493        let local_uri_str = format!(
494            "{}/api/v2/integrations/fastly/accounts/{account_id}",
495            local_configuration.get_operation_host(operation_id),
496            account_id = datadog::urlencode(account_id)
497        );
498        let mut local_req_builder =
499            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
500
501        // build headers
502        let mut headers = HeaderMap::new();
503        headers.insert("Accept", HeaderValue::from_static("*/*"));
504
505        // build user agent
506        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
507            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
508            Err(e) => {
509                log::warn!("Failed to parse user agent header: {e}, falling back to default");
510                headers.insert(
511                    reqwest::header::USER_AGENT,
512                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
513                )
514            }
515        };
516
517        // build auth
518        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
519            headers.insert(
520                "DD-API-KEY",
521                HeaderValue::from_str(local_key.key.as_str())
522                    .expect("failed to parse DD-API-KEY header"),
523            );
524        };
525        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
526            headers.insert(
527                "DD-APPLICATION-KEY",
528                HeaderValue::from_str(local_key.key.as_str())
529                    .expect("failed to parse DD-APPLICATION-KEY header"),
530            );
531        };
532
533        local_req_builder = local_req_builder.headers(headers);
534        let local_req = local_req_builder.build()?;
535        log::debug!("request content: {:?}", local_req.body());
536        let local_resp = local_client.execute(local_req).await?;
537
538        let local_status = local_resp.status();
539        let local_content = local_resp.text().await?;
540        log::debug!("response content: {}", local_content);
541
542        if !local_status.is_client_error() && !local_status.is_server_error() {
543            Ok(datadog::ResponseContent {
544                status: local_status,
545                content: local_content,
546                entity: None,
547            })
548        } else {
549            let local_entity: Option<DeleteFastlyAccountError> =
550                serde_json::from_str(&local_content).ok();
551            let local_error = datadog::ResponseContent {
552                status: local_status,
553                content: local_content,
554                entity: local_entity,
555            };
556            Err(datadog::Error::ResponseError(local_error))
557        }
558    }
559
560    /// Delete a Fastly service for an account.
561    pub async fn delete_fastly_service(
562        &self,
563        account_id: String,
564        service_id: String,
565    ) -> Result<(), datadog::Error<DeleteFastlyServiceError>> {
566        match self
567            .delete_fastly_service_with_http_info(account_id, service_id)
568            .await
569        {
570            Ok(_) => Ok(()),
571            Err(err) => Err(err),
572        }
573    }
574
575    /// Delete a Fastly service for an account.
576    pub async fn delete_fastly_service_with_http_info(
577        &self,
578        account_id: String,
579        service_id: String,
580    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteFastlyServiceError>> {
581        let local_configuration = &self.config;
582        let operation_id = "v2.delete_fastly_service";
583
584        let local_client = &self.client;
585
586        let local_uri_str = format!(
587            "{}/api/v2/integrations/fastly/accounts/{account_id}/services/{service_id}",
588            local_configuration.get_operation_host(operation_id),
589            account_id = datadog::urlencode(account_id),
590            service_id = datadog::urlencode(service_id)
591        );
592        let mut local_req_builder =
593            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
594
595        // build headers
596        let mut headers = HeaderMap::new();
597        headers.insert("Accept", HeaderValue::from_static("*/*"));
598
599        // build user agent
600        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
601            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
602            Err(e) => {
603                log::warn!("Failed to parse user agent header: {e}, falling back to default");
604                headers.insert(
605                    reqwest::header::USER_AGENT,
606                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
607                )
608            }
609        };
610
611        // build auth
612        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
613            headers.insert(
614                "DD-API-KEY",
615                HeaderValue::from_str(local_key.key.as_str())
616                    .expect("failed to parse DD-API-KEY header"),
617            );
618        };
619        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
620            headers.insert(
621                "DD-APPLICATION-KEY",
622                HeaderValue::from_str(local_key.key.as_str())
623                    .expect("failed to parse DD-APPLICATION-KEY header"),
624            );
625        };
626
627        local_req_builder = local_req_builder.headers(headers);
628        let local_req = local_req_builder.build()?;
629        log::debug!("request content: {:?}", local_req.body());
630        let local_resp = local_client.execute(local_req).await?;
631
632        let local_status = local_resp.status();
633        let local_content = local_resp.text().await?;
634        log::debug!("response content: {}", local_content);
635
636        if !local_status.is_client_error() && !local_status.is_server_error() {
637            Ok(datadog::ResponseContent {
638                status: local_status,
639                content: local_content,
640                entity: None,
641            })
642        } else {
643            let local_entity: Option<DeleteFastlyServiceError> =
644                serde_json::from_str(&local_content).ok();
645            let local_error = datadog::ResponseContent {
646                status: local_status,
647                content: local_content,
648                entity: local_entity,
649            };
650            Err(datadog::Error::ResponseError(local_error))
651        }
652    }
653
654    /// Get a Fastly account.
655    pub async fn get_fastly_account(
656        &self,
657        account_id: String,
658    ) -> Result<crate::datadogV2::model::FastlyAccountResponse, datadog::Error<GetFastlyAccountError>>
659    {
660        match self.get_fastly_account_with_http_info(account_id).await {
661            Ok(response_content) => {
662                if let Some(e) = response_content.entity {
663                    Ok(e)
664                } else {
665                    Err(datadog::Error::Serde(serde::de::Error::custom(
666                        "response content was None",
667                    )))
668                }
669            }
670            Err(err) => Err(err),
671        }
672    }
673
674    /// Get a Fastly account.
675    pub async fn get_fastly_account_with_http_info(
676        &self,
677        account_id: String,
678    ) -> Result<
679        datadog::ResponseContent<crate::datadogV2::model::FastlyAccountResponse>,
680        datadog::Error<GetFastlyAccountError>,
681    > {
682        let local_configuration = &self.config;
683        let operation_id = "v2.get_fastly_account";
684
685        let local_client = &self.client;
686
687        let local_uri_str = format!(
688            "{}/api/v2/integrations/fastly/accounts/{account_id}",
689            local_configuration.get_operation_host(operation_id),
690            account_id = datadog::urlencode(account_id)
691        );
692        let mut local_req_builder =
693            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
694
695        // build headers
696        let mut headers = HeaderMap::new();
697        headers.insert("Accept", HeaderValue::from_static("application/json"));
698
699        // build user agent
700        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
701            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
702            Err(e) => {
703                log::warn!("Failed to parse user agent header: {e}, falling back to default");
704                headers.insert(
705                    reqwest::header::USER_AGENT,
706                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
707                )
708            }
709        };
710
711        // build auth
712        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
713            headers.insert(
714                "DD-API-KEY",
715                HeaderValue::from_str(local_key.key.as_str())
716                    .expect("failed to parse DD-API-KEY header"),
717            );
718        };
719        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
720            headers.insert(
721                "DD-APPLICATION-KEY",
722                HeaderValue::from_str(local_key.key.as_str())
723                    .expect("failed to parse DD-APPLICATION-KEY header"),
724            );
725        };
726
727        local_req_builder = local_req_builder.headers(headers);
728        let local_req = local_req_builder.build()?;
729        log::debug!("request content: {:?}", local_req.body());
730        let local_resp = local_client.execute(local_req).await?;
731
732        let local_status = local_resp.status();
733        let local_content = local_resp.text().await?;
734        log::debug!("response content: {}", local_content);
735
736        if !local_status.is_client_error() && !local_status.is_server_error() {
737            match serde_json::from_str::<crate::datadogV2::model::FastlyAccountResponse>(
738                &local_content,
739            ) {
740                Ok(e) => {
741                    return Ok(datadog::ResponseContent {
742                        status: local_status,
743                        content: local_content,
744                        entity: Some(e),
745                    })
746                }
747                Err(e) => return Err(datadog::Error::Serde(e)),
748            };
749        } else {
750            let local_entity: Option<GetFastlyAccountError> =
751                serde_json::from_str(&local_content).ok();
752            let local_error = datadog::ResponseContent {
753                status: local_status,
754                content: local_content,
755                entity: local_entity,
756            };
757            Err(datadog::Error::ResponseError(local_error))
758        }
759    }
760
761    /// Get a Fastly service for an account.
762    pub async fn get_fastly_service(
763        &self,
764        account_id: String,
765        service_id: String,
766    ) -> Result<crate::datadogV2::model::FastlyServiceResponse, datadog::Error<GetFastlyServiceError>>
767    {
768        match self
769            .get_fastly_service_with_http_info(account_id, service_id)
770            .await
771        {
772            Ok(response_content) => {
773                if let Some(e) = response_content.entity {
774                    Ok(e)
775                } else {
776                    Err(datadog::Error::Serde(serde::de::Error::custom(
777                        "response content was None",
778                    )))
779                }
780            }
781            Err(err) => Err(err),
782        }
783    }
784
785    /// Get a Fastly service for an account.
786    pub async fn get_fastly_service_with_http_info(
787        &self,
788        account_id: String,
789        service_id: String,
790    ) -> Result<
791        datadog::ResponseContent<crate::datadogV2::model::FastlyServiceResponse>,
792        datadog::Error<GetFastlyServiceError>,
793    > {
794        let local_configuration = &self.config;
795        let operation_id = "v2.get_fastly_service";
796
797        let local_client = &self.client;
798
799        let local_uri_str = format!(
800            "{}/api/v2/integrations/fastly/accounts/{account_id}/services/{service_id}",
801            local_configuration.get_operation_host(operation_id),
802            account_id = datadog::urlencode(account_id),
803            service_id = datadog::urlencode(service_id)
804        );
805        let mut local_req_builder =
806            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
807
808        // build headers
809        let mut headers = HeaderMap::new();
810        headers.insert("Accept", HeaderValue::from_static("application/json"));
811
812        // build user agent
813        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
814            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
815            Err(e) => {
816                log::warn!("Failed to parse user agent header: {e}, falling back to default");
817                headers.insert(
818                    reqwest::header::USER_AGENT,
819                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
820                )
821            }
822        };
823
824        // build auth
825        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
826            headers.insert(
827                "DD-API-KEY",
828                HeaderValue::from_str(local_key.key.as_str())
829                    .expect("failed to parse DD-API-KEY header"),
830            );
831        };
832        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
833            headers.insert(
834                "DD-APPLICATION-KEY",
835                HeaderValue::from_str(local_key.key.as_str())
836                    .expect("failed to parse DD-APPLICATION-KEY header"),
837            );
838        };
839
840        local_req_builder = local_req_builder.headers(headers);
841        let local_req = local_req_builder.build()?;
842        log::debug!("request content: {:?}", local_req.body());
843        let local_resp = local_client.execute(local_req).await?;
844
845        let local_status = local_resp.status();
846        let local_content = local_resp.text().await?;
847        log::debug!("response content: {}", local_content);
848
849        if !local_status.is_client_error() && !local_status.is_server_error() {
850            match serde_json::from_str::<crate::datadogV2::model::FastlyServiceResponse>(
851                &local_content,
852            ) {
853                Ok(e) => {
854                    return Ok(datadog::ResponseContent {
855                        status: local_status,
856                        content: local_content,
857                        entity: Some(e),
858                    })
859                }
860                Err(e) => return Err(datadog::Error::Serde(e)),
861            };
862        } else {
863            let local_entity: Option<GetFastlyServiceError> =
864                serde_json::from_str(&local_content).ok();
865            let local_error = datadog::ResponseContent {
866                status: local_status,
867                content: local_content,
868                entity: local_entity,
869            };
870            Err(datadog::Error::ResponseError(local_error))
871        }
872    }
873
874    /// List Fastly accounts.
875    pub async fn list_fastly_accounts(
876        &self,
877    ) -> Result<
878        crate::datadogV2::model::FastlyAccountsResponse,
879        datadog::Error<ListFastlyAccountsError>,
880    > {
881        match self.list_fastly_accounts_with_http_info().await {
882            Ok(response_content) => {
883                if let Some(e) = response_content.entity {
884                    Ok(e)
885                } else {
886                    Err(datadog::Error::Serde(serde::de::Error::custom(
887                        "response content was None",
888                    )))
889                }
890            }
891            Err(err) => Err(err),
892        }
893    }
894
895    /// List Fastly accounts.
896    pub async fn list_fastly_accounts_with_http_info(
897        &self,
898    ) -> Result<
899        datadog::ResponseContent<crate::datadogV2::model::FastlyAccountsResponse>,
900        datadog::Error<ListFastlyAccountsError>,
901    > {
902        let local_configuration = &self.config;
903        let operation_id = "v2.list_fastly_accounts";
904
905        let local_client = &self.client;
906
907        let local_uri_str = format!(
908            "{}/api/v2/integrations/fastly/accounts",
909            local_configuration.get_operation_host(operation_id)
910        );
911        let mut local_req_builder =
912            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
913
914        // build headers
915        let mut headers = HeaderMap::new();
916        headers.insert("Accept", HeaderValue::from_static("application/json"));
917
918        // build user agent
919        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
920            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
921            Err(e) => {
922                log::warn!("Failed to parse user agent header: {e}, falling back to default");
923                headers.insert(
924                    reqwest::header::USER_AGENT,
925                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
926                )
927            }
928        };
929
930        // build auth
931        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
932            headers.insert(
933                "DD-API-KEY",
934                HeaderValue::from_str(local_key.key.as_str())
935                    .expect("failed to parse DD-API-KEY header"),
936            );
937        };
938        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
939            headers.insert(
940                "DD-APPLICATION-KEY",
941                HeaderValue::from_str(local_key.key.as_str())
942                    .expect("failed to parse DD-APPLICATION-KEY header"),
943            );
944        };
945
946        local_req_builder = local_req_builder.headers(headers);
947        let local_req = local_req_builder.build()?;
948        log::debug!("request content: {:?}", local_req.body());
949        let local_resp = local_client.execute(local_req).await?;
950
951        let local_status = local_resp.status();
952        let local_content = local_resp.text().await?;
953        log::debug!("response content: {}", local_content);
954
955        if !local_status.is_client_error() && !local_status.is_server_error() {
956            match serde_json::from_str::<crate::datadogV2::model::FastlyAccountsResponse>(
957                &local_content,
958            ) {
959                Ok(e) => {
960                    return Ok(datadog::ResponseContent {
961                        status: local_status,
962                        content: local_content,
963                        entity: Some(e),
964                    })
965                }
966                Err(e) => return Err(datadog::Error::Serde(e)),
967            };
968        } else {
969            let local_entity: Option<ListFastlyAccountsError> =
970                serde_json::from_str(&local_content).ok();
971            let local_error = datadog::ResponseContent {
972                status: local_status,
973                content: local_content,
974                entity: local_entity,
975            };
976            Err(datadog::Error::ResponseError(local_error))
977        }
978    }
979
980    /// List Fastly services for an account.
981    pub async fn list_fastly_services(
982        &self,
983        account_id: String,
984    ) -> Result<
985        crate::datadogV2::model::FastlyServicesResponse,
986        datadog::Error<ListFastlyServicesError>,
987    > {
988        match self.list_fastly_services_with_http_info(account_id).await {
989            Ok(response_content) => {
990                if let Some(e) = response_content.entity {
991                    Ok(e)
992                } else {
993                    Err(datadog::Error::Serde(serde::de::Error::custom(
994                        "response content was None",
995                    )))
996                }
997            }
998            Err(err) => Err(err),
999        }
1000    }
1001
1002    /// List Fastly services for an account.
1003    pub async fn list_fastly_services_with_http_info(
1004        &self,
1005        account_id: String,
1006    ) -> Result<
1007        datadog::ResponseContent<crate::datadogV2::model::FastlyServicesResponse>,
1008        datadog::Error<ListFastlyServicesError>,
1009    > {
1010        let local_configuration = &self.config;
1011        let operation_id = "v2.list_fastly_services";
1012
1013        let local_client = &self.client;
1014
1015        let local_uri_str = format!(
1016            "{}/api/v2/integrations/fastly/accounts/{account_id}/services",
1017            local_configuration.get_operation_host(operation_id),
1018            account_id = datadog::urlencode(account_id)
1019        );
1020        let mut local_req_builder =
1021            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1022
1023        // build headers
1024        let mut headers = HeaderMap::new();
1025        headers.insert("Accept", HeaderValue::from_static("application/json"));
1026
1027        // build user agent
1028        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1029            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1030            Err(e) => {
1031                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1032                headers.insert(
1033                    reqwest::header::USER_AGENT,
1034                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1035                )
1036            }
1037        };
1038
1039        // build auth
1040        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1041            headers.insert(
1042                "DD-API-KEY",
1043                HeaderValue::from_str(local_key.key.as_str())
1044                    .expect("failed to parse DD-API-KEY header"),
1045            );
1046        };
1047        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1048            headers.insert(
1049                "DD-APPLICATION-KEY",
1050                HeaderValue::from_str(local_key.key.as_str())
1051                    .expect("failed to parse DD-APPLICATION-KEY header"),
1052            );
1053        };
1054
1055        local_req_builder = local_req_builder.headers(headers);
1056        let local_req = local_req_builder.build()?;
1057        log::debug!("request content: {:?}", local_req.body());
1058        let local_resp = local_client.execute(local_req).await?;
1059
1060        let local_status = local_resp.status();
1061        let local_content = local_resp.text().await?;
1062        log::debug!("response content: {}", local_content);
1063
1064        if !local_status.is_client_error() && !local_status.is_server_error() {
1065            match serde_json::from_str::<crate::datadogV2::model::FastlyServicesResponse>(
1066                &local_content,
1067            ) {
1068                Ok(e) => {
1069                    return Ok(datadog::ResponseContent {
1070                        status: local_status,
1071                        content: local_content,
1072                        entity: Some(e),
1073                    })
1074                }
1075                Err(e) => return Err(datadog::Error::Serde(e)),
1076            };
1077        } else {
1078            let local_entity: Option<ListFastlyServicesError> =
1079                serde_json::from_str(&local_content).ok();
1080            let local_error = datadog::ResponseContent {
1081                status: local_status,
1082                content: local_content,
1083                entity: local_entity,
1084            };
1085            Err(datadog::Error::ResponseError(local_error))
1086        }
1087    }
1088
1089    /// Update a Fastly account.
1090    pub async fn update_fastly_account(
1091        &self,
1092        account_id: String,
1093        body: crate::datadogV2::model::FastlyAccountUpdateRequest,
1094    ) -> Result<
1095        crate::datadogV2::model::FastlyAccountResponse,
1096        datadog::Error<UpdateFastlyAccountError>,
1097    > {
1098        match self
1099            .update_fastly_account_with_http_info(account_id, body)
1100            .await
1101        {
1102            Ok(response_content) => {
1103                if let Some(e) = response_content.entity {
1104                    Ok(e)
1105                } else {
1106                    Err(datadog::Error::Serde(serde::de::Error::custom(
1107                        "response content was None",
1108                    )))
1109                }
1110            }
1111            Err(err) => Err(err),
1112        }
1113    }
1114
1115    /// Update a Fastly account.
1116    pub async fn update_fastly_account_with_http_info(
1117        &self,
1118        account_id: String,
1119        body: crate::datadogV2::model::FastlyAccountUpdateRequest,
1120    ) -> Result<
1121        datadog::ResponseContent<crate::datadogV2::model::FastlyAccountResponse>,
1122        datadog::Error<UpdateFastlyAccountError>,
1123    > {
1124        let local_configuration = &self.config;
1125        let operation_id = "v2.update_fastly_account";
1126
1127        let local_client = &self.client;
1128
1129        let local_uri_str = format!(
1130            "{}/api/v2/integrations/fastly/accounts/{account_id}",
1131            local_configuration.get_operation_host(operation_id),
1132            account_id = datadog::urlencode(account_id)
1133        );
1134        let mut local_req_builder =
1135            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1136
1137        // build headers
1138        let mut headers = HeaderMap::new();
1139        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1140        headers.insert("Accept", HeaderValue::from_static("application/json"));
1141
1142        // build user agent
1143        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1144            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1145            Err(e) => {
1146                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1147                headers.insert(
1148                    reqwest::header::USER_AGENT,
1149                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1150                )
1151            }
1152        };
1153
1154        // build auth
1155        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1156            headers.insert(
1157                "DD-API-KEY",
1158                HeaderValue::from_str(local_key.key.as_str())
1159                    .expect("failed to parse DD-API-KEY header"),
1160            );
1161        };
1162        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1163            headers.insert(
1164                "DD-APPLICATION-KEY",
1165                HeaderValue::from_str(local_key.key.as_str())
1166                    .expect("failed to parse DD-APPLICATION-KEY header"),
1167            );
1168        };
1169
1170        // build body parameters
1171        let output = Vec::new();
1172        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1173        if body.serialize(&mut ser).is_ok() {
1174            if let Some(content_encoding) = headers.get("Content-Encoding") {
1175                match content_encoding.to_str().unwrap_or_default() {
1176                    "gzip" => {
1177                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1178                        let _ = enc.write_all(ser.into_inner().as_slice());
1179                        match enc.finish() {
1180                            Ok(buf) => {
1181                                local_req_builder = local_req_builder.body(buf);
1182                            }
1183                            Err(e) => return Err(datadog::Error::Io(e)),
1184                        }
1185                    }
1186                    "deflate" => {
1187                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1188                        let _ = enc.write_all(ser.into_inner().as_slice());
1189                        match enc.finish() {
1190                            Ok(buf) => {
1191                                local_req_builder = local_req_builder.body(buf);
1192                            }
1193                            Err(e) => return Err(datadog::Error::Io(e)),
1194                        }
1195                    }
1196                    "zstd1" => {
1197                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1198                        let _ = enc.write_all(ser.into_inner().as_slice());
1199                        match enc.finish() {
1200                            Ok(buf) => {
1201                                local_req_builder = local_req_builder.body(buf);
1202                            }
1203                            Err(e) => return Err(datadog::Error::Io(e)),
1204                        }
1205                    }
1206                    _ => {
1207                        local_req_builder = local_req_builder.body(ser.into_inner());
1208                    }
1209                }
1210            } else {
1211                local_req_builder = local_req_builder.body(ser.into_inner());
1212            }
1213        }
1214
1215        local_req_builder = local_req_builder.headers(headers);
1216        let local_req = local_req_builder.build()?;
1217        log::debug!("request content: {:?}", local_req.body());
1218        let local_resp = local_client.execute(local_req).await?;
1219
1220        let local_status = local_resp.status();
1221        let local_content = local_resp.text().await?;
1222        log::debug!("response content: {}", local_content);
1223
1224        if !local_status.is_client_error() && !local_status.is_server_error() {
1225            match serde_json::from_str::<crate::datadogV2::model::FastlyAccountResponse>(
1226                &local_content,
1227            ) {
1228                Ok(e) => {
1229                    return Ok(datadog::ResponseContent {
1230                        status: local_status,
1231                        content: local_content,
1232                        entity: Some(e),
1233                    })
1234                }
1235                Err(e) => return Err(datadog::Error::Serde(e)),
1236            };
1237        } else {
1238            let local_entity: Option<UpdateFastlyAccountError> =
1239                serde_json::from_str(&local_content).ok();
1240            let local_error = datadog::ResponseContent {
1241                status: local_status,
1242                content: local_content,
1243                entity: local_entity,
1244            };
1245            Err(datadog::Error::ResponseError(local_error))
1246        }
1247    }
1248
1249    /// Update a Fastly service for an account.
1250    pub async fn update_fastly_service(
1251        &self,
1252        account_id: String,
1253        service_id: String,
1254        body: crate::datadogV2::model::FastlyServiceRequest,
1255    ) -> Result<
1256        crate::datadogV2::model::FastlyServiceResponse,
1257        datadog::Error<UpdateFastlyServiceError>,
1258    > {
1259        match self
1260            .update_fastly_service_with_http_info(account_id, service_id, body)
1261            .await
1262        {
1263            Ok(response_content) => {
1264                if let Some(e) = response_content.entity {
1265                    Ok(e)
1266                } else {
1267                    Err(datadog::Error::Serde(serde::de::Error::custom(
1268                        "response content was None",
1269                    )))
1270                }
1271            }
1272            Err(err) => Err(err),
1273        }
1274    }
1275
1276    /// Update a Fastly service for an account.
1277    pub async fn update_fastly_service_with_http_info(
1278        &self,
1279        account_id: String,
1280        service_id: String,
1281        body: crate::datadogV2::model::FastlyServiceRequest,
1282    ) -> Result<
1283        datadog::ResponseContent<crate::datadogV2::model::FastlyServiceResponse>,
1284        datadog::Error<UpdateFastlyServiceError>,
1285    > {
1286        let local_configuration = &self.config;
1287        let operation_id = "v2.update_fastly_service";
1288
1289        let local_client = &self.client;
1290
1291        let local_uri_str = format!(
1292            "{}/api/v2/integrations/fastly/accounts/{account_id}/services/{service_id}",
1293            local_configuration.get_operation_host(operation_id),
1294            account_id = datadog::urlencode(account_id),
1295            service_id = datadog::urlencode(service_id)
1296        );
1297        let mut local_req_builder =
1298            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1299
1300        // build headers
1301        let mut headers = HeaderMap::new();
1302        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1303        headers.insert("Accept", HeaderValue::from_static("application/json"));
1304
1305        // build user agent
1306        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1307            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1308            Err(e) => {
1309                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1310                headers.insert(
1311                    reqwest::header::USER_AGENT,
1312                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1313                )
1314            }
1315        };
1316
1317        // build auth
1318        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1319            headers.insert(
1320                "DD-API-KEY",
1321                HeaderValue::from_str(local_key.key.as_str())
1322                    .expect("failed to parse DD-API-KEY header"),
1323            );
1324        };
1325        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1326            headers.insert(
1327                "DD-APPLICATION-KEY",
1328                HeaderValue::from_str(local_key.key.as_str())
1329                    .expect("failed to parse DD-APPLICATION-KEY header"),
1330            );
1331        };
1332
1333        // build body parameters
1334        let output = Vec::new();
1335        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1336        if body.serialize(&mut ser).is_ok() {
1337            if let Some(content_encoding) = headers.get("Content-Encoding") {
1338                match content_encoding.to_str().unwrap_or_default() {
1339                    "gzip" => {
1340                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1341                        let _ = enc.write_all(ser.into_inner().as_slice());
1342                        match enc.finish() {
1343                            Ok(buf) => {
1344                                local_req_builder = local_req_builder.body(buf);
1345                            }
1346                            Err(e) => return Err(datadog::Error::Io(e)),
1347                        }
1348                    }
1349                    "deflate" => {
1350                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1351                        let _ = enc.write_all(ser.into_inner().as_slice());
1352                        match enc.finish() {
1353                            Ok(buf) => {
1354                                local_req_builder = local_req_builder.body(buf);
1355                            }
1356                            Err(e) => return Err(datadog::Error::Io(e)),
1357                        }
1358                    }
1359                    "zstd1" => {
1360                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1361                        let _ = enc.write_all(ser.into_inner().as_slice());
1362                        match enc.finish() {
1363                            Ok(buf) => {
1364                                local_req_builder = local_req_builder.body(buf);
1365                            }
1366                            Err(e) => return Err(datadog::Error::Io(e)),
1367                        }
1368                    }
1369                    _ => {
1370                        local_req_builder = local_req_builder.body(ser.into_inner());
1371                    }
1372                }
1373            } else {
1374                local_req_builder = local_req_builder.body(ser.into_inner());
1375            }
1376        }
1377
1378        local_req_builder = local_req_builder.headers(headers);
1379        let local_req = local_req_builder.build()?;
1380        log::debug!("request content: {:?}", local_req.body());
1381        let local_resp = local_client.execute(local_req).await?;
1382
1383        let local_status = local_resp.status();
1384        let local_content = local_resp.text().await?;
1385        log::debug!("response content: {}", local_content);
1386
1387        if !local_status.is_client_error() && !local_status.is_server_error() {
1388            match serde_json::from_str::<crate::datadogV2::model::FastlyServiceResponse>(
1389                &local_content,
1390            ) {
1391                Ok(e) => {
1392                    return Ok(datadog::ResponseContent {
1393                        status: local_status,
1394                        content: local_content,
1395                        entity: Some(e),
1396                    })
1397                }
1398                Err(e) => return Err(datadog::Error::Serde(e)),
1399            };
1400        } else {
1401            let local_entity: Option<UpdateFastlyServiceError> =
1402                serde_json::from_str(&local_content).ok();
1403            let local_error = datadog::ResponseContent {
1404                status: local_status,
1405                content: local_content,
1406                entity: local_entity,
1407            };
1408            Err(datadog::Error::ResponseError(local_error))
1409        }
1410    }
1411}