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