jmap_client/vacation_response/
helpers.rs1use crate::{
13 client::Client,
14 core::{
15 get::GetRequest,
16 request::{Arguments, Request},
17 response::{VacationResponseGetResponse, VacationResponseSetResponse},
18 set::{SetObject, SetRequest},
19 },
20 Method, Set, URI,
21};
22
23use super::{Property, VacationResponse};
24
25impl Client {
26 #[maybe_async::maybe_async]
27 pub async fn vacation_response_create(
28 &self,
29 subject: impl Into<String>,
30 text_body: Option<impl Into<String>>,
31 html_body: Option<impl Into<String>>,
32 ) -> crate::Result<VacationResponse> {
33 let mut request = self.build();
34 let created_id = request
35 .set_vacation_response()
36 .create()
37 .is_enabled(true)
38 .subject(Some(subject))
39 .text_body(text_body)
40 .html_body(html_body)
41 .create_id()
42 .unwrap();
43
44 request
45 .send_single::<VacationResponseSetResponse>()
46 .await?
47 .created(&created_id)
48 }
49
50 #[maybe_async::maybe_async]
51 pub async fn vacation_response_enable(
52 &self,
53 subject: impl Into<String>,
54 text_body: Option<impl Into<String>>,
55 html_body: Option<impl Into<String>>,
56 ) -> crate::Result<Option<VacationResponse>> {
57 let mut request = self.build();
58 request
59 .set_vacation_response()
60 .update("singleton")
61 .is_enabled(true)
62 .subject(Some(subject))
63 .text_body(text_body)
64 .html_body(html_body);
65
66 request
67 .send_single::<VacationResponseSetResponse>()
68 .await?
69 .updated("singleton")
70 }
71
72 #[maybe_async::maybe_async]
73 pub async fn vacation_response_disable(&self) -> crate::Result<Option<VacationResponse>> {
74 let mut request = self.build();
75 request
76 .set_vacation_response()
77 .update("singleton")
78 .is_enabled(false);
79
80 request
81 .send_single::<VacationResponseSetResponse>()
82 .await?
83 .updated("singleton")
84 }
85
86 #[maybe_async::maybe_async]
87 pub async fn vacation_response_set_dates(
88 &self,
89 from_date: Option<i64>,
90 to_date: Option<i64>,
91 ) -> crate::Result<Option<VacationResponse>> {
92 let mut request = self.build();
93 request
94 .set_vacation_response()
95 .update("singleton")
96 .is_enabled(true)
97 .from_date(from_date)
98 .to_date(to_date);
99
100 request
101 .send_single::<VacationResponseSetResponse>()
102 .await?
103 .updated("singleton")
104 }
105
106 #[maybe_async::maybe_async]
107 pub async fn vacation_response_get(
108 &self,
109 properties: Option<impl IntoIterator<Item = Property>>,
110 ) -> crate::Result<Option<VacationResponse>> {
111 let mut request = self.build();
112 let get_request = request.get_vacation_response().ids(["singleton"]);
113 if let Some(properties) = properties {
114 get_request.properties(properties.into_iter());
115 }
116 request
117 .send_single::<VacationResponseGetResponse>()
118 .await
119 .map(|mut r| r.take_list().pop())
120 }
121
122 #[maybe_async::maybe_async]
123 pub async fn vacation_response_destroy(&self) -> crate::Result<()> {
124 let mut request = self.build();
125 request.set_vacation_response().destroy(["singleton"]);
126 request
127 .send_single::<VacationResponseSetResponse>()
128 .await?
129 .destroyed("singleton")
130 }
131}
132
133impl Request<'_> {
134 pub fn get_vacation_response(&mut self) -> &mut GetRequest<VacationResponse<Set>> {
135 self.add_capability(URI::VacationResponse);
136 self.add_method_call(
137 Method::GetVacationResponse,
138 Arguments::vacation_response_get(self.params(Method::GetVacationResponse)),
139 )
140 .vacation_response_get_mut()
141 }
142
143 #[maybe_async::maybe_async]
144 pub async fn send_get_vacation_response(self) -> crate::Result<VacationResponseGetResponse> {
145 self.send_single().await
146 }
147
148 pub fn set_vacation_response(&mut self) -> &mut SetRequest<VacationResponse<Set>> {
149 self.add_capability(URI::VacationResponse);
150 self.add_method_call(
151 Method::SetVacationResponse,
152 Arguments::vacation_response_set(self.params(Method::GetVacationResponse)),
153 )
154 .vacation_response_set_mut()
155 }
156
157 #[maybe_async::maybe_async]
158 pub async fn send_set_vacation_response(self) -> crate::Result<VacationResponseSetResponse> {
159 self.send_single().await
160 }
161}