use crate::{
Error,
error::normal_error,
request::{Oss, OssRequest},
};
use bytes::Bytes;
use http::Method;
use http_body_util::Full;
pub struct PutBucketLifecycle {
req: OssRequest,
body: Option<String>,
}
impl PutBucketLifecycle {
pub(super) fn new(oss: Oss) -> Self {
let mut req = OssRequest::new(oss, Method::PUT);
req.insert_query("lifecycle", "");
PutBucketLifecycle { req, body: None }
}
pub fn set_configuration(mut self, xml: impl ToString) -> Self {
self.body = Some(xml.to_string());
self
}
pub async fn send(mut self) -> Result<(), Error> {
let body = self.body.ok_or(Error::MissingRequestBody)?;
self.req.set_body(Full::new(Bytes::from(body)));
let response = self.req.send_to_oss()?.await?;
match response.status() {
code if code.is_success() => Ok(()),
_ => Err(normal_error(response).await),
}
}
}