use log::trace;
use url::Url;
use crate::{
coroutine::*,
rfc4918::{WebdavAuth, proppatch::Proppatch, send::SendError},
rfc6352::addressbook::{Addressbook, join_path, property_set},
};
#[derive(Debug)]
pub struct UpdateAddressbook {
state: State,
}
impl UpdateAddressbook {
pub fn new(
base_url: &Url,
auth: &WebdavAuth,
user_agent: &str,
home_set_path: &str,
addressbook: &Addressbook,
) -> Self {
let path = join_path(home_set_path, &addressbook.id);
let set = property_set(addressbook);
let proppatch = Proppatch::new(base_url, auth, user_agent, &path, &set);
Self {
state: State::Proppatch(proppatch),
}
}
}
impl WebdavCoroutine for UpdateAddressbook {
type Yield = WebdavYield;
type Return = Result<(), SendError>;
fn resume(&mut self, arg: Option<&[u8]>) -> WebdavCoroutineState<Self::Yield, Self::Return> {
trace!("sending request");
match &mut self.state {
State::Proppatch(proppatch) => proppatch.resume(arg),
}
}
}
#[derive(Debug)]
enum State {
Proppatch(Proppatch),
}