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 `ListDrafts`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListDraftsParams {
    pub page: Option<String>,
}

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

impl<'a> Entries<'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
    }

    /// Reply to an entry
    pub async fn create_reply(
        &self,
        entry_id: i64,
        body: &CreateReplyRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::CREATE_REPLY, &[&entry_id]);
        operation.resource_id(entry_id);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Trash a draft (Entries::DraftsController#destroy). The id is the draft's entry id,
    /// as ListDrafts reports it.
    pub async fn delete_draft(&self, entry_id: i64) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::DELETE_DRAFT, &[&entry_id]);
        operation.resource_id(entry_id);
        self.client.send_unit(operation).await
    }

    /// List draft messages
    pub async fn list_drafts(
        &self,
        params: &ListDraftsParams,
    ) -> Result<Page<ListDraftsResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::LIST_DRAFTS, &[]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Mark an entry as spam. Denies the sender when every thread from them is already spam.
    pub async fn mark_spam(&self, entry_id: i64) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::MARK_ENTRY_SPAM, &[&entry_id]);
        operation.resource_id(entry_id);
        self.client.send_unit(operation).await
    }

    /// Get a prefilled forward of an entry: subject, quoted body and blank recipients.
    /// Send it with CreateMessage once the recipients are filled in.
    pub async fn new_forward(
        &self,
        entry_id: i64,
    ) -> Result<NewEntryForwardResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::NEW_ENTRY_FORWARD, &[&entry_id]);
        operation.resource_id(entry_id);
        self.client.send(operation).await
    }

    /// Get a prefilled reply to an entry: the quoted body and, in addressed, the
    /// participating contacts a reply goes to as HEY computes them — the sender moved onto
    /// the To line and the acting user's own addresses, aliases and catch-alls excluded.
    pub async fn new_reply(&self, entry_id: i64) -> Result<NewEntryReplyResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::NEW_ENTRY_REPLY, &[&entry_id]);
        operation.resource_id(entry_id);
        self.client.send(operation).await
    }
}