svix_webhook_with_clone/api/
statistics.rs

1use super::PostOptions;
2use crate::{apis::statistics_api, error::Result, models::*, Configuration};
3
4pub struct Statistics<'a> {
5    cfg: &'a Configuration,
6}
7
8pub struct AggregateAppStatsOptions {
9    pub app_ids: Option<Vec<String>>,
10    pub since: String,
11    pub until: String,
12}
13
14impl<'a> Statistics<'a> {
15    pub(super) fn new(cfg: &'a Configuration) -> Self {
16        Self { cfg }
17    }
18
19    /// Creates a background task to calculate the message destinations for all
20    /// applications in the environment.
21    ///
22    /// Note that this endpoint is asynchronous. You will need to poll the `Get
23    /// Background Task` endpoint to retrieve the results of the operation.
24    pub async fn aggregate_app_stats(
25        &self,
26        AggregateAppStatsOptions {
27            app_ids,
28            since,
29            until,
30        }: AggregateAppStatsOptions,
31        options: Option<PostOptions>,
32    ) -> Result<AppUsageStatsOut> {
33        let options = options.unwrap_or_default();
34        let params = statistics_api::V1PeriodStatisticsPeriodAggregateAppStatsParams {
35            app_usage_stats_in: AppUsageStatsIn {
36                app_ids,
37                since,
38                until,
39            },
40            idempotency_key: options.idempotency_key,
41        };
42        statistics_api::v1_period_statistics_period_aggregate_app_stats(self.cfg, params).await
43    }
44
45    /// Creates a background task to calculate the listed event types for all
46    /// apps in the organization.
47    ///
48    /// Note that this endpoint is asynchronous. You will need to poll the `Get
49    /// Background Task` endpoint to retrieve the results of the operation.
50    pub async fn aggregate_event_types(&self) -> Result<AggregateEventTypesOut> {
51        statistics_api::v1_period_statistics_period_aggregate_event_types(self.cfg).await
52    }
53}