ossify/ops/object/base/
clean_restored_object.rs1use std::future::Future;
9
10use http::Method;
11use serde::Serialize;
12
13use crate::body::NoneBody;
14use crate::error::Result;
15use crate::response::EmptyResponseProcessor;
16use crate::ser::OnlyKeyField;
17use crate::{Client, Ops, Prepared, Request};
18
19#[derive(Debug, Clone, Default, Serialize)]
21#[serde(rename_all = "camelCase")]
22pub struct CleanRestoredObjectParams {
23 pub(crate) clean_restored_object: OnlyKeyField,
24}
25
26impl CleanRestoredObjectParams {
27 pub fn new() -> Self {
28 Self::default()
29 }
30}
31
32pub struct CleanRestoredObject {
34 pub object_key: String,
35 pub params: CleanRestoredObjectParams,
36}
37
38impl Ops for CleanRestoredObject {
39 type Response = EmptyResponseProcessor;
40 type Body = NoneBody;
41 type Query = CleanRestoredObjectParams;
42
43 fn prepare(self) -> Result<Prepared<CleanRestoredObjectParams>> {
44 Ok(Prepared {
45 method: Method::POST,
46 key: Some(self.object_key),
47 query: Some(self.params),
48 ..Default::default()
49 })
50 }
51}
52
53pub trait CleanRestoredObjectOperations {
55 fn clean_restored_object(&self, object_key: impl Into<String>) -> impl Future<Output = Result<()>>;
56}
57
58impl CleanRestoredObjectOperations for Client {
59 async fn clean_restored_object(&self, object_key: impl Into<String>) -> Result<()> {
60 let ops = CleanRestoredObject {
61 object_key: object_key.into(),
62 params: CleanRestoredObjectParams::new(),
63 };
64 self.request(ops).await
65 }
66}
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
73 fn test_serialize_params() {
74 let q = crate::ser::to_string(&CleanRestoredObjectParams::new()).unwrap();
75 assert_eq!(q, "cleanRestoredObject");
76 }
77
78 #[test]
79 fn test_prepare_key_method() {
80 let prepared = CleanRestoredObject {
81 object_key: "foo.jpg".into(),
82 params: CleanRestoredObjectParams::new(),
83 }
84 .prepare()
85 .unwrap();
86 assert_eq!(prepared.method, Method::POST);
87 assert_eq!(prepared.key.as_deref(), Some("foo.jpg"));
88 }
89}