1use 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#[non_exhaustive]
15#[derive(Clone, Default, Debug)]
16pub struct CreateOnCallEscalationPolicyOptionalParams {
17 pub include: Option<String>,
19}
20
21impl CreateOnCallEscalationPolicyOptionalParams {
22 pub fn include(mut self, value: String) -> Self {
24 self.include = Some(value);
25 self
26 }
27}
28
29#[non_exhaustive]
31#[derive(Clone, Default, Debug)]
32pub struct CreateOnCallScheduleOptionalParams {
33 pub include: Option<String>,
35}
36
37impl CreateOnCallScheduleOptionalParams {
38 pub fn include(mut self, value: String) -> Self {
40 self.include = Some(value);
41 self
42 }
43}
44
45#[non_exhaustive]
47#[derive(Clone, Default, Debug)]
48pub struct GetOnCallEscalationPolicyOptionalParams {
49 pub include: Option<String>,
51}
52
53impl GetOnCallEscalationPolicyOptionalParams {
54 pub fn include(mut self, value: String) -> Self {
56 self.include = Some(value);
57 self
58 }
59}
60
61#[non_exhaustive]
63#[derive(Clone, Default, Debug)]
64pub struct GetOnCallScheduleOptionalParams {
65 pub include: Option<String>,
67}
68
69impl GetOnCallScheduleOptionalParams {
70 pub fn include(mut self, value: String) -> Self {
72 self.include = Some(value);
73 self
74 }
75}
76
77#[non_exhaustive]
79#[derive(Clone, Default, Debug)]
80pub struct GetOnCallTeamRoutingRulesOptionalParams {
81 pub include: Option<String>,
83}
84
85impl GetOnCallTeamRoutingRulesOptionalParams {
86 pub fn include(mut self, value: String) -> Self {
88 self.include = Some(value);
89 self
90 }
91}
92
93#[non_exhaustive]
95#[derive(Clone, Default, Debug)]
96pub struct GetScheduleOnCallUserOptionalParams {
97 pub include: Option<String>,
99 pub filter_at_ts: Option<String>,
101}
102
103impl GetScheduleOnCallUserOptionalParams {
104 pub fn include(mut self, value: String) -> Self {
106 self.include = Some(value);
107 self
108 }
109 pub fn filter_at_ts(mut self, value: String) -> Self {
111 self.filter_at_ts = Some(value);
112 self
113 }
114}
115
116#[non_exhaustive]
118#[derive(Clone, Default, Debug)]
119pub struct GetTeamOnCallUsersOptionalParams {
120 pub include: Option<String>,
122}
123
124impl GetTeamOnCallUsersOptionalParams {
125 pub fn include(mut self, value: String) -> Self {
127 self.include = Some(value);
128 self
129 }
130}
131
132#[non_exhaustive]
134#[derive(Clone, Default, Debug)]
135pub struct SetOnCallTeamRoutingRulesOptionalParams {
136 pub include: Option<String>,
138}
139
140impl SetOnCallTeamRoutingRulesOptionalParams {
141 pub fn include(mut self, value: String) -> Self {
143 self.include = Some(value);
144 self
145 }
146}
147
148#[non_exhaustive]
150#[derive(Clone, Default, Debug)]
151pub struct UpdateOnCallEscalationPolicyOptionalParams {
152 pub include: Option<String>,
154}
155
156impl UpdateOnCallEscalationPolicyOptionalParams {
157 pub fn include(mut self, value: String) -> Self {
159 self.include = Some(value);
160 self
161 }
162}
163
164#[non_exhaustive]
166#[derive(Clone, Default, Debug)]
167pub struct UpdateOnCallScheduleOptionalParams {
168 pub include: Option<String>,
170}
171
172impl UpdateOnCallScheduleOptionalParams {
173 pub fn include(mut self, value: String) -> Self {
175 self.include = Some(value);
176 self
177 }
178}
179
180#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(untagged)]
183pub enum CreateOnCallEscalationPolicyError {
184 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
185 UnknownValue(serde_json::Value),
186}
187
188#[derive(Debug, Clone, Serialize, Deserialize)]
190#[serde(untagged)]
191pub enum CreateOnCallScheduleError {
192 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
193 UnknownValue(serde_json::Value),
194}
195
196#[derive(Debug, Clone, Serialize, Deserialize)]
198#[serde(untagged)]
199pub enum DeleteOnCallEscalationPolicyError {
200 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
201 UnknownValue(serde_json::Value),
202}
203
204#[derive(Debug, Clone, Serialize, Deserialize)]
206#[serde(untagged)]
207pub enum DeleteOnCallScheduleError {
208 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
209 UnknownValue(serde_json::Value),
210}
211
212#[derive(Debug, Clone, Serialize, Deserialize)]
214#[serde(untagged)]
215pub enum GetOnCallEscalationPolicyError {
216 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
217 UnknownValue(serde_json::Value),
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize)]
222#[serde(untagged)]
223pub enum GetOnCallScheduleError {
224 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
225 UnknownValue(serde_json::Value),
226}
227
228#[derive(Debug, Clone, Serialize, Deserialize)]
230#[serde(untagged)]
231pub enum GetOnCallTeamRoutingRulesError {
232 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
233 UnknownValue(serde_json::Value),
234}
235
236#[derive(Debug, Clone, Serialize, Deserialize)]
238#[serde(untagged)]
239pub enum GetScheduleOnCallUserError {
240 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
241 UnknownValue(serde_json::Value),
242}
243
244#[derive(Debug, Clone, Serialize, Deserialize)]
246#[serde(untagged)]
247pub enum GetTeamOnCallUsersError {
248 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
249 UnknownValue(serde_json::Value),
250}
251
252#[derive(Debug, Clone, Serialize, Deserialize)]
254#[serde(untagged)]
255pub enum SetOnCallTeamRoutingRulesError {
256 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
257 UnknownValue(serde_json::Value),
258}
259
260#[derive(Debug, Clone, Serialize, Deserialize)]
262#[serde(untagged)]
263pub enum UpdateOnCallEscalationPolicyError {
264 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
265 UnknownValue(serde_json::Value),
266}
267
268#[derive(Debug, Clone, Serialize, Deserialize)]
270#[serde(untagged)]
271pub enum UpdateOnCallScheduleError {
272 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
273 UnknownValue(serde_json::Value),
274}
275
276#[derive(Debug, Clone)]
279pub struct OnCallAPI {
280 config: datadog::Configuration,
281 client: reqwest_middleware::ClientWithMiddleware,
282}
283
284impl Default for OnCallAPI {
285 fn default() -> Self {
286 Self::with_config(datadog::Configuration::default())
287 }
288}
289
290impl OnCallAPI {
291 pub fn new() -> Self {
292 Self::default()
293 }
294 pub fn with_config(config: datadog::Configuration) -> Self {
295 let mut reqwest_client_builder = reqwest::Client::builder();
296
297 if let Some(proxy_url) = &config.proxy_url {
298 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
299 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
300 }
301
302 let mut middleware_client_builder =
303 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
304
305 if config.enable_retry {
306 struct RetryableStatus;
307 impl reqwest_retry::RetryableStrategy for RetryableStatus {
308 fn handle(
309 &self,
310 res: &Result<reqwest::Response, reqwest_middleware::Error>,
311 ) -> Option<reqwest_retry::Retryable> {
312 match res {
313 Ok(success) => reqwest_retry::default_on_request_success(success),
314 Err(_) => None,
315 }
316 }
317 }
318 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
319 .build_with_max_retries(config.max_retries);
320
321 let retry_middleware =
322 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
323 backoff_policy,
324 RetryableStatus,
325 );
326
327 middleware_client_builder = middleware_client_builder.with(retry_middleware);
328 }
329
330 let client = middleware_client_builder.build();
331
332 Self { config, client }
333 }
334
335 pub fn with_client_and_config(
336 config: datadog::Configuration,
337 client: reqwest_middleware::ClientWithMiddleware,
338 ) -> Self {
339 Self { config, client }
340 }
341
342 pub async fn create_on_call_escalation_policy(
344 &self,
345 body: crate::datadogV2::model::EscalationPolicyCreateRequest,
346 params: CreateOnCallEscalationPolicyOptionalParams,
347 ) -> Result<
348 crate::datadogV2::model::EscalationPolicy,
349 datadog::Error<CreateOnCallEscalationPolicyError>,
350 > {
351 match self
352 .create_on_call_escalation_policy_with_http_info(body, params)
353 .await
354 {
355 Ok(response_content) => {
356 if let Some(e) = response_content.entity {
357 Ok(e)
358 } else {
359 Err(datadog::Error::Serde(serde::de::Error::custom(
360 "response content was None",
361 )))
362 }
363 }
364 Err(err) => Err(err),
365 }
366 }
367
368 pub async fn create_on_call_escalation_policy_with_http_info(
370 &self,
371 body: crate::datadogV2::model::EscalationPolicyCreateRequest,
372 params: CreateOnCallEscalationPolicyOptionalParams,
373 ) -> Result<
374 datadog::ResponseContent<crate::datadogV2::model::EscalationPolicy>,
375 datadog::Error<CreateOnCallEscalationPolicyError>,
376 > {
377 let local_configuration = &self.config;
378 let operation_id = "v2.create_on_call_escalation_policy";
379
380 let include = params.include;
382
383 let local_client = &self.client;
384
385 let local_uri_str = format!(
386 "{}/api/v2/on-call/escalation-policies",
387 local_configuration.get_operation_host(operation_id)
388 );
389 let mut local_req_builder =
390 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
391
392 if let Some(ref local_query_param) = include {
393 local_req_builder =
394 local_req_builder.query(&[("include", &local_query_param.to_string())]);
395 };
396
397 let mut headers = HeaderMap::new();
399 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
400 headers.insert("Accept", HeaderValue::from_static("application/json"));
401
402 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
404 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
405 Err(e) => {
406 log::warn!("Failed to parse user agent header: {e}, falling back to default");
407 headers.insert(
408 reqwest::header::USER_AGENT,
409 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
410 )
411 }
412 };
413
414 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
416 headers.insert(
417 "DD-API-KEY",
418 HeaderValue::from_str(local_key.key.as_str())
419 .expect("failed to parse DD-API-KEY header"),
420 );
421 };
422 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
423 headers.insert(
424 "DD-APPLICATION-KEY",
425 HeaderValue::from_str(local_key.key.as_str())
426 .expect("failed to parse DD-APPLICATION-KEY header"),
427 );
428 };
429
430 let output = Vec::new();
432 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
433 if body.serialize(&mut ser).is_ok() {
434 if let Some(content_encoding) = headers.get("Content-Encoding") {
435 match content_encoding.to_str().unwrap_or_default() {
436 "gzip" => {
437 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
438 let _ = enc.write_all(ser.into_inner().as_slice());
439 match enc.finish() {
440 Ok(buf) => {
441 local_req_builder = local_req_builder.body(buf);
442 }
443 Err(e) => return Err(datadog::Error::Io(e)),
444 }
445 }
446 "deflate" => {
447 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
448 let _ = enc.write_all(ser.into_inner().as_slice());
449 match enc.finish() {
450 Ok(buf) => {
451 local_req_builder = local_req_builder.body(buf);
452 }
453 Err(e) => return Err(datadog::Error::Io(e)),
454 }
455 }
456 "zstd1" => {
457 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
458 let _ = enc.write_all(ser.into_inner().as_slice());
459 match enc.finish() {
460 Ok(buf) => {
461 local_req_builder = local_req_builder.body(buf);
462 }
463 Err(e) => return Err(datadog::Error::Io(e)),
464 }
465 }
466 _ => {
467 local_req_builder = local_req_builder.body(ser.into_inner());
468 }
469 }
470 } else {
471 local_req_builder = local_req_builder.body(ser.into_inner());
472 }
473 }
474
475 local_req_builder = local_req_builder.headers(headers);
476 let local_req = local_req_builder.build()?;
477 log::debug!("request content: {:?}", local_req.body());
478 let local_resp = local_client.execute(local_req).await?;
479
480 let local_status = local_resp.status();
481 let local_content = local_resp.text().await?;
482 log::debug!("response content: {}", local_content);
483
484 if !local_status.is_client_error() && !local_status.is_server_error() {
485 match serde_json::from_str::<crate::datadogV2::model::EscalationPolicy>(&local_content)
486 {
487 Ok(e) => {
488 return Ok(datadog::ResponseContent {
489 status: local_status,
490 content: local_content,
491 entity: Some(e),
492 })
493 }
494 Err(e) => return Err(datadog::Error::Serde(e)),
495 };
496 } else {
497 let local_entity: Option<CreateOnCallEscalationPolicyError> =
498 serde_json::from_str(&local_content).ok();
499 let local_error = datadog::ResponseContent {
500 status: local_status,
501 content: local_content,
502 entity: local_entity,
503 };
504 Err(datadog::Error::ResponseError(local_error))
505 }
506 }
507
508 pub async fn create_on_call_schedule(
510 &self,
511 body: crate::datadogV2::model::ScheduleCreateRequest,
512 params: CreateOnCallScheduleOptionalParams,
513 ) -> Result<crate::datadogV2::model::Schedule, datadog::Error<CreateOnCallScheduleError>> {
514 match self
515 .create_on_call_schedule_with_http_info(body, params)
516 .await
517 {
518 Ok(response_content) => {
519 if let Some(e) = response_content.entity {
520 Ok(e)
521 } else {
522 Err(datadog::Error::Serde(serde::de::Error::custom(
523 "response content was None",
524 )))
525 }
526 }
527 Err(err) => Err(err),
528 }
529 }
530
531 pub async fn create_on_call_schedule_with_http_info(
533 &self,
534 body: crate::datadogV2::model::ScheduleCreateRequest,
535 params: CreateOnCallScheduleOptionalParams,
536 ) -> Result<
537 datadog::ResponseContent<crate::datadogV2::model::Schedule>,
538 datadog::Error<CreateOnCallScheduleError>,
539 > {
540 let local_configuration = &self.config;
541 let operation_id = "v2.create_on_call_schedule";
542
543 let include = params.include;
545
546 let local_client = &self.client;
547
548 let local_uri_str = format!(
549 "{}/api/v2/on-call/schedules",
550 local_configuration.get_operation_host(operation_id)
551 );
552 let mut local_req_builder =
553 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
554
555 if let Some(ref local_query_param) = include {
556 local_req_builder =
557 local_req_builder.query(&[("include", &local_query_param.to_string())]);
558 };
559
560 let mut headers = HeaderMap::new();
562 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
563 headers.insert("Accept", HeaderValue::from_static("application/json"));
564
565 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
567 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
568 Err(e) => {
569 log::warn!("Failed to parse user agent header: {e}, falling back to default");
570 headers.insert(
571 reqwest::header::USER_AGENT,
572 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
573 )
574 }
575 };
576
577 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
579 headers.insert(
580 "DD-API-KEY",
581 HeaderValue::from_str(local_key.key.as_str())
582 .expect("failed to parse DD-API-KEY header"),
583 );
584 };
585 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
586 headers.insert(
587 "DD-APPLICATION-KEY",
588 HeaderValue::from_str(local_key.key.as_str())
589 .expect("failed to parse DD-APPLICATION-KEY header"),
590 );
591 };
592
593 let output = Vec::new();
595 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
596 if body.serialize(&mut ser).is_ok() {
597 if let Some(content_encoding) = headers.get("Content-Encoding") {
598 match content_encoding.to_str().unwrap_or_default() {
599 "gzip" => {
600 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
601 let _ = enc.write_all(ser.into_inner().as_slice());
602 match enc.finish() {
603 Ok(buf) => {
604 local_req_builder = local_req_builder.body(buf);
605 }
606 Err(e) => return Err(datadog::Error::Io(e)),
607 }
608 }
609 "deflate" => {
610 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
611 let _ = enc.write_all(ser.into_inner().as_slice());
612 match enc.finish() {
613 Ok(buf) => {
614 local_req_builder = local_req_builder.body(buf);
615 }
616 Err(e) => return Err(datadog::Error::Io(e)),
617 }
618 }
619 "zstd1" => {
620 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
621 let _ = enc.write_all(ser.into_inner().as_slice());
622 match enc.finish() {
623 Ok(buf) => {
624 local_req_builder = local_req_builder.body(buf);
625 }
626 Err(e) => return Err(datadog::Error::Io(e)),
627 }
628 }
629 _ => {
630 local_req_builder = local_req_builder.body(ser.into_inner());
631 }
632 }
633 } else {
634 local_req_builder = local_req_builder.body(ser.into_inner());
635 }
636 }
637
638 local_req_builder = local_req_builder.headers(headers);
639 let local_req = local_req_builder.build()?;
640 log::debug!("request content: {:?}", local_req.body());
641 let local_resp = local_client.execute(local_req).await?;
642
643 let local_status = local_resp.status();
644 let local_content = local_resp.text().await?;
645 log::debug!("response content: {}", local_content);
646
647 if !local_status.is_client_error() && !local_status.is_server_error() {
648 match serde_json::from_str::<crate::datadogV2::model::Schedule>(&local_content) {
649 Ok(e) => {
650 return Ok(datadog::ResponseContent {
651 status: local_status,
652 content: local_content,
653 entity: Some(e),
654 })
655 }
656 Err(e) => return Err(datadog::Error::Serde(e)),
657 };
658 } else {
659 let local_entity: Option<CreateOnCallScheduleError> =
660 serde_json::from_str(&local_content).ok();
661 let local_error = datadog::ResponseContent {
662 status: local_status,
663 content: local_content,
664 entity: local_entity,
665 };
666 Err(datadog::Error::ResponseError(local_error))
667 }
668 }
669
670 pub async fn delete_on_call_escalation_policy(
672 &self,
673 policy_id: String,
674 ) -> Result<(), datadog::Error<DeleteOnCallEscalationPolicyError>> {
675 match self
676 .delete_on_call_escalation_policy_with_http_info(policy_id)
677 .await
678 {
679 Ok(_) => Ok(()),
680 Err(err) => Err(err),
681 }
682 }
683
684 pub async fn delete_on_call_escalation_policy_with_http_info(
686 &self,
687 policy_id: String,
688 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteOnCallEscalationPolicyError>>
689 {
690 let local_configuration = &self.config;
691 let operation_id = "v2.delete_on_call_escalation_policy";
692
693 let local_client = &self.client;
694
695 let local_uri_str = format!(
696 "{}/api/v2/on-call/escalation-policies/{policy_id}",
697 local_configuration.get_operation_host(operation_id),
698 policy_id = datadog::urlencode(policy_id)
699 );
700 let mut local_req_builder =
701 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
702
703 let mut headers = HeaderMap::new();
705 headers.insert("Accept", HeaderValue::from_static("*/*"));
706
707 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
709 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
710 Err(e) => {
711 log::warn!("Failed to parse user agent header: {e}, falling back to default");
712 headers.insert(
713 reqwest::header::USER_AGENT,
714 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
715 )
716 }
717 };
718
719 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
721 headers.insert(
722 "DD-API-KEY",
723 HeaderValue::from_str(local_key.key.as_str())
724 .expect("failed to parse DD-API-KEY header"),
725 );
726 };
727 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
728 headers.insert(
729 "DD-APPLICATION-KEY",
730 HeaderValue::from_str(local_key.key.as_str())
731 .expect("failed to parse DD-APPLICATION-KEY header"),
732 );
733 };
734
735 local_req_builder = local_req_builder.headers(headers);
736 let local_req = local_req_builder.build()?;
737 log::debug!("request content: {:?}", local_req.body());
738 let local_resp = local_client.execute(local_req).await?;
739
740 let local_status = local_resp.status();
741 let local_content = local_resp.text().await?;
742 log::debug!("response content: {}", local_content);
743
744 if !local_status.is_client_error() && !local_status.is_server_error() {
745 Ok(datadog::ResponseContent {
746 status: local_status,
747 content: local_content,
748 entity: None,
749 })
750 } else {
751 let local_entity: Option<DeleteOnCallEscalationPolicyError> =
752 serde_json::from_str(&local_content).ok();
753 let local_error = datadog::ResponseContent {
754 status: local_status,
755 content: local_content,
756 entity: local_entity,
757 };
758 Err(datadog::Error::ResponseError(local_error))
759 }
760 }
761
762 pub async fn delete_on_call_schedule(
764 &self,
765 schedule_id: String,
766 ) -> Result<(), datadog::Error<DeleteOnCallScheduleError>> {
767 match self
768 .delete_on_call_schedule_with_http_info(schedule_id)
769 .await
770 {
771 Ok(_) => Ok(()),
772 Err(err) => Err(err),
773 }
774 }
775
776 pub async fn delete_on_call_schedule_with_http_info(
778 &self,
779 schedule_id: String,
780 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteOnCallScheduleError>> {
781 let local_configuration = &self.config;
782 let operation_id = "v2.delete_on_call_schedule";
783
784 let local_client = &self.client;
785
786 let local_uri_str = format!(
787 "{}/api/v2/on-call/schedules/{schedule_id}",
788 local_configuration.get_operation_host(operation_id),
789 schedule_id = datadog::urlencode(schedule_id)
790 );
791 let mut local_req_builder =
792 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
793
794 let mut headers = HeaderMap::new();
796 headers.insert("Accept", HeaderValue::from_static("*/*"));
797
798 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
800 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
801 Err(e) => {
802 log::warn!("Failed to parse user agent header: {e}, falling back to default");
803 headers.insert(
804 reqwest::header::USER_AGENT,
805 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
806 )
807 }
808 };
809
810 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
812 headers.insert(
813 "DD-API-KEY",
814 HeaderValue::from_str(local_key.key.as_str())
815 .expect("failed to parse DD-API-KEY header"),
816 );
817 };
818 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
819 headers.insert(
820 "DD-APPLICATION-KEY",
821 HeaderValue::from_str(local_key.key.as_str())
822 .expect("failed to parse DD-APPLICATION-KEY header"),
823 );
824 };
825
826 local_req_builder = local_req_builder.headers(headers);
827 let local_req = local_req_builder.build()?;
828 log::debug!("request content: {:?}", local_req.body());
829 let local_resp = local_client.execute(local_req).await?;
830
831 let local_status = local_resp.status();
832 let local_content = local_resp.text().await?;
833 log::debug!("response content: {}", local_content);
834
835 if !local_status.is_client_error() && !local_status.is_server_error() {
836 Ok(datadog::ResponseContent {
837 status: local_status,
838 content: local_content,
839 entity: None,
840 })
841 } else {
842 let local_entity: Option<DeleteOnCallScheduleError> =
843 serde_json::from_str(&local_content).ok();
844 let local_error = datadog::ResponseContent {
845 status: local_status,
846 content: local_content,
847 entity: local_entity,
848 };
849 Err(datadog::Error::ResponseError(local_error))
850 }
851 }
852
853 pub async fn get_on_call_escalation_policy(
855 &self,
856 policy_id: String,
857 params: GetOnCallEscalationPolicyOptionalParams,
858 ) -> Result<
859 crate::datadogV2::model::EscalationPolicy,
860 datadog::Error<GetOnCallEscalationPolicyError>,
861 > {
862 match self
863 .get_on_call_escalation_policy_with_http_info(policy_id, params)
864 .await
865 {
866 Ok(response_content) => {
867 if let Some(e) = response_content.entity {
868 Ok(e)
869 } else {
870 Err(datadog::Error::Serde(serde::de::Error::custom(
871 "response content was None",
872 )))
873 }
874 }
875 Err(err) => Err(err),
876 }
877 }
878
879 pub async fn get_on_call_escalation_policy_with_http_info(
881 &self,
882 policy_id: String,
883 params: GetOnCallEscalationPolicyOptionalParams,
884 ) -> Result<
885 datadog::ResponseContent<crate::datadogV2::model::EscalationPolicy>,
886 datadog::Error<GetOnCallEscalationPolicyError>,
887 > {
888 let local_configuration = &self.config;
889 let operation_id = "v2.get_on_call_escalation_policy";
890
891 let include = params.include;
893
894 let local_client = &self.client;
895
896 let local_uri_str = format!(
897 "{}/api/v2/on-call/escalation-policies/{policy_id}",
898 local_configuration.get_operation_host(operation_id),
899 policy_id = datadog::urlencode(policy_id)
900 );
901 let mut local_req_builder =
902 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
903
904 if let Some(ref local_query_param) = include {
905 local_req_builder =
906 local_req_builder.query(&[("include", &local_query_param.to_string())]);
907 };
908
909 let mut headers = HeaderMap::new();
911 headers.insert("Accept", HeaderValue::from_static("application/json"));
912
913 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
915 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
916 Err(e) => {
917 log::warn!("Failed to parse user agent header: {e}, falling back to default");
918 headers.insert(
919 reqwest::header::USER_AGENT,
920 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
921 )
922 }
923 };
924
925 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
927 headers.insert(
928 "DD-API-KEY",
929 HeaderValue::from_str(local_key.key.as_str())
930 .expect("failed to parse DD-API-KEY header"),
931 );
932 };
933 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
934 headers.insert(
935 "DD-APPLICATION-KEY",
936 HeaderValue::from_str(local_key.key.as_str())
937 .expect("failed to parse DD-APPLICATION-KEY header"),
938 );
939 };
940
941 local_req_builder = local_req_builder.headers(headers);
942 let local_req = local_req_builder.build()?;
943 log::debug!("request content: {:?}", local_req.body());
944 let local_resp = local_client.execute(local_req).await?;
945
946 let local_status = local_resp.status();
947 let local_content = local_resp.text().await?;
948 log::debug!("response content: {}", local_content);
949
950 if !local_status.is_client_error() && !local_status.is_server_error() {
951 match serde_json::from_str::<crate::datadogV2::model::EscalationPolicy>(&local_content)
952 {
953 Ok(e) => {
954 return Ok(datadog::ResponseContent {
955 status: local_status,
956 content: local_content,
957 entity: Some(e),
958 })
959 }
960 Err(e) => return Err(datadog::Error::Serde(e)),
961 };
962 } else {
963 let local_entity: Option<GetOnCallEscalationPolicyError> =
964 serde_json::from_str(&local_content).ok();
965 let local_error = datadog::ResponseContent {
966 status: local_status,
967 content: local_content,
968 entity: local_entity,
969 };
970 Err(datadog::Error::ResponseError(local_error))
971 }
972 }
973
974 pub async fn get_on_call_schedule(
976 &self,
977 schedule_id: String,
978 params: GetOnCallScheduleOptionalParams,
979 ) -> Result<crate::datadogV2::model::Schedule, datadog::Error<GetOnCallScheduleError>> {
980 match self
981 .get_on_call_schedule_with_http_info(schedule_id, params)
982 .await
983 {
984 Ok(response_content) => {
985 if let Some(e) = response_content.entity {
986 Ok(e)
987 } else {
988 Err(datadog::Error::Serde(serde::de::Error::custom(
989 "response content was None",
990 )))
991 }
992 }
993 Err(err) => Err(err),
994 }
995 }
996
997 pub async fn get_on_call_schedule_with_http_info(
999 &self,
1000 schedule_id: String,
1001 params: GetOnCallScheduleOptionalParams,
1002 ) -> Result<
1003 datadog::ResponseContent<crate::datadogV2::model::Schedule>,
1004 datadog::Error<GetOnCallScheduleError>,
1005 > {
1006 let local_configuration = &self.config;
1007 let operation_id = "v2.get_on_call_schedule";
1008
1009 let include = params.include;
1011
1012 let local_client = &self.client;
1013
1014 let local_uri_str = format!(
1015 "{}/api/v2/on-call/schedules/{schedule_id}",
1016 local_configuration.get_operation_host(operation_id),
1017 schedule_id = datadog::urlencode(schedule_id)
1018 );
1019 let mut local_req_builder =
1020 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1021
1022 if let Some(ref local_query_param) = include {
1023 local_req_builder =
1024 local_req_builder.query(&[("include", &local_query_param.to_string())]);
1025 };
1026
1027 let mut headers = HeaderMap::new();
1029 headers.insert("Accept", HeaderValue::from_static("application/json"));
1030
1031 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1033 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1034 Err(e) => {
1035 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1036 headers.insert(
1037 reqwest::header::USER_AGENT,
1038 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1039 )
1040 }
1041 };
1042
1043 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1045 headers.insert(
1046 "DD-API-KEY",
1047 HeaderValue::from_str(local_key.key.as_str())
1048 .expect("failed to parse DD-API-KEY header"),
1049 );
1050 };
1051 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1052 headers.insert(
1053 "DD-APPLICATION-KEY",
1054 HeaderValue::from_str(local_key.key.as_str())
1055 .expect("failed to parse DD-APPLICATION-KEY header"),
1056 );
1057 };
1058
1059 local_req_builder = local_req_builder.headers(headers);
1060 let local_req = local_req_builder.build()?;
1061 log::debug!("request content: {:?}", local_req.body());
1062 let local_resp = local_client.execute(local_req).await?;
1063
1064 let local_status = local_resp.status();
1065 let local_content = local_resp.text().await?;
1066 log::debug!("response content: {}", local_content);
1067
1068 if !local_status.is_client_error() && !local_status.is_server_error() {
1069 match serde_json::from_str::<crate::datadogV2::model::Schedule>(&local_content) {
1070 Ok(e) => {
1071 return Ok(datadog::ResponseContent {
1072 status: local_status,
1073 content: local_content,
1074 entity: Some(e),
1075 })
1076 }
1077 Err(e) => return Err(datadog::Error::Serde(e)),
1078 };
1079 } else {
1080 let local_entity: Option<GetOnCallScheduleError> =
1081 serde_json::from_str(&local_content).ok();
1082 let local_error = datadog::ResponseContent {
1083 status: local_status,
1084 content: local_content,
1085 entity: local_entity,
1086 };
1087 Err(datadog::Error::ResponseError(local_error))
1088 }
1089 }
1090
1091 pub async fn get_on_call_team_routing_rules(
1093 &self,
1094 team_id: String,
1095 params: GetOnCallTeamRoutingRulesOptionalParams,
1096 ) -> Result<
1097 crate::datadogV2::model::TeamRoutingRules,
1098 datadog::Error<GetOnCallTeamRoutingRulesError>,
1099 > {
1100 match self
1101 .get_on_call_team_routing_rules_with_http_info(team_id, params)
1102 .await
1103 {
1104 Ok(response_content) => {
1105 if let Some(e) = response_content.entity {
1106 Ok(e)
1107 } else {
1108 Err(datadog::Error::Serde(serde::de::Error::custom(
1109 "response content was None",
1110 )))
1111 }
1112 }
1113 Err(err) => Err(err),
1114 }
1115 }
1116
1117 pub async fn get_on_call_team_routing_rules_with_http_info(
1119 &self,
1120 team_id: String,
1121 params: GetOnCallTeamRoutingRulesOptionalParams,
1122 ) -> Result<
1123 datadog::ResponseContent<crate::datadogV2::model::TeamRoutingRules>,
1124 datadog::Error<GetOnCallTeamRoutingRulesError>,
1125 > {
1126 let local_configuration = &self.config;
1127 let operation_id = "v2.get_on_call_team_routing_rules";
1128
1129 let include = params.include;
1131
1132 let local_client = &self.client;
1133
1134 let local_uri_str = format!(
1135 "{}/api/v2/on-call/teams/{team_id}/routing-rules",
1136 local_configuration.get_operation_host(operation_id),
1137 team_id = datadog::urlencode(team_id)
1138 );
1139 let mut local_req_builder =
1140 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1141
1142 if let Some(ref local_query_param) = include {
1143 local_req_builder =
1144 local_req_builder.query(&[("include", &local_query_param.to_string())]);
1145 };
1146
1147 let mut headers = HeaderMap::new();
1149 headers.insert("Accept", HeaderValue::from_static("application/json"));
1150
1151 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1153 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1154 Err(e) => {
1155 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1156 headers.insert(
1157 reqwest::header::USER_AGENT,
1158 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1159 )
1160 }
1161 };
1162
1163 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1165 headers.insert(
1166 "DD-API-KEY",
1167 HeaderValue::from_str(local_key.key.as_str())
1168 .expect("failed to parse DD-API-KEY header"),
1169 );
1170 };
1171 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1172 headers.insert(
1173 "DD-APPLICATION-KEY",
1174 HeaderValue::from_str(local_key.key.as_str())
1175 .expect("failed to parse DD-APPLICATION-KEY header"),
1176 );
1177 };
1178
1179 local_req_builder = local_req_builder.headers(headers);
1180 let local_req = local_req_builder.build()?;
1181 log::debug!("request content: {:?}", local_req.body());
1182 let local_resp = local_client.execute(local_req).await?;
1183
1184 let local_status = local_resp.status();
1185 let local_content = local_resp.text().await?;
1186 log::debug!("response content: {}", local_content);
1187
1188 if !local_status.is_client_error() && !local_status.is_server_error() {
1189 match serde_json::from_str::<crate::datadogV2::model::TeamRoutingRules>(&local_content)
1190 {
1191 Ok(e) => {
1192 return Ok(datadog::ResponseContent {
1193 status: local_status,
1194 content: local_content,
1195 entity: Some(e),
1196 })
1197 }
1198 Err(e) => return Err(datadog::Error::Serde(e)),
1199 };
1200 } else {
1201 let local_entity: Option<GetOnCallTeamRoutingRulesError> =
1202 serde_json::from_str(&local_content).ok();
1203 let local_error = datadog::ResponseContent {
1204 status: local_status,
1205 content: local_content,
1206 entity: local_entity,
1207 };
1208 Err(datadog::Error::ResponseError(local_error))
1209 }
1210 }
1211
1212 pub async fn get_schedule_on_call_user(
1214 &self,
1215 schedule_id: String,
1216 params: GetScheduleOnCallUserOptionalParams,
1217 ) -> Result<crate::datadogV2::model::Shift, datadog::Error<GetScheduleOnCallUserError>> {
1218 match self
1219 .get_schedule_on_call_user_with_http_info(schedule_id, params)
1220 .await
1221 {
1222 Ok(response_content) => {
1223 if let Some(e) = response_content.entity {
1224 Ok(e)
1225 } else {
1226 Err(datadog::Error::Serde(serde::de::Error::custom(
1227 "response content was None",
1228 )))
1229 }
1230 }
1231 Err(err) => Err(err),
1232 }
1233 }
1234
1235 pub async fn get_schedule_on_call_user_with_http_info(
1237 &self,
1238 schedule_id: String,
1239 params: GetScheduleOnCallUserOptionalParams,
1240 ) -> Result<
1241 datadog::ResponseContent<crate::datadogV2::model::Shift>,
1242 datadog::Error<GetScheduleOnCallUserError>,
1243 > {
1244 let local_configuration = &self.config;
1245 let operation_id = "v2.get_schedule_on_call_user";
1246
1247 let include = params.include;
1249 let filter_at_ts = params.filter_at_ts;
1250
1251 let local_client = &self.client;
1252
1253 let local_uri_str = format!(
1254 "{}/api/v2/on-call/schedules/{schedule_id}/on-call",
1255 local_configuration.get_operation_host(operation_id),
1256 schedule_id = datadog::urlencode(schedule_id)
1257 );
1258 let mut local_req_builder =
1259 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1260
1261 if let Some(ref local_query_param) = include {
1262 local_req_builder =
1263 local_req_builder.query(&[("include", &local_query_param.to_string())]);
1264 };
1265 if let Some(ref local_query_param) = filter_at_ts {
1266 local_req_builder =
1267 local_req_builder.query(&[("filter[at_ts]", &local_query_param.to_string())]);
1268 };
1269
1270 let mut headers = HeaderMap::new();
1272 headers.insert("Accept", HeaderValue::from_static("application/json"));
1273
1274 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1276 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1277 Err(e) => {
1278 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1279 headers.insert(
1280 reqwest::header::USER_AGENT,
1281 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1282 )
1283 }
1284 };
1285
1286 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1288 headers.insert(
1289 "DD-API-KEY",
1290 HeaderValue::from_str(local_key.key.as_str())
1291 .expect("failed to parse DD-API-KEY header"),
1292 );
1293 };
1294 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1295 headers.insert(
1296 "DD-APPLICATION-KEY",
1297 HeaderValue::from_str(local_key.key.as_str())
1298 .expect("failed to parse DD-APPLICATION-KEY header"),
1299 );
1300 };
1301
1302 local_req_builder = local_req_builder.headers(headers);
1303 let local_req = local_req_builder.build()?;
1304 log::debug!("request content: {:?}", local_req.body());
1305 let local_resp = local_client.execute(local_req).await?;
1306
1307 let local_status = local_resp.status();
1308 let local_content = local_resp.text().await?;
1309 log::debug!("response content: {}", local_content);
1310
1311 if !local_status.is_client_error() && !local_status.is_server_error() {
1312 match serde_json::from_str::<crate::datadogV2::model::Shift>(&local_content) {
1313 Ok(e) => {
1314 return Ok(datadog::ResponseContent {
1315 status: local_status,
1316 content: local_content,
1317 entity: Some(e),
1318 })
1319 }
1320 Err(e) => return Err(datadog::Error::Serde(e)),
1321 };
1322 } else {
1323 let local_entity: Option<GetScheduleOnCallUserError> =
1324 serde_json::from_str(&local_content).ok();
1325 let local_error = datadog::ResponseContent {
1326 status: local_status,
1327 content: local_content,
1328 entity: local_entity,
1329 };
1330 Err(datadog::Error::ResponseError(local_error))
1331 }
1332 }
1333
1334 pub async fn get_team_on_call_users(
1336 &self,
1337 team_id: String,
1338 params: GetTeamOnCallUsersOptionalParams,
1339 ) -> Result<
1340 crate::datadogV2::model::TeamOnCallResponders,
1341 datadog::Error<GetTeamOnCallUsersError>,
1342 > {
1343 match self
1344 .get_team_on_call_users_with_http_info(team_id, params)
1345 .await
1346 {
1347 Ok(response_content) => {
1348 if let Some(e) = response_content.entity {
1349 Ok(e)
1350 } else {
1351 Err(datadog::Error::Serde(serde::de::Error::custom(
1352 "response content was None",
1353 )))
1354 }
1355 }
1356 Err(err) => Err(err),
1357 }
1358 }
1359
1360 pub async fn get_team_on_call_users_with_http_info(
1362 &self,
1363 team_id: String,
1364 params: GetTeamOnCallUsersOptionalParams,
1365 ) -> Result<
1366 datadog::ResponseContent<crate::datadogV2::model::TeamOnCallResponders>,
1367 datadog::Error<GetTeamOnCallUsersError>,
1368 > {
1369 let local_configuration = &self.config;
1370 let operation_id = "v2.get_team_on_call_users";
1371
1372 let include = params.include;
1374
1375 let local_client = &self.client;
1376
1377 let local_uri_str = format!(
1378 "{}/api/v2/on-call/teams/{team_id}/on-call",
1379 local_configuration.get_operation_host(operation_id),
1380 team_id = datadog::urlencode(team_id)
1381 );
1382 let mut local_req_builder =
1383 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1384
1385 if let Some(ref local_query_param) = include {
1386 local_req_builder =
1387 local_req_builder.query(&[("include", &local_query_param.to_string())]);
1388 };
1389
1390 let mut headers = HeaderMap::new();
1392 headers.insert("Accept", HeaderValue::from_static("application/json"));
1393
1394 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1396 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1397 Err(e) => {
1398 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1399 headers.insert(
1400 reqwest::header::USER_AGENT,
1401 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1402 )
1403 }
1404 };
1405
1406 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1408 headers.insert(
1409 "DD-API-KEY",
1410 HeaderValue::from_str(local_key.key.as_str())
1411 .expect("failed to parse DD-API-KEY header"),
1412 );
1413 };
1414 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1415 headers.insert(
1416 "DD-APPLICATION-KEY",
1417 HeaderValue::from_str(local_key.key.as_str())
1418 .expect("failed to parse DD-APPLICATION-KEY header"),
1419 );
1420 };
1421
1422 local_req_builder = local_req_builder.headers(headers);
1423 let local_req = local_req_builder.build()?;
1424 log::debug!("request content: {:?}", local_req.body());
1425 let local_resp = local_client.execute(local_req).await?;
1426
1427 let local_status = local_resp.status();
1428 let local_content = local_resp.text().await?;
1429 log::debug!("response content: {}", local_content);
1430
1431 if !local_status.is_client_error() && !local_status.is_server_error() {
1432 match serde_json::from_str::<crate::datadogV2::model::TeamOnCallResponders>(
1433 &local_content,
1434 ) {
1435 Ok(e) => {
1436 return Ok(datadog::ResponseContent {
1437 status: local_status,
1438 content: local_content,
1439 entity: Some(e),
1440 })
1441 }
1442 Err(e) => return Err(datadog::Error::Serde(e)),
1443 };
1444 } else {
1445 let local_entity: Option<GetTeamOnCallUsersError> =
1446 serde_json::from_str(&local_content).ok();
1447 let local_error = datadog::ResponseContent {
1448 status: local_status,
1449 content: local_content,
1450 entity: local_entity,
1451 };
1452 Err(datadog::Error::ResponseError(local_error))
1453 }
1454 }
1455
1456 pub async fn set_on_call_team_routing_rules(
1458 &self,
1459 team_id: String,
1460 body: crate::datadogV2::model::TeamRoutingRulesRequest,
1461 params: SetOnCallTeamRoutingRulesOptionalParams,
1462 ) -> Result<
1463 crate::datadogV2::model::TeamRoutingRules,
1464 datadog::Error<SetOnCallTeamRoutingRulesError>,
1465 > {
1466 match self
1467 .set_on_call_team_routing_rules_with_http_info(team_id, body, params)
1468 .await
1469 {
1470 Ok(response_content) => {
1471 if let Some(e) = response_content.entity {
1472 Ok(e)
1473 } else {
1474 Err(datadog::Error::Serde(serde::de::Error::custom(
1475 "response content was None",
1476 )))
1477 }
1478 }
1479 Err(err) => Err(err),
1480 }
1481 }
1482
1483 pub async fn set_on_call_team_routing_rules_with_http_info(
1485 &self,
1486 team_id: String,
1487 body: crate::datadogV2::model::TeamRoutingRulesRequest,
1488 params: SetOnCallTeamRoutingRulesOptionalParams,
1489 ) -> Result<
1490 datadog::ResponseContent<crate::datadogV2::model::TeamRoutingRules>,
1491 datadog::Error<SetOnCallTeamRoutingRulesError>,
1492 > {
1493 let local_configuration = &self.config;
1494 let operation_id = "v2.set_on_call_team_routing_rules";
1495
1496 let include = params.include;
1498
1499 let local_client = &self.client;
1500
1501 let local_uri_str = format!(
1502 "{}/api/v2/on-call/teams/{team_id}/routing-rules",
1503 local_configuration.get_operation_host(operation_id),
1504 team_id = datadog::urlencode(team_id)
1505 );
1506 let mut local_req_builder =
1507 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
1508
1509 if let Some(ref local_query_param) = include {
1510 local_req_builder =
1511 local_req_builder.query(&[("include", &local_query_param.to_string())]);
1512 };
1513
1514 let mut headers = HeaderMap::new();
1516 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1517 headers.insert("Accept", HeaderValue::from_static("application/json"));
1518
1519 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1521 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1522 Err(e) => {
1523 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1524 headers.insert(
1525 reqwest::header::USER_AGENT,
1526 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1527 )
1528 }
1529 };
1530
1531 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1533 headers.insert(
1534 "DD-API-KEY",
1535 HeaderValue::from_str(local_key.key.as_str())
1536 .expect("failed to parse DD-API-KEY header"),
1537 );
1538 };
1539 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1540 headers.insert(
1541 "DD-APPLICATION-KEY",
1542 HeaderValue::from_str(local_key.key.as_str())
1543 .expect("failed to parse DD-APPLICATION-KEY header"),
1544 );
1545 };
1546
1547 let output = Vec::new();
1549 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1550 if body.serialize(&mut ser).is_ok() {
1551 if let Some(content_encoding) = headers.get("Content-Encoding") {
1552 match content_encoding.to_str().unwrap_or_default() {
1553 "gzip" => {
1554 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1555 let _ = enc.write_all(ser.into_inner().as_slice());
1556 match enc.finish() {
1557 Ok(buf) => {
1558 local_req_builder = local_req_builder.body(buf);
1559 }
1560 Err(e) => return Err(datadog::Error::Io(e)),
1561 }
1562 }
1563 "deflate" => {
1564 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1565 let _ = enc.write_all(ser.into_inner().as_slice());
1566 match enc.finish() {
1567 Ok(buf) => {
1568 local_req_builder = local_req_builder.body(buf);
1569 }
1570 Err(e) => return Err(datadog::Error::Io(e)),
1571 }
1572 }
1573 "zstd1" => {
1574 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1575 let _ = enc.write_all(ser.into_inner().as_slice());
1576 match enc.finish() {
1577 Ok(buf) => {
1578 local_req_builder = local_req_builder.body(buf);
1579 }
1580 Err(e) => return Err(datadog::Error::Io(e)),
1581 }
1582 }
1583 _ => {
1584 local_req_builder = local_req_builder.body(ser.into_inner());
1585 }
1586 }
1587 } else {
1588 local_req_builder = local_req_builder.body(ser.into_inner());
1589 }
1590 }
1591
1592 local_req_builder = local_req_builder.headers(headers);
1593 let local_req = local_req_builder.build()?;
1594 log::debug!("request content: {:?}", local_req.body());
1595 let local_resp = local_client.execute(local_req).await?;
1596
1597 let local_status = local_resp.status();
1598 let local_content = local_resp.text().await?;
1599 log::debug!("response content: {}", local_content);
1600
1601 if !local_status.is_client_error() && !local_status.is_server_error() {
1602 match serde_json::from_str::<crate::datadogV2::model::TeamRoutingRules>(&local_content)
1603 {
1604 Ok(e) => {
1605 return Ok(datadog::ResponseContent {
1606 status: local_status,
1607 content: local_content,
1608 entity: Some(e),
1609 })
1610 }
1611 Err(e) => return Err(datadog::Error::Serde(e)),
1612 };
1613 } else {
1614 let local_entity: Option<SetOnCallTeamRoutingRulesError> =
1615 serde_json::from_str(&local_content).ok();
1616 let local_error = datadog::ResponseContent {
1617 status: local_status,
1618 content: local_content,
1619 entity: local_entity,
1620 };
1621 Err(datadog::Error::ResponseError(local_error))
1622 }
1623 }
1624
1625 pub async fn update_on_call_escalation_policy(
1627 &self,
1628 policy_id: String,
1629 body: crate::datadogV2::model::EscalationPolicyUpdateRequest,
1630 params: UpdateOnCallEscalationPolicyOptionalParams,
1631 ) -> Result<
1632 crate::datadogV2::model::EscalationPolicy,
1633 datadog::Error<UpdateOnCallEscalationPolicyError>,
1634 > {
1635 match self
1636 .update_on_call_escalation_policy_with_http_info(policy_id, body, params)
1637 .await
1638 {
1639 Ok(response_content) => {
1640 if let Some(e) = response_content.entity {
1641 Ok(e)
1642 } else {
1643 Err(datadog::Error::Serde(serde::de::Error::custom(
1644 "response content was None",
1645 )))
1646 }
1647 }
1648 Err(err) => Err(err),
1649 }
1650 }
1651
1652 pub async fn update_on_call_escalation_policy_with_http_info(
1654 &self,
1655 policy_id: String,
1656 body: crate::datadogV2::model::EscalationPolicyUpdateRequest,
1657 params: UpdateOnCallEscalationPolicyOptionalParams,
1658 ) -> Result<
1659 datadog::ResponseContent<crate::datadogV2::model::EscalationPolicy>,
1660 datadog::Error<UpdateOnCallEscalationPolicyError>,
1661 > {
1662 let local_configuration = &self.config;
1663 let operation_id = "v2.update_on_call_escalation_policy";
1664
1665 let include = params.include;
1667
1668 let local_client = &self.client;
1669
1670 let local_uri_str = format!(
1671 "{}/api/v2/on-call/escalation-policies/{policy_id}",
1672 local_configuration.get_operation_host(operation_id),
1673 policy_id = datadog::urlencode(policy_id)
1674 );
1675 let mut local_req_builder =
1676 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
1677
1678 if let Some(ref local_query_param) = include {
1679 local_req_builder =
1680 local_req_builder.query(&[("include", &local_query_param.to_string())]);
1681 };
1682
1683 let mut headers = HeaderMap::new();
1685 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1686 headers.insert("Accept", HeaderValue::from_static("application/json"));
1687
1688 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1690 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1691 Err(e) => {
1692 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1693 headers.insert(
1694 reqwest::header::USER_AGENT,
1695 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1696 )
1697 }
1698 };
1699
1700 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1702 headers.insert(
1703 "DD-API-KEY",
1704 HeaderValue::from_str(local_key.key.as_str())
1705 .expect("failed to parse DD-API-KEY header"),
1706 );
1707 };
1708 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1709 headers.insert(
1710 "DD-APPLICATION-KEY",
1711 HeaderValue::from_str(local_key.key.as_str())
1712 .expect("failed to parse DD-APPLICATION-KEY header"),
1713 );
1714 };
1715
1716 let output = Vec::new();
1718 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1719 if body.serialize(&mut ser).is_ok() {
1720 if let Some(content_encoding) = headers.get("Content-Encoding") {
1721 match content_encoding.to_str().unwrap_or_default() {
1722 "gzip" => {
1723 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1724 let _ = enc.write_all(ser.into_inner().as_slice());
1725 match enc.finish() {
1726 Ok(buf) => {
1727 local_req_builder = local_req_builder.body(buf);
1728 }
1729 Err(e) => return Err(datadog::Error::Io(e)),
1730 }
1731 }
1732 "deflate" => {
1733 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1734 let _ = enc.write_all(ser.into_inner().as_slice());
1735 match enc.finish() {
1736 Ok(buf) => {
1737 local_req_builder = local_req_builder.body(buf);
1738 }
1739 Err(e) => return Err(datadog::Error::Io(e)),
1740 }
1741 }
1742 "zstd1" => {
1743 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1744 let _ = enc.write_all(ser.into_inner().as_slice());
1745 match enc.finish() {
1746 Ok(buf) => {
1747 local_req_builder = local_req_builder.body(buf);
1748 }
1749 Err(e) => return Err(datadog::Error::Io(e)),
1750 }
1751 }
1752 _ => {
1753 local_req_builder = local_req_builder.body(ser.into_inner());
1754 }
1755 }
1756 } else {
1757 local_req_builder = local_req_builder.body(ser.into_inner());
1758 }
1759 }
1760
1761 local_req_builder = local_req_builder.headers(headers);
1762 let local_req = local_req_builder.build()?;
1763 log::debug!("request content: {:?}", local_req.body());
1764 let local_resp = local_client.execute(local_req).await?;
1765
1766 let local_status = local_resp.status();
1767 let local_content = local_resp.text().await?;
1768 log::debug!("response content: {}", local_content);
1769
1770 if !local_status.is_client_error() && !local_status.is_server_error() {
1771 match serde_json::from_str::<crate::datadogV2::model::EscalationPolicy>(&local_content)
1772 {
1773 Ok(e) => {
1774 return Ok(datadog::ResponseContent {
1775 status: local_status,
1776 content: local_content,
1777 entity: Some(e),
1778 })
1779 }
1780 Err(e) => return Err(datadog::Error::Serde(e)),
1781 };
1782 } else {
1783 let local_entity: Option<UpdateOnCallEscalationPolicyError> =
1784 serde_json::from_str(&local_content).ok();
1785 let local_error = datadog::ResponseContent {
1786 status: local_status,
1787 content: local_content,
1788 entity: local_entity,
1789 };
1790 Err(datadog::Error::ResponseError(local_error))
1791 }
1792 }
1793
1794 pub async fn update_on_call_schedule(
1796 &self,
1797 schedule_id: String,
1798 body: crate::datadogV2::model::ScheduleUpdateRequest,
1799 params: UpdateOnCallScheduleOptionalParams,
1800 ) -> Result<crate::datadogV2::model::Schedule, datadog::Error<UpdateOnCallScheduleError>> {
1801 match self
1802 .update_on_call_schedule_with_http_info(schedule_id, body, params)
1803 .await
1804 {
1805 Ok(response_content) => {
1806 if let Some(e) = response_content.entity {
1807 Ok(e)
1808 } else {
1809 Err(datadog::Error::Serde(serde::de::Error::custom(
1810 "response content was None",
1811 )))
1812 }
1813 }
1814 Err(err) => Err(err),
1815 }
1816 }
1817
1818 pub async fn update_on_call_schedule_with_http_info(
1820 &self,
1821 schedule_id: String,
1822 body: crate::datadogV2::model::ScheduleUpdateRequest,
1823 params: UpdateOnCallScheduleOptionalParams,
1824 ) -> Result<
1825 datadog::ResponseContent<crate::datadogV2::model::Schedule>,
1826 datadog::Error<UpdateOnCallScheduleError>,
1827 > {
1828 let local_configuration = &self.config;
1829 let operation_id = "v2.update_on_call_schedule";
1830
1831 let include = params.include;
1833
1834 let local_client = &self.client;
1835
1836 let local_uri_str = format!(
1837 "{}/api/v2/on-call/schedules/{schedule_id}",
1838 local_configuration.get_operation_host(operation_id),
1839 schedule_id = datadog::urlencode(schedule_id)
1840 );
1841 let mut local_req_builder =
1842 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
1843
1844 if let Some(ref local_query_param) = include {
1845 local_req_builder =
1846 local_req_builder.query(&[("include", &local_query_param.to_string())]);
1847 };
1848
1849 let mut headers = HeaderMap::new();
1851 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1852 headers.insert("Accept", HeaderValue::from_static("application/json"));
1853
1854 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1856 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1857 Err(e) => {
1858 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1859 headers.insert(
1860 reqwest::header::USER_AGENT,
1861 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1862 )
1863 }
1864 };
1865
1866 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1868 headers.insert(
1869 "DD-API-KEY",
1870 HeaderValue::from_str(local_key.key.as_str())
1871 .expect("failed to parse DD-API-KEY header"),
1872 );
1873 };
1874 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1875 headers.insert(
1876 "DD-APPLICATION-KEY",
1877 HeaderValue::from_str(local_key.key.as_str())
1878 .expect("failed to parse DD-APPLICATION-KEY header"),
1879 );
1880 };
1881
1882 let output = Vec::new();
1884 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1885 if body.serialize(&mut ser).is_ok() {
1886 if let Some(content_encoding) = headers.get("Content-Encoding") {
1887 match content_encoding.to_str().unwrap_or_default() {
1888 "gzip" => {
1889 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1890 let _ = enc.write_all(ser.into_inner().as_slice());
1891 match enc.finish() {
1892 Ok(buf) => {
1893 local_req_builder = local_req_builder.body(buf);
1894 }
1895 Err(e) => return Err(datadog::Error::Io(e)),
1896 }
1897 }
1898 "deflate" => {
1899 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1900 let _ = enc.write_all(ser.into_inner().as_slice());
1901 match enc.finish() {
1902 Ok(buf) => {
1903 local_req_builder = local_req_builder.body(buf);
1904 }
1905 Err(e) => return Err(datadog::Error::Io(e)),
1906 }
1907 }
1908 "zstd1" => {
1909 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1910 let _ = enc.write_all(ser.into_inner().as_slice());
1911 match enc.finish() {
1912 Ok(buf) => {
1913 local_req_builder = local_req_builder.body(buf);
1914 }
1915 Err(e) => return Err(datadog::Error::Io(e)),
1916 }
1917 }
1918 _ => {
1919 local_req_builder = local_req_builder.body(ser.into_inner());
1920 }
1921 }
1922 } else {
1923 local_req_builder = local_req_builder.body(ser.into_inner());
1924 }
1925 }
1926
1927 local_req_builder = local_req_builder.headers(headers);
1928 let local_req = local_req_builder.build()?;
1929 log::debug!("request content: {:?}", local_req.body());
1930 let local_resp = local_client.execute(local_req).await?;
1931
1932 let local_status = local_resp.status();
1933 let local_content = local_resp.text().await?;
1934 log::debug!("response content: {}", local_content);
1935
1936 if !local_status.is_client_error() && !local_status.is_server_error() {
1937 match serde_json::from_str::<crate::datadogV2::model::Schedule>(&local_content) {
1938 Ok(e) => {
1939 return Ok(datadog::ResponseContent {
1940 status: local_status,
1941 content: local_content,
1942 entity: Some(e),
1943 })
1944 }
1945 Err(e) => return Err(datadog::Error::Serde(e)),
1946 };
1947 } else {
1948 let local_entity: Option<UpdateOnCallScheduleError> =
1949 serde_json::from_str(&local_content).ok();
1950 let local_error = datadog::ResponseContent {
1951 status: local_status,
1952 content: local_content,
1953 entity: local_entity,
1954 };
1955 Err(datadog::Error::ResponseError(local_error))
1956 }
1957 }
1958}