sendgrid_api/subusers_api.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct SubusersApi {
5 pub client: Client,
6}
7
8impl SubusersApi {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 SubusersApi { client }
12 }
13
14 /**
15 * List all Subusers.
16 *
17 * This function performs a `GET` to the `/subusers` endpoint.
18 *
19 * **This endpoint allows you to retrieve a list of all of your subusers.**
20 *
21 * You can choose to retrieve specific subusers as well as limit the results that come back from the API.
22 *
23 * **Parameters:**
24 *
25 * * `username: &str` -- The license key provided with your New Relic account.
26 * * `limit: i64` -- The number of results you would like to get in each request.
27 * * `offset: i64` -- The number of subusers to skip.
28 */
29 pub async fn get_subusers(
30 &self,
31 username: &str,
32 limit: i64,
33 offset: i64,
34 ) -> ClientResult<crate::Response<Vec<crate::types::Subuser>>> {
35 let mut query_args: Vec<(String, String)> = Default::default();
36 if limit > 0 {
37 query_args.push(("limit".to_string(), limit.to_string()));
38 }
39 if offset > 0 {
40 query_args.push(("offset".to_string(), offset.to_string()));
41 }
42 if !username.is_empty() {
43 query_args.push(("username".to_string(), username.to_string()));
44 }
45 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
46 let url = self.client.url(&format!("/subusers?{}", query_), None);
47 self.client
48 .get(
49 &url,
50 crate::Message {
51 body: None,
52 content_type: None,
53 },
54 )
55 .await
56 }
57 /**
58 * List all Subusers.
59 *
60 * This function performs a `GET` to the `/subusers` endpoint.
61 *
62 * As opposed to `get_subusers`, this function returns all the pages of the request at once.
63 *
64 * **This endpoint allows you to retrieve a list of all of your subusers.**
65 *
66 * You can choose to retrieve specific subusers as well as limit the results that come back from the API.
67 */
68 pub async fn get_all_subusers(
69 &self,
70 username: &str,
71 offset: i64,
72 ) -> ClientResult<crate::Response<Vec<crate::types::Subuser>>> {
73 let mut query_args: Vec<(String, String)> = Default::default();
74 if offset > 0 {
75 query_args.push(("offset".to_string(), offset.to_string()));
76 }
77 if !username.is_empty() {
78 query_args.push(("username".to_string(), username.to_string()));
79 }
80 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
81 let url = self.client.url(&format!("/subusers?{}", query_), None);
82 self.client
83 .get_all_pages(
84 &url,
85 crate::Message {
86 body: None,
87 content_type: None,
88 },
89 )
90 .await
91 }
92 /**
93 * Create Subuser.
94 *
95 * This function performs a `POST` to the `/subusers` endpoint.
96 *
97 * **This endpoint allows you to create a new subuser.**
98 */
99 pub async fn post_subuser(
100 &self,
101 body: &crate::types::PostSubusersRequest,
102 ) -> ClientResult<crate::Response<crate::types::SubuserPost>> {
103 let url = self.client.url("/subusers", None);
104 self.client
105 .post(
106 &url,
107 crate::Message {
108 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
109 content_type: Some("application/json".to_string()),
110 },
111 )
112 .await
113 }
114 /**
115 * Delete a subuser.
116 *
117 * This function performs a `DELETE` to the `/subusers/{subuser_name}` endpoint.
118 *
119 * **This endpoint allows you to delete a subuser.**
120 *
121 * This is a permanent action. Once deleted, a subuser cannot be retrieved.
122 */
123 pub async fn delete_subusers_subuser_name(
124 &self,
125 subuser_name: &str,
126 ) -> ClientResult<crate::Response<crate::types::Help>> {
127 let url = self.client.url(
128 &format!(
129 "/subusers/{}",
130 crate::progenitor_support::encode_path(subuser_name),
131 ),
132 None,
133 );
134 self.client
135 .delete(
136 &url,
137 crate::Message {
138 body: None,
139 content_type: None,
140 },
141 )
142 .await
143 }
144 /**
145 * Enable/disable a subuser.
146 *
147 * This function performs a `PATCH` to the `/subusers/{subuser_name}` endpoint.
148 *
149 * **This endpoint allows you to enable or disable a subuser.**
150 */
151 pub async fn patch_subusers_subuser_name(
152 &self,
153 subuser_name: &str,
154 body: &crate::types::PatchSubusersSubuserNameRequest,
155 ) -> ClientResult<crate::Response<crate::types::Help>> {
156 let url = self.client.url(
157 &format!(
158 "/subusers/{}",
159 crate::progenitor_support::encode_path(subuser_name),
160 ),
161 None,
162 );
163 self.client
164 .patch(
165 &url,
166 crate::Message {
167 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
168 content_type: Some("application/json".to_string()),
169 },
170 )
171 .await
172 }
173 /**
174 * Retrieve Subuser Reputations.
175 *
176 * This function performs a `GET` to the `/subusers/reputations` endpoint.
177 *
178 * **This endpoint allows you to request the reputations for your subusers.**
179 *
180 * Subuser sender reputations give a good idea how well a sender is doing with regards to how recipients and recipient servers react to the mail that is being received. When a bounce, spam report, or other negative action happens on a sent email, it will affect your sender rating.
181 *
182 * **Parameters:**
183 *
184 * * `usernames: &str` -- The license key provided with your New Relic account.
185 */
186 pub async fn get_subusers_reputations(
187 &self,
188 usernames: &str,
189 ) -> ClientResult<crate::Response<Vec<crate::types::GetSubusersReputationsResponse>>> {
190 let mut query_args: Vec<(String, String)> = Default::default();
191 if !usernames.is_empty() {
192 query_args.push(("usernames".to_string(), usernames.to_string()));
193 }
194 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
195 let url = self
196 .client
197 .url(&format!("/subusers/reputations?{}", query_), None);
198 self.client
199 .get(
200 &url,
201 crate::Message {
202 body: None,
203 content_type: None,
204 },
205 )
206 .await
207 }
208 /**
209 * Retrieve Subuser Reputations.
210 *
211 * This function performs a `GET` to the `/subusers/reputations` endpoint.
212 *
213 * As opposed to `get_subusers_reputations`, this function returns all the pages of the request at once.
214 *
215 * **This endpoint allows you to request the reputations for your subusers.**
216 *
217 * Subuser sender reputations give a good idea how well a sender is doing with regards to how recipients and recipient servers react to the mail that is being received. When a bounce, spam report, or other negative action happens on a sent email, it will affect your sender rating.
218 */
219 pub async fn get_all_subusers_reputations(
220 &self,
221 usernames: &str,
222 ) -> ClientResult<crate::Response<Vec<crate::types::GetSubusersReputationsResponse>>> {
223 let mut query_args: Vec<(String, String)> = Default::default();
224 if !usernames.is_empty() {
225 query_args.push(("usernames".to_string(), usernames.to_string()));
226 }
227 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
228 let url = self
229 .client
230 .url(&format!("/subusers/reputations?{}", query_), None);
231 self.client
232 .get_all_pages(
233 &url,
234 crate::Message {
235 body: None,
236 content_type: None,
237 },
238 )
239 .await
240 }
241 /**
242 * Update IPs assigned to a subuser.
243 *
244 * This function performs a `PUT` to the `/subusers/{subuser_name}/ips` endpoint.
245 *
246 * **This endpoint allows you update your subusers' assigned IP.**
247 *
248 * Each subuser should be assigned to an IP address from which all of this subuser's mail will be sent. Often, this is the same IP as the parent account, but each subuser can have one or more of their own IP addresses as well.
249 *
250 * More information:
251 *
252 * * [How to request more IPs](https://sendgrid.com/docs/ui/account-and-settings/dedicated-ip-addresses/)
253 * * [Setup Reverse DNS](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/)
254 */
255 pub async fn put_subusers_subuser_name_ips(
256 &self,
257 subuser_name: &str,
258 body: &[std::net::Ipv4Addr],
259 ) -> ClientResult<crate::Response<crate::types::PutSubusersSubuserNameIpsResponse>> {
260 let url = self.client.url(
261 &format!(
262 "/subusers/{}/ips",
263 crate::progenitor_support::encode_path(subuser_name),
264 ),
265 None,
266 );
267 self.client
268 .put(
269 &url,
270 crate::Message {
271 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
272 content_type: Some("application/json".to_string()),
273 },
274 )
275 .await
276 }
277}