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::*;

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

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

    /// Create a new message (start a new topic).
    /// The acting sender ID must be included; the Go SDK resolves this automatically.
    /// Every message is created drafted on HEY's side; without entry.status the server
    /// delivers it, while entry.status "drafted" leaves it as a draft and answers
    /// 204 with a Location header naming /messages/{entry_id}.
    pub async fn create(&self, body: &CreateMessageRequestContent) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::CREATE_MESSAGE, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Get a message
    pub async fn get(&self, message_id: i64) -> Result<GetMessageResponseContent, Error> {
        let mut operation = self.client.operation(&routes::GET_MESSAGE, &[&message_id]);
        operation.resource_id(message_id);
        self.client.send(operation).await
    }

    /// A draft's editable state: content, recipients and scheduled delivery as the
    /// composer would load them (GET /messages/{id}/edit).
    pub async fn get_edit(&self, message_id: i64) -> Result<GetMessageEditResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::GET_MESSAGE_EDIT, &[&message_id]);
        operation.resource_id(message_id);
        self.client.send(operation).await
    }

    /// Revise a message entry (MessagesController#update). With entry.status "drafted" the
    /// entry is saved as a draft (204 + Location, like CreateMessage); without it a draft is
    /// delivered through the undo-delay window. A trashed draft is silently restored first.
    /// The revision is not a patch: subject, content and any scheduled delivery are rewritten
    /// from this request (an omitted scheduled delivery clears one), while recipients are
    /// replaced only when entry.addressed is present.
    ///
    /// Not naturally idempotent despite the PUT: without the drafted status this request
    /// *delivers*, so a transparent retry after an ambiguous first attempt could send the
    /// message again. The client must not retry it.
    pub async fn update(
        &self,
        message_id: i64,
        body: &CreateMessageRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_MESSAGE, &[&message_id]);
        operation.resource_id(message_id);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }
}