ossify/ops/bucket/style/
list_style.rs1use std::future::Future;
6
7use http::Method;
8use serde::{Deserialize, Serialize};
9
10pub use super::get_style::StyleInfo;
11use crate::body::NoneBody;
12use crate::error::Result;
13use crate::response::BodyResponseProcessor;
14use crate::ser::OnlyKeyField;
15use crate::{Client, Ops, Prepared, Request};
16
17#[derive(Debug, Clone, Default, Serialize)]
18pub struct ListStyleParams {
19 style: OnlyKeyField,
20}
21
22#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
24#[serde(rename = "StyleList", rename_all = "PascalCase")]
25pub struct StyleList {
26 #[serde(rename = "Style", default)]
27 pub styles: Vec<StyleInfo>,
28}
29
30pub struct ListStyle;
31
32impl Ops for ListStyle {
33 type Response = BodyResponseProcessor<StyleList>;
34 type Body = NoneBody;
35 type Query = ListStyleParams;
36
37 fn prepare(self) -> Result<Prepared<ListStyleParams>> {
38 Ok(Prepared {
39 method: Method::GET,
40 query: Some(ListStyleParams::default()),
41 ..Default::default()
42 })
43 }
44}
45
46pub trait ListStyleOps {
47 fn list_style(&self) -> impl Future<Output = Result<StyleList>>;
51}
52
53impl ListStyleOps for Client {
54 async fn list_style(&self) -> Result<StyleList> {
55 self.request(ListStyle).await
56 }
57}
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn params_serialize() {
65 assert_eq!(crate::ser::to_string(&ListStyleParams::default()).unwrap(), "style");
66 }
67
68 #[test]
69 fn response_round_trip() {
70 let xml = r#"<?xml version="1.0" encoding="UTF-8"?>
71<StyleList>
72 <Style>
73 <Name>imagestyle</Name>
74 <Content>image/resize,p_50</Content>
75 <Category>image</Category>
76 <CreateTime>Wed, 20 May 2020 12:07:15 GMT</CreateTime>
77 <LastModifyTime>Wed, 21 May 2020 12:07:15 GMT</LastModifyTime>
78 </Style>
79 <Style>
80 <Name>imagestyle1</Name>
81 <Content>image/resize,w_200</Content>
82 <Category>image</Category>
83 <CreateTime>Wed, 20 May 2020 12:08:04 GMT</CreateTime>
84 <LastModifyTime>Wed, 21 May 2020 12:08:04 GMT</LastModifyTime>
85 </Style>
86</StyleList>"#;
87 let parsed: StyleList = quick_xml::de::from_str(xml).unwrap();
88 assert_eq!(parsed.styles.len(), 2);
89 assert_eq!(parsed.styles[0].name, "imagestyle");
90 assert_eq!(parsed.styles[1].content, "image/resize,w_200");
91 }
92}