hey-sdk 0.31.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(missing_docs, unreachable_pub, clippy::all, clippy::pedantic)]

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

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

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

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

    /// Get journal entry for a day
    pub async fn get_entry(&self, day: &str) -> Result<GetJournalEntryResponseContent, Error> {
        let operation = self.client.operation(&routes::GET_JOURNAL_ENTRY, &[&day]);
        self.client.send(operation).await
    }

    /// List journal entries newest first. The next page, if any, is a Link header.
    /// Pass q to search journal entry content.
    pub async fn list_entries(
        &self,
        params: &ListJournalEntriesParams,
    ) -> Result<Page<ListJournalEntriesResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::LIST_JOURNAL_ENTRIES, &[]);
        operation.query_optional("page", params.page.as_ref());
        operation.query_optional("q", params.q.as_ref());
        self.client.send_page(operation).await
    }

    /// Update the journal entry for a day: writes it, creating it if the day has none, and
    /// answers the entry as a recording. Empty content removes the entry instead, and HEY then
    /// answers 204 with no body — which is not this shape, so send that through the SDK's own
    /// journal wrapper rather than here.
    pub async fn update_entry(
        &self,
        day: &str,
        body: &UpdateJournalEntryRequestContent,
    ) -> Result<UpdateJournalEntryResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_JOURNAL_ENTRY, &[&day]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}