hey-sdk 0.30.0

Rust client for the HEY API, generated from a Smithy model of the API
Documentation
// Generated by hey-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.

#![allow(clippy::too_many_arguments)]

use crate::client::Client;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;
use crate::pagination::Page;

/// Optional query parameters for `GetContact`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetContactParams {
    pub page: Option<String>,
}

/// Optional query parameters for `ListContacts`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListContactsParams {
    pub page: Option<String>,
    pub q: Option<String>,
}

pub struct Contacts<'a> {
    client: &'a Client,
}

impl<'a> Contacts<'a> {
    pub(crate) fn new(client: &'a Client) -> Self {
        Self { client }
    }

    /// The client this service sends through.
    pub fn client(&self) -> &'a Client {
        self.client
    }

    /// Bundle a contact so their mail arrives grouped
    pub async fn bundle(&self, contact_id: i64) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::BUNDLE_CONTACT, &[&contact_id]);
        operation.resource_id(contact_id);
        self.client.send_unit(operation).await
    }

    /// Add a contact. Answers the contact that was created.
    pub async fn create(
        &self,
        body: &CreateContactRequestContent,
    ) -> Result<CreateContactResponseContent, Error> {
        let mut operation = self.client.operation(&routes::CREATE_CONTACT, &[]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Clear the private note on a contact
    pub async fn delete_note(&self, contact_id: i64) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::DELETE_CONTACT_NOTE, &[&contact_id]);
        operation.resource_id(contact_id);
        self.client.send_unit(operation).await
    }

    /// Get a contact, with a page of the threads they are on
    pub async fn get(
        &self,
        contact_id: i64,
        params: &GetContactParams,
    ) -> Result<Page<GetContactResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::GET_CONTACT, &[&contact_id]);
        operation.resource_id(contact_id);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Read the private note kept on a contact
    pub async fn get_note(&self, contact_id: i64) -> Result<GetContactNoteResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::GET_CONTACT_NOTE, &[&contact_id]);
        operation.resource_id(contact_id);
        self.client.send(operation).await
    }

    /// Hide a contact. Nothing is deleted — RevealContact brings them back.
    pub async fn hide(&self, contact_id: i64) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::HIDE_CONTACT, &[&contact_id]);
        operation.resource_id(contact_id);
        self.client.send_unit(operation).await
    }

    /// List contacts
    pub async fn list(
        &self,
        params: &ListContactsParams,
    ) -> Result<Page<ListContactsResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::LIST_CONTACTS, &[]);
        operation.query_optional("page", params.page.as_ref());
        operation.query_optional("q", params.q.as_ref());
        self.client.send_page(operation).await
    }

    /// Put a hidden contact back in the contact list
    pub async fn reveal(&self, contact_id: i64) -> Result<RevealContactResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::REVEAL_CONTACT, &[&contact_id]);
        operation.resource_id(contact_id);
        self.client.send(operation).await
    }

    /// Stop bundling a contact's mail
    pub async fn unbundle(&self, contact_id: i64) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::UNBUNDLE_CONTACT, &[&contact_id]);
        operation.resource_id(contact_id);
        self.client.send_unit(operation).await
    }

    /// Edit a contact. HEY rewrites the whole contact, so send every field: a name,
    /// address or alias left out is cleared. Answers the contact, which is not always
    /// the one addressed — promoting an alias makes the alias primary.
    pub async fn update(
        &self,
        contact_id: i64,
        body: &ContactRequestContent,
    ) -> Result<UpdateContactResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_CONTACT, &[&contact_id]);
        operation.resource_id(contact_id);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Screen a contact in or out. Status is "approved" or "denied".
    pub async fn update_clearance(
        &self,
        contact_id: i64,
        body: &UpdateContactClearanceRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_CONTACT_CLEARANCE, &[&contact_id]);
        operation.resource_id(contact_id);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Write the private note on a contact, replacing whatever was there
    pub async fn update_note(
        &self,
        contact_id: i64,
        body: &ContactNoteRequestContent,
    ) -> Result<UpdateContactNoteResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_CONTACT_NOTE, &[&contact_id]);
        operation.resource_id(contact_id);
        operation.json(body)?;
        self.client.send(operation).await
    }
}