Skip to main content

hey_sdk/generated/services/
topics.rs

1// Generated by hey-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.
2
3#![allow(missing_docs, unreachable_pub, clippy::all, clippy::pedantic)]
4
5use crate::client::Client;
6use crate::error::Error;
7use crate::generated::routes;
8use crate::generated::types::*;
9use crate::pagination::Page;
10
11/// Optional query parameters for `GetTopicEntries`.
12#[derive(Debug, Clone, Default, PartialEq)]
13pub struct GetTopicEntriesParams {
14    pub page: Option<String>,
15}
16
17/// Optional query parameters for `GetEverythingTopics`.
18#[derive(Debug, Clone, Default, PartialEq)]
19pub struct GetEverythingTopicsParams {
20    pub page: Option<String>,
21}
22
23/// Optional query parameters for `GetSentTopics`.
24#[derive(Debug, Clone, Default, PartialEq)]
25pub struct GetSentTopicsParams {
26    pub page: Option<String>,
27}
28
29/// Optional query parameters for `GetSpamTopics`.
30#[derive(Debug, Clone, Default, PartialEq)]
31pub struct GetSpamTopicsParams {
32    pub page: Option<String>,
33}
34
35/// Optional query parameters for `GetTrashTopics`.
36#[derive(Debug, Clone, Default, PartialEq)]
37pub struct GetTrashTopicsParams {
38    pub page: Option<String>,
39}
40
41/// Optional query parameters for `TrashTopic`.
42#[derive(Debug, Clone, Default, PartialEq)]
43pub struct TrashTopicParams {
44    pub confirm_destroy: Option<String>,
45}
46
47pub struct Topics<'a> {
48    client: &'a Client,
49}
50
51impl<'a> Topics<'a> {
52    pub(crate) fn new(client: &'a Client) -> Self {
53        Self { client }
54    }
55
56    /// The client this service sends through.
57    pub fn client(&self) -> &'a Client {
58        self.client
59    }
60
61    /// Empty the spam box. Runs synchronously, so it can take a while on a large mailbox.
62    pub async fn empty_spam(&self) -> Result<(), Error> {
63        let operation = self.client.operation(&routes::EMPTY_SPAM, &[]);
64        self.client.send_unit(operation).await
65    }
66
67    /// Empty the trash. Runs synchronously, so it can take a while on a large mailbox.
68    pub async fn empty_trash(&self) -> Result<(), Error> {
69        let operation = self.client.operation(&routes::EMPTY_TRASH, &[]);
70        self.client.send_unit(operation).await
71    }
72
73    /// Get a topic
74    pub async fn get(&self, topic_id: i64) -> Result<GetTopicResponseContent, Error> {
75        let mut operation = self.client.operation(&routes::GET_TOPIC, &[&topic_id]);
76        operation.resource_id(topic_id);
77        self.client.send(operation).await
78    }
79
80    /// Get entries for a topic
81    pub async fn get_entries(
82        &self,
83        topic_id: i64,
84        params: &GetTopicEntriesParams,
85    ) -> Result<Page<GetTopicEntriesResponseContent>, Error> {
86        let mut operation = self
87            .client
88            .operation(&routes::GET_TOPIC_ENTRIES, &[&topic_id]);
89        operation.resource_id(topic_id);
90        operation.query_optional("page", params.page.as_ref());
91        self.client.send_page(operation).await
92    }
93
94    /// Get all topics (everything view)
95    pub async fn get_everything(
96        &self,
97        params: &GetEverythingTopicsParams,
98    ) -> Result<Page<GetEverythingTopicsResponseContent>, Error> {
99        let mut operation = self.client.operation(&routes::GET_EVERYTHING_TOPICS, &[]);
100        operation.query_optional("page", params.page.as_ref());
101        self.client.send_page(operation).await
102    }
103
104    /// Get sent topics
105    pub async fn get_sent(
106        &self,
107        params: &GetSentTopicsParams,
108    ) -> Result<Page<GetSentTopicsResponseContent>, Error> {
109        let mut operation = self.client.operation(&routes::GET_SENT_TOPICS, &[]);
110        operation.query_optional("page", params.page.as_ref());
111        self.client.send_page(operation).await
112    }
113
114    /// Get spam topics
115    pub async fn get_spam(
116        &self,
117        params: &GetSpamTopicsParams,
118    ) -> Result<Page<GetSpamTopicsResponseContent>, Error> {
119        let mut operation = self.client.operation(&routes::GET_SPAM_TOPICS, &[]);
120        operation.query_optional("page", params.page.as_ref());
121        self.client.send_page(operation).await
122    }
123
124    /// Get trash topics
125    pub async fn get_trash(
126        &self,
127        params: &GetTrashTopicsParams,
128    ) -> Result<Page<GetTrashTopicsResponseContent>, Error> {
129        let mut operation = self.client.operation(&routes::GET_TRASH_TOPICS, &[]);
130        operation.query_optional("page", params.page.as_ref());
131        self.client.send_page(operation).await
132    }
133
134    /// Mark a spam topic as ham. Every other spam topic from the same sender is hammed too.
135    pub async fn mark_ham(&self, topic_id: i64) -> Result<(), Error> {
136        let mut operation = self.client.operation(&routes::MARK_TOPIC_HAM, &[&topic_id]);
137        operation.resource_id(topic_id);
138        self.client.send_unit(operation).await
139    }
140
141    /// Move a topic to another box.
142    ///
143    /// Answers 204 without moving anything when the acting user has no posting for the topic.
144    pub async fn move_topic(
145        &self,
146        topic_id: i64,
147        body: &MoveTopicRequestContent,
148    ) -> Result<(), Error> {
149        let mut operation = self.client.operation(&routes::MOVE_TOPIC, &[&topic_id]);
150        operation.resource_id(topic_id);
151        operation.json(body)?;
152        self.client.send_unit(operation).await
153    }
154
155    /// Restore a topic from the trash or the catch-all
156    pub async fn restore(&self, topic_id: i64) -> Result<(), Error> {
157        let mut operation = self.client.operation(&routes::RESTORE_TOPIC, &[&topic_id]);
158        operation.resource_id(topic_id);
159        self.client.send_unit(operation).await
160    }
161
162    /// Trash a topic.
163    ///
164    /// A shared topic redirects to the removal confirmation page unless confirm_destroy is set,
165    /// so always pass it when trashing something that might be shared.
166    pub async fn trash(&self, topic_id: i64, params: &TrashTopicParams) -> Result<(), Error> {
167        let mut operation = self.client.operation(&routes::TRASH_TOPIC, &[&topic_id]);
168        operation.resource_id(topic_id);
169        operation.query_optional("confirm_destroy", params.confirm_destroy.as_ref());
170        self.client.send_unit(operation).await
171    }
172}