sendgrid_api/
subuser_statistics.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct SubuserStatistics {
5    pub client: Client,
6}
7
8impl SubuserStatistics {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        SubuserStatistics { client }
12    }
13
14    /**
15     * Retrieve the monthly email statistics for a single subuser.
16     *
17     * This function performs a `GET` to the `/subusers/{subuser_name}/stats/monthly` endpoint.
18     *
19     * **This endpoint allows you to retrive the monthly email statistics for a specific subuser.**
20     *
21     * When using the `sort_by_metric` to sort your stats by a specific metric, you can not sort by the following metrics:
22     * `bounce_drops`, `deferred`, `invalid_emails`, `processed`, `spam_report_drops`, `spam_reports`, or `unsubscribe_drops`.
23     *
24     * **Parameters:**
25     *
26     * * `date: &str` -- The date of the month to retrieve statistics for. Must be formatted YYYY-MM-DD.
27     * * `sort_by_metric: &str` -- The metric that you want to sort by. Metrics that you can sort by are: `blocks`, `bounces`, `clicks`, `delivered`, `opens`, `requests`, `unique_clicks`, `unique_opens`, and `unsubscribes`.'.
28     * * `sort_by_direction: crate::types::SortByDirection` -- The direction you want to sort.
29     * * `limit: i64` -- Optional field to limit the number of results returned.
30     * * `offset: i64` -- Optional beginning point in the list to retrieve from.
31     */
32    pub async fn get_subusers_subuser_name_stats_monthly(
33        &self,
34        subuser_name: &str,
35        date: &str,
36        sort_by_metric: &str,
37        sort_by_direction: crate::types::SortByDirection,
38        limit: i64,
39        offset: i64,
40    ) -> ClientResult<crate::Response<crate::types::SubuserStatsData>> {
41        let mut query_args: Vec<(String, String)> = Default::default();
42        if !date.is_empty() {
43            query_args.push(("date".to_string(), date.to_string()));
44        }
45        if limit > 0 {
46            query_args.push(("limit".to_string(), limit.to_string()));
47        }
48        if offset > 0 {
49            query_args.push(("offset".to_string(), offset.to_string()));
50        }
51        if !sort_by_direction.to_string().is_empty() {
52            query_args.push((
53                "sort_by_direction".to_string(),
54                sort_by_direction.to_string(),
55            ));
56        }
57        if !sort_by_metric.is_empty() {
58            query_args.push(("sort_by_metric".to_string(), sort_by_metric.to_string()));
59        }
60        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
61        let url = self.client.url(
62            &format!(
63                "/subusers/{}/stats/monthly?{}",
64                crate::progenitor_support::encode_path(subuser_name),
65                query_
66            ),
67            None,
68        );
69        self.client
70            .get(
71                &url,
72                crate::Message {
73                    body: None,
74                    content_type: None,
75                },
76            )
77            .await
78    }
79    /**
80     * Retrieve monthly stats for all subusers.
81     *
82     * This function performs a `GET` to the `/subusers/stats/monthly` endpoint.
83     *
84     * **This endpoint allows you to retrieve the monthly email statistics for all subusers over the given date range.**
85     *
86     * When using the `sort_by_metric` to sort your stats by a specific metric, you can not sort by the following metrics:
87     * `bounce_drops`, `deferred`, `invalid_emails`, `processed`, `spam_report_drops`, `spam_reports`, or `unsubscribe_drops`.
88     *
89     * **Parameters:**
90     *
91     * * `date: &str` -- The date of the month to retrieve statistics for. Must be formatted YYYY-MM-DD.
92     * * `subuser: &str` -- The license key provided with your New Relic account.
93     * * `sort_by_metric: crate::types::SortByMetric` -- The metric that you want to sort by. Metrics that you can sort by are: `blocks`, `bounces`, `clicks`, `delivered`, `opens`, `requests`, `unique_clicks`, `unique_opens`, and `unsubscribes`.'.
94     * * `sort_by_direction: crate::types::SortByDirection` -- The direction you want to sort.
95     * * `limit: i64` -- Optional field to limit the number of results returned.
96     * * `offset: i64` -- Optional beginning point in the list to retrieve from.
97     */
98    pub async fn get_subusers_stats_monthly(
99        &self,
100        date: &str,
101        subuser: &str,
102        sort_by_metric: crate::types::SortByMetric,
103        sort_by_direction: crate::types::SortByDirection,
104        limit: i64,
105        offset: i64,
106    ) -> ClientResult<crate::Response<crate::types::SubuserStatsData>> {
107        let mut query_args: Vec<(String, String)> = Default::default();
108        if !date.is_empty() {
109            query_args.push(("date".to_string(), date.to_string()));
110        }
111        if limit > 0 {
112            query_args.push(("limit".to_string(), limit.to_string()));
113        }
114        if offset > 0 {
115            query_args.push(("offset".to_string(), offset.to_string()));
116        }
117        if !sort_by_direction.to_string().is_empty() {
118            query_args.push((
119                "sort_by_direction".to_string(),
120                sort_by_direction.to_string(),
121            ));
122        }
123        if !sort_by_metric.to_string().is_empty() {
124            query_args.push(("sort_by_metric".to_string(), sort_by_metric.to_string()));
125        }
126        if !subuser.is_empty() {
127            query_args.push(("subuser".to_string(), subuser.to_string()));
128        }
129        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
130        let url = self
131            .client
132            .url(&format!("/subusers/stats/monthly?{}", query_), None);
133        self.client
134            .get(
135                &url,
136                crate::Message {
137                    body: None,
138                    content_type: None,
139                },
140            )
141            .await
142    }
143    /**
144     * Retrieve the totals for each email statistic metric for all subusers.
145     *
146     * This function performs a `GET` to the `/subusers/stats/sums` endpoint.
147     *
148     * **This endpoint allows you to retrieve the total sums of each email statistic metric for all subusers over the given date range.**
149     *
150     * **Parameters:**
151     *
152     * * `sort_by_direction: crate::types::SortByDirection` -- The direction you want to sort.
153     * * `start_date: &str` -- The starting date of the statistics to retrieve. Must follow format YYYY-MM-DD.
154     * * `end_date: &str` -- The end date of the statistics to retrieve. Defaults to today. Must follow format YYYY-MM-DD.
155     * * `limit: i64` -- Limits the number of results returned per page.
156     * * `offset: i64` -- The point in the list to begin retrieving results from.
157     * * `aggregated_by: &str` -- How to group the statistics. Defaults to today. Must follow format YYYY-MM-DD.
158     * * `sort_by_metric: &str` -- The metric that you want to sort by.  Must be a single metric.
159     */
160    pub async fn get_subusers_stats_sum(
161        &self,
162        sort_by_direction: crate::types::SortByDirection,
163        start_date: &str,
164        end_date: &str,
165        limit: i64,
166        offset: i64,
167        aggregated_by: &str,
168        sort_by_metric: &str,
169    ) -> ClientResult<crate::Response<crate::types::CategoryStats>> {
170        let mut query_args: Vec<(String, String)> = Default::default();
171        if !aggregated_by.is_empty() {
172            query_args.push(("aggregated_by".to_string(), aggregated_by.to_string()));
173        }
174        if !end_date.is_empty() {
175            query_args.push(("end_date".to_string(), end_date.to_string()));
176        }
177        if limit > 0 {
178            query_args.push(("limit".to_string(), limit.to_string()));
179        }
180        if offset > 0 {
181            query_args.push(("offset".to_string(), offset.to_string()));
182        }
183        if !sort_by_direction.to_string().is_empty() {
184            query_args.push((
185                "sort_by_direction".to_string(),
186                sort_by_direction.to_string(),
187            ));
188        }
189        if !sort_by_metric.is_empty() {
190            query_args.push(("sort_by_metric".to_string(), sort_by_metric.to_string()));
191        }
192        if !start_date.is_empty() {
193            query_args.push(("start_date".to_string(), start_date.to_string()));
194        }
195        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
196        let url = self
197            .client
198            .url(&format!("/subusers/stats/sums?{}", query_), None);
199        self.client
200            .get(
201                &url,
202                crate::Message {
203                    body: None,
204                    content_type: None,
205                },
206            )
207            .await
208    }
209    /**
210     * Retrieve email statistics for your subusers.
211     *
212     * This function performs a `GET` to the `/subusers/stats` endpoint.
213     *
214     * **This endpoint allows you to retrieve the email statistics for the given subusers.**
215     *
216     * You may retrieve statistics for up to 10 different subusers by including an additional _subusers_ parameter for each additional subuser.
217     *
218     * **Parameters:**
219     *
220     * * `limit: i64` -- Limits the number of results returned per page.
221     * * `offset: i64` -- The point in the list to begin retrieving results from.
222     * * `aggregated_by: crate::types::TraitStatsAdvancedBaseQueryStringsAggregatedBy` -- How to group the statistics. Must be either "day", "week", or "month".
223     * * `subusers: &str` -- The subuser you want to retrieve statistics for. You may include this parameter up to 10 times to retrieve statistics for multiple subusers.
224     * * `start_date: &str` -- The starting date of the statistics to retrieve. Must follow format YYYY-MM-DD.
225     * * `end_date: &str` -- The end date of the statistics to retrieve. Defaults to today.
226     */
227    pub async fn get_subusers_stat(
228        &self,
229        limit: i64,
230        offset: i64,
231        aggregated_by: crate::types::TraitStatsAdvancedBaseQueryStringsAggregatedBy,
232        subusers: &str,
233        start_date: &str,
234        end_date: &str,
235    ) -> ClientResult<crate::Response<crate::types::CategoryStats>> {
236        let mut query_args: Vec<(String, String)> = Default::default();
237        if !aggregated_by.to_string().is_empty() {
238            query_args.push(("aggregated_by".to_string(), aggregated_by.to_string()));
239        }
240        if !end_date.is_empty() {
241            query_args.push(("end_date".to_string(), end_date.to_string()));
242        }
243        if limit > 0 {
244            query_args.push(("limit".to_string(), limit.to_string()));
245        }
246        if offset > 0 {
247            query_args.push(("offset".to_string(), offset.to_string()));
248        }
249        if !start_date.is_empty() {
250            query_args.push(("start_date".to_string(), start_date.to_string()));
251        }
252        if !subusers.is_empty() {
253            query_args.push(("subusers".to_string(), subusers.to_string()));
254        }
255        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
256        let url = self
257            .client
258            .url(&format!("/subusers/stats?{}", query_), None);
259        self.client
260            .get(
261                &url,
262                crate::Message {
263                    body: None,
264                    content_type: None,
265                },
266            )
267            .await
268    }
269}