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

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

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

    /// Complete a habit for a day
    pub async fn complete(
        &self,
        day: &str,
        habit_id: i64,
    ) -> Result<CompleteHabitResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::COMPLETE_HABIT, &[&day, &habit_id]);
        operation.resource_id(habit_id);
        self.client.send(operation).await
    }

    /// Start a new habit. Answers the created habit as a recording.
    pub async fn create(
        &self,
        body: &HabitRequestContent,
    ) -> Result<CreateHabitResponseContent, Error> {
        let mut operation = self.client.operation(&routes::CREATE_HABIT, &[]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Delete a habit. habitId is the recording's id.
    pub async fn delete(&self, habit_id: i64) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::DELETE_HABIT, &[&habit_id]);
        operation.resource_id(habit_id);
        self.client.send_unit(operation).await
    }

    /// Resume a paused habit
    pub async fn resume(&self, habit_id: i64) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::RESUME_HABIT, &[&habit_id]);
        operation.resource_id(habit_id);
        self.client.send_unit(operation).await
    }

    /// Pause a habit, so it stops appearing on the calendar
    pub async fn stop(&self, habit_id: i64) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::STOP_HABIT, &[&habit_id]);
        operation.resource_id(habit_id);
        self.client.send_unit(operation).await
    }

    /// Uncomplete a habit for a day
    pub async fn uncomplete(
        &self,
        day: &str,
        habit_id: i64,
    ) -> Result<UncompleteHabitResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UNCOMPLETE_HABIT, &[&day, &habit_id]);
        operation.resource_id(habit_id);
        self.client.send(operation).await
    }

    /// Edit a habit. habitId is the recording's id.
    pub async fn update(
        &self,
        habit_id: i64,
        body: &HabitRequestContent,
    ) -> Result<UpdateHabitResponseContent, Error> {
        let mut operation = self.client.operation(&routes::UPDATE_HABIT, &[&habit_id]);
        operation.resource_id(habit_id);
        operation.json(body)?;
        self.client.send(operation).await
    }
}