/*
* Elastic Email REST API
*
* This API is based on the REST API architecture, allowing the user to easily manage their data with this resource-based approach. Every API call is established on which specific request type (GET, POST, PUT, DELETE) will be used. The API has a limit of 20 concurrent connections and a hard timeout of 600 seconds per request. To start using this API, you will need your Access Token (available <a target='_blank' href='https://app.elasticemail.com/marketing/settings/new/manage-api'>here</a>). Remember to keep it safe. Required access levels are listed in the given request’s description. Downloadable library clients can be found in our Github repository <a target='_blank' href='https://github.com/ElasticEmail?tab=repositories&q=%22rest+api%22+in%3Areadme'>here</a>
*
* The version of the OpenAPI document: 4.0.0
* Contact: support@elasticemail.com
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
/// struct for typed errors of method [`events_by_transactionid_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EventsByTransactionidGetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`events_channels_by_name_export_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EventsChannelsByNameExportPostError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`events_channels_by_name_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EventsChannelsByNameGetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`events_channels_export_by_id_status_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EventsChannelsExportByIdStatusGetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`events_export_by_id_status_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EventsExportByIdStatusGetError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`events_export_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EventsExportPostError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`events_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EventsGetError {
UnknownValue(serde_json::Value),
}
/// Returns a log of delivery events for the specific transaction ID. Required Access Level: ViewReports
pub async fn events_by_transactionid_get(configuration: &configuration::Configuration, transactionid: &str, from: Option<String>, to: Option<String>, order_by: Option<models::EventsOrderBy>, limit: Option<i32>, offset: Option<i32>) -> Result<Vec<models::RecipientEvent>, Error<EventsByTransactionidGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_transactionid = transactionid;
let p_from = from;
let p_to = to;
let p_order_by = order_by;
let p_limit = limit;
let p_offset = offset;
let uri_str = format!("{}/events/{transactionid}", configuration.base_path, transactionid=crate::apis::urlencode(p_transactionid));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_from {
req_builder = req_builder.query(&[("from", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_to {
req_builder = req_builder.query(&[("to", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_order_by {
req_builder = req_builder.query(&[("orderBy", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-ElasticEmail-ApiKey", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<EventsByTransactionidGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Export delivery events log information to the specified file format. Required Access Level: Export
pub async fn events_channels_by_name_export_post(configuration: &configuration::Configuration, name: &str, event_types: Option<Vec<models::EventType>>, from: Option<String>, to: Option<String>, file_format: Option<models::ExportFileFormats>, compression_format: Option<models::CompressionFormat>, file_name: Option<&str>) -> Result<models::ExportLink, Error<EventsChannelsByNameExportPostError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_name = name;
let p_event_types = event_types;
let p_from = from;
let p_to = to;
let p_file_format = file_format;
let p_compression_format = compression_format;
let p_file_name = file_name;
let uri_str = format!("{}/events/channels/{name}/export", configuration.base_path, name=crate::apis::urlencode(p_name));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_event_types {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("eventTypes".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("eventTypes", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_from {
req_builder = req_builder.query(&[("from", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_to {
req_builder = req_builder.query(&[("to", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_file_format {
req_builder = req_builder.query(&[("fileFormat", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_compression_format {
req_builder = req_builder.query(&[("compressionFormat", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_file_name {
req_builder = req_builder.query(&[("fileName", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-ElasticEmail-ApiKey", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<EventsChannelsByNameExportPostError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns a log of delivery events filtered by specified parameters. Required Access Level: ViewReports
pub async fn events_channels_by_name_get(configuration: &configuration::Configuration, name: &str, event_types: Option<Vec<models::EventType>>, from: Option<String>, to: Option<String>, order_by: Option<models::EventsOrderBy>, limit: Option<i32>, offset: Option<i32>) -> Result<Vec<models::RecipientEvent>, Error<EventsChannelsByNameGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_name = name;
let p_event_types = event_types;
let p_from = from;
let p_to = to;
let p_order_by = order_by;
let p_limit = limit;
let p_offset = offset;
let uri_str = format!("{}/events/channels/{name}", configuration.base_path, name=crate::apis::urlencode(p_name));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_event_types {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("eventTypes".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("eventTypes", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_from {
req_builder = req_builder.query(&[("from", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_to {
req_builder = req_builder.query(&[("to", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_order_by {
req_builder = req_builder.query(&[("orderBy", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-ElasticEmail-ApiKey", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<EventsChannelsByNameGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Check the current status of the channel export. Required Access Level: Export
pub async fn events_channels_export_by_id_status_get(configuration: &configuration::Configuration, id: &str) -> Result<models::ExportStatus, Error<EventsChannelsExportByIdStatusGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let uri_str = format!("{}/events/channels/export/{id}/status", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-ElasticEmail-ApiKey", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<EventsChannelsExportByIdStatusGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Check the current status of the export. Required Access Level: Export
pub async fn events_export_by_id_status_get(configuration: &configuration::Configuration, id: &str) -> Result<models::ExportStatus, Error<EventsExportByIdStatusGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_id = id;
let uri_str = format!("{}/events/export/{id}/status", configuration.base_path, id=crate::apis::urlencode(p_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-ElasticEmail-ApiKey", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<EventsExportByIdStatusGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Export delivery events log information to the specified file format. Required Access Level: Export
pub async fn events_export_post(configuration: &configuration::Configuration, event_types: Option<Vec<models::EventType>>, from: Option<String>, to: Option<String>, file_format: Option<models::ExportFileFormats>, compression_format: Option<models::CompressionFormat>, file_name: Option<&str>) -> Result<models::ExportLink, Error<EventsExportPostError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_event_types = event_types;
let p_from = from;
let p_to = to;
let p_file_format = file_format;
let p_compression_format = compression_format;
let p_file_name = file_name;
let uri_str = format!("{}/events/export", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_event_types {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("eventTypes".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("eventTypes", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_from {
req_builder = req_builder.query(&[("from", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_to {
req_builder = req_builder.query(&[("to", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_file_format {
req_builder = req_builder.query(&[("fileFormat", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_compression_format {
req_builder = req_builder.query(&[("compressionFormat", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_file_name {
req_builder = req_builder.query(&[("fileName", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-ElasticEmail-ApiKey", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<EventsExportPostError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns a log of delivery events filtered by specified parameters. Required Access Level: ViewReports
pub async fn events_get(configuration: &configuration::Configuration, event_types: Option<Vec<models::EventType>>, from: Option<String>, to: Option<String>, order_by: Option<models::EventsOrderBy>, limit: Option<i32>, offset: Option<i32>) -> Result<Vec<models::RecipientEvent>, Error<EventsGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_event_types = event_types;
let p_from = from;
let p_to = to;
let p_order_by = order_by;
let p_limit = limit;
let p_offset = offset;
let uri_str = format!("{}/events", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_event_types {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("eventTypes".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("eventTypes", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_from {
req_builder = req_builder.query(&[("from", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_to {
req_builder = req_builder.query(&[("to", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_order_by {
req_builder = req_builder.query(&[("orderBy", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-ElasticEmail-ApiKey", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<EventsGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}