Skip to main content

hey_sdk/generated/services/
contacts.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 `GetContact`.
12#[derive(Debug, Clone, Default, PartialEq)]
13pub struct GetContactParams {
14    pub page: Option<String>,
15}
16
17/// Optional query parameters for `ListContacts`.
18#[derive(Debug, Clone, Default, PartialEq)]
19pub struct ListContactsParams {
20    pub page: Option<String>,
21    pub q: Option<String>,
22}
23
24pub struct Contacts<'a> {
25    client: &'a Client,
26}
27
28impl<'a> Contacts<'a> {
29    pub(crate) fn new(client: &'a Client) -> Self {
30        Self { client }
31    }
32
33    /// The client this service sends through.
34    pub fn client(&self) -> &'a Client {
35        self.client
36    }
37
38    /// Bundle a contact so their mail arrives grouped
39    pub async fn bundle(&self, contact_id: i64) -> Result<(), Error> {
40        let mut operation = self
41            .client
42            .operation(&routes::BUNDLE_CONTACT, &[&contact_id]);
43        operation.resource_id(contact_id);
44        self.client.send_unit(operation).await
45    }
46
47    /// Add a contact. Answers the contact that was created.
48    pub async fn create(
49        &self,
50        body: &CreateContactRequestContent,
51    ) -> Result<CreateContactResponseContent, Error> {
52        let mut operation = self.client.operation(&routes::CREATE_CONTACT, &[]);
53        operation.json(body)?;
54        self.client.send(operation).await
55    }
56
57    /// Clear the private note on a contact
58    pub async fn delete_note(&self, contact_id: i64) -> Result<(), Error> {
59        let mut operation = self
60            .client
61            .operation(&routes::DELETE_CONTACT_NOTE, &[&contact_id]);
62        operation.resource_id(contact_id);
63        self.client.send_unit(operation).await
64    }
65
66    /// Get a contact, with a page of the threads they are on
67    pub async fn get(
68        &self,
69        contact_id: i64,
70        params: &GetContactParams,
71    ) -> Result<Page<GetContactResponseContent>, Error> {
72        let mut operation = self.client.operation(&routes::GET_CONTACT, &[&contact_id]);
73        operation.resource_id(contact_id);
74        operation.query_optional("page", params.page.as_ref());
75        self.client.send_page(operation).await
76    }
77
78    /// Read the private note kept on a contact
79    pub async fn get_note(&self, contact_id: i64) -> Result<GetContactNoteResponseContent, Error> {
80        let mut operation = self
81            .client
82            .operation(&routes::GET_CONTACT_NOTE, &[&contact_id]);
83        operation.resource_id(contact_id);
84        self.client.send(operation).await
85    }
86
87    /// Hide a contact. Nothing is deleted — RevealContact brings them back.
88    pub async fn hide(&self, contact_id: i64) -> Result<(), Error> {
89        let mut operation = self.client.operation(&routes::HIDE_CONTACT, &[&contact_id]);
90        operation.resource_id(contact_id);
91        self.client.send_unit(operation).await
92    }
93
94    /// List contacts
95    pub async fn list(
96        &self,
97        params: &ListContactsParams,
98    ) -> Result<Page<ListContactsResponseContent>, Error> {
99        let mut operation = self.client.operation(&routes::LIST_CONTACTS, &[]);
100        operation.query_optional("page", params.page.as_ref());
101        operation.query_optional("q", params.q.as_ref());
102        self.client.send_page(operation).await
103    }
104
105    /// Put a hidden contact back in the contact list
106    pub async fn reveal(&self, contact_id: i64) -> Result<RevealContactResponseContent, Error> {
107        let mut operation = self
108            .client
109            .operation(&routes::REVEAL_CONTACT, &[&contact_id]);
110        operation.resource_id(contact_id);
111        self.client.send(operation).await
112    }
113
114    /// Stop bundling a contact's mail
115    pub async fn unbundle(&self, contact_id: i64) -> Result<(), Error> {
116        let mut operation = self
117            .client
118            .operation(&routes::UNBUNDLE_CONTACT, &[&contact_id]);
119        operation.resource_id(contact_id);
120        self.client.send_unit(operation).await
121    }
122
123    /// Edit a contact. HEY rewrites the whole contact, so send every field: a name,
124    /// address or alias left out is cleared. Answers the contact, which is not always
125    /// the one addressed — promoting an alias makes the alias primary.
126    pub async fn update(
127        &self,
128        contact_id: i64,
129        body: &ContactRequestContent,
130    ) -> Result<UpdateContactResponseContent, Error> {
131        let mut operation = self
132            .client
133            .operation(&routes::UPDATE_CONTACT, &[&contact_id]);
134        operation.resource_id(contact_id);
135        operation.json(body)?;
136        self.client.send(operation).await
137    }
138
139    /// Screen a contact in or out. Status is "approved" or "denied".
140    pub async fn update_clearance(
141        &self,
142        contact_id: i64,
143        body: &UpdateContactClearanceRequestContent,
144    ) -> Result<(), Error> {
145        let mut operation = self
146            .client
147            .operation(&routes::UPDATE_CONTACT_CLEARANCE, &[&contact_id]);
148        operation.resource_id(contact_id);
149        operation.json(body)?;
150        self.client.send_unit(operation).await
151    }
152
153    /// Write the private note on a contact, replacing whatever was there
154    pub async fn update_note(
155        &self,
156        contact_id: i64,
157        body: &ContactNoteRequestContent,
158    ) -> Result<UpdateContactNoteResponseContent, Error> {
159        let mut operation = self
160            .client
161            .operation(&routes::UPDATE_CONTACT_NOTE, &[&contact_id]);
162        operation.resource_id(contact_id);
163        operation.json(body)?;
164        self.client.send(operation).await
165    }
166}