use reqwest;
use crate::apis::ResponseContent;
use super::{Error, configuration};
#[derive(Clone, Debug)]
pub struct WaitForParams {
pub wait_for_conditions: Option<crate::models::WaitForConditions>
}
#[derive(Clone, Debug)]
pub struct WaitForEmailCountParams {
pub count: Option<i32>,
pub inbox_id: Option<String>,
pub timeout: Option<i64>,
pub unread_only: Option<bool>
}
#[derive(Clone, Debug)]
pub struct WaitForLatestEmailParams {
pub inbox_id: Option<String>,
pub timeout: Option<i64>,
pub unread_only: Option<bool>
}
#[derive(Clone, Debug)]
pub struct WaitForMatchingEmailParams {
pub match_options: crate::models::MatchOptions,
pub count: Option<i32>,
pub inbox_id: Option<String>,
pub timeout: Option<i64>,
pub unread_only: Option<bool>
}
#[derive(Clone, Debug)]
pub struct WaitForMatchingFirstEmailParams {
pub match_options: crate::models::MatchOptions,
pub inbox_id: Option<String>,
pub timeout: Option<i64>,
pub unread_only: Option<bool>
}
#[derive(Clone, Debug)]
pub struct WaitForNthEmailParams {
pub inbox_id: Option<String>,
pub index: Option<i32>,
pub timeout: Option<i64>,
pub unread_only: Option<bool>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WaitForError {
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WaitForEmailCountError {
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WaitForLatestEmailError {
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WaitForMatchingEmailError {
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WaitForMatchingFirstEmailError {
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WaitForNthEmailError {
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
pub async fn wait_for(configuration: &configuration::Configuration, params: WaitForParams) -> Result<Vec<crate::models::EmailPreview>, Error<WaitForError>> {
let wait_for_conditions = params.wait_for_conditions;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/waitFor", configuration.base_path);
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
local_var_req_builder = local_var_req_builder.json(&wait_for_conditions);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<WaitForError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn wait_for_email_count(configuration: &configuration::Configuration, params: WaitForEmailCountParams) -> Result<Vec<crate::models::EmailPreview>, Error<WaitForEmailCountError>> {
let count = params.count;
let inbox_id = params.inbox_id;
let timeout = params.timeout;
let unread_only = params.unread_only;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/waitForEmailCount", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_str) = count {
local_var_req_builder = local_var_req_builder.query(&[("count", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = inbox_id {
local_var_req_builder = local_var_req_builder.query(&[("inboxId", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = timeout {
local_var_req_builder = local_var_req_builder.query(&[("timeout", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = unread_only {
local_var_req_builder = local_var_req_builder.query(&[("unreadOnly", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<WaitForEmailCountError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn wait_for_latest_email(configuration: &configuration::Configuration, params: WaitForLatestEmailParams) -> Result<crate::models::Email, Error<WaitForLatestEmailError>> {
let inbox_id = params.inbox_id;
let timeout = params.timeout;
let unread_only = params.unread_only;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/waitForLatestEmail", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_str) = inbox_id {
local_var_req_builder = local_var_req_builder.query(&[("inboxId", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = timeout {
local_var_req_builder = local_var_req_builder.query(&[("timeout", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = unread_only {
local_var_req_builder = local_var_req_builder.query(&[("unreadOnly", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<WaitForLatestEmailError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn wait_for_matching_email(configuration: &configuration::Configuration, params: WaitForMatchingEmailParams) -> Result<Vec<crate::models::EmailPreview>, Error<WaitForMatchingEmailError>> {
let match_options = params.match_options;
let count = params.count;
let inbox_id = params.inbox_id;
let timeout = params.timeout;
let unread_only = params.unread_only;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/waitForMatchingEmails", configuration.base_path);
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_str) = count {
local_var_req_builder = local_var_req_builder.query(&[("count", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = inbox_id {
local_var_req_builder = local_var_req_builder.query(&[("inboxId", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = timeout {
local_var_req_builder = local_var_req_builder.query(&[("timeout", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = unread_only {
local_var_req_builder = local_var_req_builder.query(&[("unreadOnly", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
local_var_req_builder = local_var_req_builder.json(&match_options);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<WaitForMatchingEmailError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn wait_for_matching_first_email(configuration: &configuration::Configuration, params: WaitForMatchingFirstEmailParams) -> Result<crate::models::Email, Error<WaitForMatchingFirstEmailError>> {
let match_options = params.match_options;
let inbox_id = params.inbox_id;
let timeout = params.timeout;
let unread_only = params.unread_only;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/waitForMatchingFirstEmail", configuration.base_path);
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_str) = inbox_id {
local_var_req_builder = local_var_req_builder.query(&[("inboxId", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = timeout {
local_var_req_builder = local_var_req_builder.query(&[("timeout", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = unread_only {
local_var_req_builder = local_var_req_builder.query(&[("unreadOnly", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
local_var_req_builder = local_var_req_builder.json(&match_options);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<WaitForMatchingFirstEmailError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn wait_for_nth_email(configuration: &configuration::Configuration, params: WaitForNthEmailParams) -> Result<crate::models::Email, Error<WaitForNthEmailError>> {
let inbox_id = params.inbox_id;
let index = params.index;
let timeout = params.timeout;
let unread_only = params.unread_only;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/waitForNthEmail", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_str) = inbox_id {
local_var_req_builder = local_var_req_builder.query(&[("inboxId", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = index {
local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = timeout {
local_var_req_builder = local_var_req_builder.query(&[("timeout", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = unread_only {
local_var_req_builder = local_var_req_builder.query(&[("unreadOnly", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<WaitForNthEmailError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}