ElasticEmail 4.2.0

Official Rust SDK for the Elastic Email REST API v4
Documentation
/*
 * 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 [`domains_by_domain_delete`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainsByDomainDeleteError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domains_by_domain_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainsByDomainGetError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domains_by_domain_put`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainsByDomainPutError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domains_by_domain_restricted_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainsByDomainRestrictedGetError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domains_by_domain_verification_put`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainsByDomainVerificationPutError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domains_by_email_default_patch`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainsByEmailDefaultPatchError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domains_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainsGetError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domains_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainsPostError {
    UnknownValue(serde_json::Value),
}


/// Deletes configured domain from Account. Required Access Level: ModifySettings
pub async fn domains_by_domain_delete(configuration: &configuration::Configuration, domain: &str) -> Result<(), Error<DomainsByDomainDeleteError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_domain = domain;

    let uri_str = format!("{}/domains/{domain}", configuration.base_path, domain=crate::apis::urlencode(p_domain));
    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &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() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<DomainsByDomainDeleteError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Retrieve a domain configured for this Account. Required Access Level: ViewSettings
pub async fn domains_by_domain_get(configuration: &configuration::Configuration, domain: &str) -> Result<models::DomainData, Error<DomainsByDomainGetError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_domain = domain;

    let uri_str = format!("{}/domains/{domain}", configuration.base_path, domain=crate::apis::urlencode(p_domain));
    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<DomainsByDomainGetError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Updates the specified domain. Required Access Level: ModifySettings
pub async fn domains_by_domain_put(configuration: &configuration::Configuration, domain: &str, domain_update_payload: models::DomainUpdatePayload) -> Result<models::DomainDetail, Error<DomainsByDomainPutError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_domain = domain;
    let p_domain_update_payload = domain_update_payload;

    let uri_str = format!("{}/domains/{domain}", configuration.base_path, domain=crate::apis::urlencode(p_domain));
    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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);
    };
    req_builder = req_builder.json(&p_domain_update_payload);

    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<DomainsByDomainPutError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Checking if domain is from free provider, or restricted. Required Access Level: ViewSettings
pub async fn domains_by_domain_restricted_get(configuration: &configuration::Configuration, domain: &str) -> Result<bool, Error<DomainsByDomainRestrictedGetError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_domain = domain;

    let uri_str = format!("{}/domains/{domain}/restricted", configuration.base_path, domain=crate::apis::urlencode(p_domain));
    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<DomainsByDomainRestrictedGetError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Verifies that required DNS records exist for specified domain. Required Access Level: ModifySettings
pub async fn domains_by_domain_verification_put(configuration: &configuration::Configuration, domain: &str, body: &str) -> Result<models::DomainData, Error<DomainsByDomainVerificationPutError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_domain = domain;
    let p_body = body;

    let uri_str = format!("{}/domains/{domain}/verification", configuration.base_path, domain=crate::apis::urlencode(p_domain));
    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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);
    };
    req_builder = req_builder.json(&p_body);

    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<DomainsByDomainVerificationPutError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Sets a verified email address as default sender. Required Access Level: ModifySettings
pub async fn domains_by_email_default_patch(configuration: &configuration::Configuration, email: &str) -> Result<models::DomainDetail, Error<DomainsByEmailDefaultPatchError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_email = email;

    let uri_str = format!("{}/domains/{email}/default", configuration.base_path, email=crate::apis::urlencode(p_email));
    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &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<DomainsByEmailDefaultPatchError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Returns a list of all domains configured for this Account. Required Access Level: ViewSettings
pub async fn domains_get(configuration: &configuration::Configuration, ) -> Result<Vec<models::DomainDetail>, Error<DomainsGetError>> {

    let uri_str = format!("{}/domains", configuration.base_path);
    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<DomainsGetError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Add new domain to Account. Required Access Level: ModifySettings
pub async fn domains_post(configuration: &configuration::Configuration, domain_payload: models::DomainPayload) -> Result<models::DomainDetail, Error<DomainsPostError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_domain_payload = domain_payload;

    let uri_str = format!("{}/domains", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::POST, &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);
    };
    req_builder = req_builder.json(&p_domain_payload);

    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<DomainsPostError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}