Skip to main content

io_gmail/v1/rest/settings/
update_vacation.rs

1//! Update the Gmail vacation settings (`users.settings.updateVacation`).
2//!
3//! <https://developers.google.com/gmail/api/reference/rest/v1/users.settings/updateVacation>
4
5use alloc::format;
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use url::Url;
10
11use crate::{
12    coroutine::*,
13    gmail_try,
14    v1::{
15        rest::settings::GmailVacationSettings,
16        send::{GMAIL_API_BASE, GmailSend, GmailSendError, GmailSendOutput},
17    },
18};
19
20/// I/O-free coroutine updating the Gmail vacation responder settings
21/// (`users.settings.updateVacation`).
22pub struct GmailVacationUpdate {
23    send: GmailSend<GmailVacationSettings>,
24}
25
26impl GmailVacationUpdate {
27    /// Builds the `users.settings.updateVacation` request wrapping the given
28    /// settings.
29    pub fn new(
30        auth: &HttpAuthBearer,
31        user_id: &str,
32        settings: GmailVacationSettings,
33    ) -> Result<Self, GmailSendError> {
34        debug!("prepare gmail vacation settings update");
35        trace!("settings: {settings:?}");
36
37        let url =
38            Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/settings/vacation"))?;
39        let send = GmailSend::put_json(auth, url, &settings)?;
40
41        Ok(Self { send })
42    }
43}
44
45impl GmailCoroutine for GmailVacationUpdate {
46    type Yield = GmailYield;
47    type Return = Result<GmailSendOutput<GmailVacationSettings>, GmailSendError>;
48
49    fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
50        let out = gmail_try!(&mut self.send, arg);
51        debug!("vacation settings updated");
52        trace!("out: {out:?}");
53        GmailCoroutineState::Complete(Ok(out))
54    }
55}