Skip to main content

hey_sdk/generated/services/
entries.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 `ListDrafts`.
12#[derive(Debug, Clone, Default, PartialEq)]
13pub struct ListDraftsParams {
14    pub page: Option<String>,
15}
16
17pub struct Entries<'a> {
18    client: &'a Client,
19}
20
21impl<'a> Entries<'a> {
22    pub(crate) fn new(client: &'a Client) -> Self {
23        Self { client }
24    }
25
26    /// The client this service sends through.
27    pub fn client(&self) -> &'a Client {
28        self.client
29    }
30
31    /// Reply to an entry
32    pub async fn create_reply(
33        &self,
34        entry_id: i64,
35        body: &CreateReplyRequestContent,
36    ) -> Result<(), Error> {
37        let mut operation = self.client.operation(&routes::CREATE_REPLY, &[&entry_id]);
38        operation.resource_id(entry_id);
39        operation.json(body)?;
40        self.client.send_unit(operation).await
41    }
42
43    /// Trash a draft (Entries::DraftsController#destroy). The id is the draft's entry id,
44    /// as ListDrafts reports it.
45    pub async fn delete_draft(&self, entry_id: i64) -> Result<(), Error> {
46        let mut operation = self.client.operation(&routes::DELETE_DRAFT, &[&entry_id]);
47        operation.resource_id(entry_id);
48        self.client.send_unit(operation).await
49    }
50
51    /// List draft messages
52    pub async fn list_drafts(
53        &self,
54        params: &ListDraftsParams,
55    ) -> Result<Page<ListDraftsResponseContent>, Error> {
56        let mut operation = self.client.operation(&routes::LIST_DRAFTS, &[]);
57        operation.query_optional("page", params.page.as_ref());
58        self.client.send_page(operation).await
59    }
60
61    /// Mark an entry as spam. Denies the sender when every thread from them is already spam.
62    pub async fn mark_spam(&self, entry_id: i64) -> Result<(), Error> {
63        let mut operation = self
64            .client
65            .operation(&routes::MARK_ENTRY_SPAM, &[&entry_id]);
66        operation.resource_id(entry_id);
67        self.client.send_unit(operation).await
68    }
69
70    /// Get a prefilled forward of an entry: subject, quoted body and blank recipients.
71    /// Send it with CreateMessage once the recipients are filled in.
72    pub async fn new_forward(
73        &self,
74        entry_id: i64,
75    ) -> Result<NewEntryForwardResponseContent, Error> {
76        let mut operation = self
77            .client
78            .operation(&routes::NEW_ENTRY_FORWARD, &[&entry_id]);
79        operation.resource_id(entry_id);
80        self.client.send(operation).await
81    }
82
83    /// Get a prefilled reply to an entry: the quoted body and, in addressed, the
84    /// participating contacts a reply goes to as HEY computes them — the sender moved onto
85    /// the To line and the acting user's own addresses, aliases and catch-alls excluded.
86    pub async fn new_reply(&self, entry_id: i64) -> Result<NewEntryReplyResponseContent, Error> {
87        let mut operation = self
88            .client
89            .operation(&routes::NEW_ENTRY_REPLY, &[&entry_id]);
90        operation.resource_id(entry_id);
91        self.client.send(operation).await
92    }
93}