sendgrid_api/
categories.rs

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