hey_sdk/generated/services/
topics.rs1#![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#[derive(Debug, Clone, Default, PartialEq)]
13pub struct GetTopicEntriesParams {
14 pub page: Option<String>,
15}
16
17#[derive(Debug, Clone, Default, PartialEq)]
19pub struct GetEverythingTopicsParams {
20 pub page: Option<String>,
21}
22
23#[derive(Debug, Clone, Default, PartialEq)]
25pub struct GetSentTopicsParams {
26 pub page: Option<String>,
27}
28
29#[derive(Debug, Clone, Default, PartialEq)]
31pub struct GetSpamTopicsParams {
32 pub page: Option<String>,
33}
34
35#[derive(Debug, Clone, Default, PartialEq)]
37pub struct GetTrashTopicsParams {
38 pub page: Option<String>,
39}
40
41#[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 pub fn client(&self) -> &'a Client {
58 self.client
59 }
60
61 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 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 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 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 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 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 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 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 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 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 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 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}