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

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

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

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

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

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

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

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

    /// Empty the spam box. Runs synchronously, so it can take a while on a large mailbox.
    pub async fn empty_spam(&self) -> Result<(), Error> {
        let operation = self.client.operation(&routes::EMPTY_SPAM, &[]);
        self.client.send_unit(operation).await
    }

    /// Empty the trash. Runs synchronously, so it can take a while on a large mailbox.
    pub async fn empty_trash(&self) -> Result<(), Error> {
        let operation = self.client.operation(&routes::EMPTY_TRASH, &[]);
        self.client.send_unit(operation).await
    }

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

    /// Get entries for a topic
    pub async fn get_entries(
        &self,
        topic_id: i64,
        params: &GetTopicEntriesParams,
    ) -> Result<Page<GetTopicEntriesResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::GET_TOPIC_ENTRIES, &[&topic_id]);
        operation.resource_id(topic_id);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Get all topics (everything view)
    pub async fn get_everything(
        &self,
        params: &GetEverythingTopicsParams,
    ) -> Result<Page<GetEverythingTopicsResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::GET_EVERYTHING_TOPICS, &[]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Get sent topics
    pub async fn get_sent(
        &self,
        params: &GetSentTopicsParams,
    ) -> Result<Page<GetSentTopicsResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::GET_SENT_TOPICS, &[]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Get spam topics
    pub async fn get_spam(
        &self,
        params: &GetSpamTopicsParams,
    ) -> Result<Page<GetSpamTopicsResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::GET_SPAM_TOPICS, &[]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Get trash topics
    pub async fn get_trash(
        &self,
        params: &GetTrashTopicsParams,
    ) -> Result<Page<GetTrashTopicsResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::GET_TRASH_TOPICS, &[]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Mark a spam topic as ham. Every other spam topic from the same sender is hammed too.
    pub async fn mark_ham(&self, topic_id: i64) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::MARK_TOPIC_HAM, &[&topic_id]);
        operation.resource_id(topic_id);
        self.client.send_unit(operation).await
    }

    /// Move a topic to another box.
    ///
    /// Answers 204 without moving anything when the acting user has no posting for the topic.
    pub async fn move_topic(
        &self,
        topic_id: i64,
        body: &MoveTopicRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::MOVE_TOPIC, &[&topic_id]);
        operation.resource_id(topic_id);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Restore a topic from the trash or the catch-all
    pub async fn restore(&self, topic_id: i64) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::RESTORE_TOPIC, &[&topic_id]);
        operation.resource_id(topic_id);
        self.client.send_unit(operation).await
    }

    /// Trash a topic.
    ///
    /// A shared topic redirects to the removal confirmation page unless confirm_destroy is set,
    /// so always pass it when trashing something that might be shared.
    pub async fn trash(&self, topic_id: i64, params: &TrashTopicParams) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::TRASH_TOPIC, &[&topic_id]);
        operation.resource_id(topic_id);
        operation.query_optional("confirm_destroy", params.confirm_destroy.as_ref());
        self.client.send_unit(operation).await
    }
}