unosend 1.0.0

Official Rust SDK for Unosend - Email API for developers
Documentation
use crate::client::Unosend;
use crate::error::UnosendError;
use serde::{Deserialize, Serialize};

/// Contact management API.
pub struct ContactsApi {
    client: Unosend,
}

impl ContactsApi {
    pub(crate) fn new(client: Unosend) -> Self {
        Self { client }
    }

    /// Create a new contact.
    pub async fn create(&self, request: CreateContactRequest) -> Result<Contact, UnosendError> {
        self.client.post("/contacts", &request).await
    }

    /// List contacts in an audience.
    pub async fn list(&self, audience_id: &str) -> Result<ContactList, UnosendError> {
        self.client
            .get(&format!("/audiences/{}/contacts", audience_id))
            .await
    }

    /// Get a contact by ID.
    pub async fn get(&self, contact_id: &str) -> Result<Contact, UnosendError> {
        self.client.get(&format!("/contacts/{}", contact_id)).await
    }

    /// Delete a contact.
    pub async fn delete(&self, contact_id: &str) -> Result<(), UnosendError> {
        self.client.delete(&format!("/contacts/{}", contact_id)).await
    }
}

/// Request to create a contact.
#[derive(Debug, Clone, Serialize)]
pub struct CreateContactRequest {
    pub audience_id: String,
    pub email: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub first_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub unsubscribed: Option<bool>,
}

/// Contact information.
#[derive(Debug, Clone, Deserialize)]
pub struct Contact {
    pub id: String,
    pub email: String,
    pub first_name: Option<String>,
    pub last_name: Option<String>,
    pub unsubscribed: bool,
    pub created_at: String,
}

/// List of contacts.
#[derive(Debug, Clone, Deserialize)]
pub struct ContactList {
    pub data: Vec<Contact>,
}