mailslurp/apis/
common_actions_controller_api.rs

1/*
2 * MailSlurp API
3 *
4 * MailSlurp is an API for sending and receiving emails from dynamically allocated email addresses. It's designed for developers and QA teams to test applications, process inbound emails, send templated notifications, attachments, and more.  ## Resources  - [Homepage](https://www.mailslurp.com) - Get an [API KEY](https://app.mailslurp.com/sign-up/) - Generated [SDK Clients](https://www.mailslurp.com/docs/) - [Examples](https://github.com/mailslurp/examples) repository
5 *
6 * The version of the OpenAPI document: 6.5.2
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method `create_new_email_address`
18#[derive(Clone, Debug)]
19pub struct CreateNewEmailAddressParams {
20    /// allowTeamAccess
21    pub allow_team_access: Option<bool>,
22    /// description
23    pub description: Option<String>,
24    /// emailAddress
25    pub email_address: Option<String>,
26    /// expiresAt
27    pub expires_at: Option<String>,
28    /// expiresIn
29    pub expires_in: Option<i64>,
30    /// favourite
31    pub favourite: Option<bool>,
32    /// inboxType
33    pub inbox_type: Option<String>,
34    /// name
35    pub name: Option<String>,
36    /// tags
37    pub tags: Option<Vec<String>>,
38    /// useDomainPool
39    pub use_domain_pool: Option<bool>
40}
41
42/// struct for passing parameters to the method `create_new_email_address1`
43#[derive(Clone, Debug)]
44pub struct CreateNewEmailAddress1Params {
45    /// allowTeamAccess
46    pub allow_team_access: Option<bool>,
47    /// description
48    pub description: Option<String>,
49    /// emailAddress
50    pub email_address: Option<String>,
51    /// expiresAt
52    pub expires_at: Option<String>,
53    /// expiresIn
54    pub expires_in: Option<i64>,
55    /// favourite
56    pub favourite: Option<bool>,
57    /// inboxType
58    pub inbox_type: Option<String>,
59    /// name
60    pub name: Option<String>,
61    /// tags
62    pub tags: Option<Vec<String>>,
63    /// useDomainPool
64    pub use_domain_pool: Option<bool>
65}
66
67/// struct for passing parameters to the method `empty_inbox`
68#[derive(Clone, Debug)]
69pub struct EmptyInboxParams {
70    /// inboxId
71    pub inbox_id: String
72}
73
74/// struct for passing parameters to the method `send_email_simple`
75#[derive(Clone, Debug)]
76pub struct SendEmailSimpleParams {
77    /// emailOptions
78    pub email_options: crate::models::SimpleSendEmailOptions
79}
80
81
82/// struct for typed errors of method `create_new_email_address`
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum CreateNewEmailAddressError {
86    Status401(),
87    Status403(),
88    Status404(),
89    UnknownValue(serde_json::Value),
90}
91
92/// struct for typed errors of method `create_new_email_address1`
93#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum CreateNewEmailAddress1Error {
96    Status401(),
97    Status403(),
98    Status404(),
99    UnknownValue(serde_json::Value),
100}
101
102/// struct for typed errors of method `empty_inbox`
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum EmptyInboxError {
106    Status401(),
107    Status403(),
108    UnknownValue(serde_json::Value),
109}
110
111/// struct for typed errors of method `send_email_simple`
112#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(untagged)]
114pub enum SendEmailSimpleError {
115    Status401(),
116    Status403(),
117    Status404(),
118    UnknownValue(serde_json::Value),
119}
120
121
122/// Returns an Inbox with an `id` and an `emailAddress`
123pub async fn create_new_email_address(configuration: &configuration::Configuration, params: CreateNewEmailAddressParams) -> Result<crate::models::Inbox, Error<CreateNewEmailAddressError>> {
124    // unbox the parameters
125    let allow_team_access = params.allow_team_access;
126    let description = params.description;
127    let email_address = params.email_address;
128    let expires_at = params.expires_at;
129    let expires_in = params.expires_in;
130    let favourite = params.favourite;
131    let inbox_type = params.inbox_type;
132    let name = params.name;
133    let tags = params.tags;
134    let use_domain_pool = params.use_domain_pool;
135
136
137    let local_var_client = &configuration.client;
138
139    let local_var_uri_str = format!("{}/createInbox", configuration.base_path);
140    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
141
142    if let Some(ref local_var_str) = allow_team_access {
143        local_var_req_builder = local_var_req_builder.query(&[("allowTeamAccess", &local_var_str.to_string())]);
144    }
145    if let Some(ref local_var_str) = description {
146        local_var_req_builder = local_var_req_builder.query(&[("description", &local_var_str.to_string())]);
147    }
148    if let Some(ref local_var_str) = email_address {
149        local_var_req_builder = local_var_req_builder.query(&[("emailAddress", &local_var_str.to_string())]);
150    }
151    if let Some(ref local_var_str) = expires_at {
152        local_var_req_builder = local_var_req_builder.query(&[("expiresAt", &local_var_str.to_string())]);
153    }
154    if let Some(ref local_var_str) = expires_in {
155        local_var_req_builder = local_var_req_builder.query(&[("expiresIn", &local_var_str.to_string())]);
156    }
157    if let Some(ref local_var_str) = favourite {
158        local_var_req_builder = local_var_req_builder.query(&[("favourite", &local_var_str.to_string())]);
159    }
160    if let Some(ref local_var_str) = inbox_type {
161        local_var_req_builder = local_var_req_builder.query(&[("inboxType", &local_var_str.to_string())]);
162    }
163    if let Some(ref local_var_str) = name {
164        local_var_req_builder = local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
165    }
166    if let Some(ref local_var_str) = tags {
167        local_var_req_builder = local_var_req_builder.query(&[("tags", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]);
168    }
169    if let Some(ref local_var_str) = use_domain_pool {
170        local_var_req_builder = local_var_req_builder.query(&[("useDomainPool", &local_var_str.to_string())]);
171    }
172    if let Some(ref local_var_user_agent) = configuration.user_agent {
173        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
174    }
175    if let Some(ref local_var_apikey) = configuration.api_key {
176        let local_var_key = local_var_apikey.key.clone();
177        let local_var_value = match local_var_apikey.prefix {
178            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
179            None => local_var_key,
180        };
181        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
182    };
183
184    let local_var_req = local_var_req_builder.build()?;
185    let local_var_resp = local_var_client.execute(local_var_req).await?;
186
187    let local_var_status = local_var_resp.status();
188    let local_var_content = local_var_resp.text().await?;
189
190    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
191        serde_json::from_str(&local_var_content).map_err(Error::from)
192    } else {
193        let local_var_entity: Option<CreateNewEmailAddressError> = serde_json::from_str(&local_var_content).ok();
194        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
195        Err(Error::ResponseError(local_var_error))
196    }
197}
198
199/// Returns an Inbox with an `id` and an `emailAddress`
200pub async fn create_new_email_address1(configuration: &configuration::Configuration, params: CreateNewEmailAddress1Params) -> Result<crate::models::Inbox, Error<CreateNewEmailAddress1Error>> {
201    // unbox the parameters
202    let allow_team_access = params.allow_team_access;
203    let description = params.description;
204    let email_address = params.email_address;
205    let expires_at = params.expires_at;
206    let expires_in = params.expires_in;
207    let favourite = params.favourite;
208    let inbox_type = params.inbox_type;
209    let name = params.name;
210    let tags = params.tags;
211    let use_domain_pool = params.use_domain_pool;
212
213
214    let local_var_client = &configuration.client;
215
216    let local_var_uri_str = format!("{}/newEmailAddress", configuration.base_path);
217    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
218
219    if let Some(ref local_var_str) = allow_team_access {
220        local_var_req_builder = local_var_req_builder.query(&[("allowTeamAccess", &local_var_str.to_string())]);
221    }
222    if let Some(ref local_var_str) = description {
223        local_var_req_builder = local_var_req_builder.query(&[("description", &local_var_str.to_string())]);
224    }
225    if let Some(ref local_var_str) = email_address {
226        local_var_req_builder = local_var_req_builder.query(&[("emailAddress", &local_var_str.to_string())]);
227    }
228    if let Some(ref local_var_str) = expires_at {
229        local_var_req_builder = local_var_req_builder.query(&[("expiresAt", &local_var_str.to_string())]);
230    }
231    if let Some(ref local_var_str) = expires_in {
232        local_var_req_builder = local_var_req_builder.query(&[("expiresIn", &local_var_str.to_string())]);
233    }
234    if let Some(ref local_var_str) = favourite {
235        local_var_req_builder = local_var_req_builder.query(&[("favourite", &local_var_str.to_string())]);
236    }
237    if let Some(ref local_var_str) = inbox_type {
238        local_var_req_builder = local_var_req_builder.query(&[("inboxType", &local_var_str.to_string())]);
239    }
240    if let Some(ref local_var_str) = name {
241        local_var_req_builder = local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
242    }
243    if let Some(ref local_var_str) = tags {
244        local_var_req_builder = local_var_req_builder.query(&[("tags", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]);
245    }
246    if let Some(ref local_var_str) = use_domain_pool {
247        local_var_req_builder = local_var_req_builder.query(&[("useDomainPool", &local_var_str.to_string())]);
248    }
249    if let Some(ref local_var_user_agent) = configuration.user_agent {
250        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
251    }
252    if let Some(ref local_var_apikey) = configuration.api_key {
253        let local_var_key = local_var_apikey.key.clone();
254        let local_var_value = match local_var_apikey.prefix {
255            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
256            None => local_var_key,
257        };
258        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
259    };
260
261    let local_var_req = local_var_req_builder.build()?;
262    let local_var_resp = local_var_client.execute(local_var_req).await?;
263
264    let local_var_status = local_var_resp.status();
265    let local_var_content = local_var_resp.text().await?;
266
267    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
268        serde_json::from_str(&local_var_content).map_err(Error::from)
269    } else {
270        let local_var_entity: Option<CreateNewEmailAddress1Error> = serde_json::from_str(&local_var_content).ok();
271        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
272        Err(Error::ResponseError(local_var_error))
273    }
274}
275
276/// Deletes all emails
277pub async fn empty_inbox(configuration: &configuration::Configuration, params: EmptyInboxParams) -> Result<(), Error<EmptyInboxError>> {
278    // unbox the parameters
279    let inbox_id = params.inbox_id;
280
281
282    let local_var_client = &configuration.client;
283
284    let local_var_uri_str = format!("{}/emptyInbox", configuration.base_path);
285    let mut local_var_req_builder = local_var_client.delete(local_var_uri_str.as_str());
286
287    local_var_req_builder = local_var_req_builder.query(&[("inboxId", &inbox_id.to_string())]);
288    if let Some(ref local_var_user_agent) = configuration.user_agent {
289        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
290    }
291    if let Some(ref local_var_apikey) = configuration.api_key {
292        let local_var_key = local_var_apikey.key.clone();
293        let local_var_value = match local_var_apikey.prefix {
294            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
295            None => local_var_key,
296        };
297        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
298    };
299
300    let local_var_req = local_var_req_builder.build()?;
301    let local_var_resp = local_var_client.execute(local_var_req).await?;
302
303    let local_var_status = local_var_resp.status();
304    let local_var_content = local_var_resp.text().await?;
305
306    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
307        Ok(())
308    } else {
309        let local_var_entity: Option<EmptyInboxError> = serde_json::from_str(&local_var_content).ok();
310        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
311        Err(Error::ResponseError(local_var_error))
312    }
313}
314
315/// If no senderId or inboxId provided a random email address will be used to send from.
316pub async fn send_email_simple(configuration: &configuration::Configuration, params: SendEmailSimpleParams) -> Result<(), Error<SendEmailSimpleError>> {
317    // unbox the parameters
318    let email_options = params.email_options;
319
320
321    let local_var_client = &configuration.client;
322
323    let local_var_uri_str = format!("{}/sendEmail", configuration.base_path);
324    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
325
326    if let Some(ref local_var_user_agent) = configuration.user_agent {
327        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
328    }
329    if let Some(ref local_var_apikey) = configuration.api_key {
330        let local_var_key = local_var_apikey.key.clone();
331        let local_var_value = match local_var_apikey.prefix {
332            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
333            None => local_var_key,
334        };
335        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
336    };
337    local_var_req_builder = local_var_req_builder.json(&email_options);
338
339    let local_var_req = local_var_req_builder.build()?;
340    let local_var_resp = local_var_client.execute(local_var_req).await?;
341
342    let local_var_status = local_var_resp.status();
343    let local_var_content = local_var_resp.text().await?;
344
345    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
346        Ok(())
347    } else {
348        let local_var_entity: Option<SendEmailSimpleError> = serde_json::from_str(&local_var_content).ok();
349        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
350        Err(Error::ResponseError(local_var_error))
351    }
352}
353