ruma_client_api/filter/
get_filter.rs1pub mod v3 {
6 use ruma_common::{
11 OwnedUserId,
12 api::{auth_scheme::AccessToken, request, response},
13 metadata,
14 };
15
16 use crate::filter::FilterDefinition;
17
18 metadata! {
19 method: GET,
20 rate_limited: false,
21 authentication: AccessToken,
22 history: {
23 1.0 => "/_matrix/client/r0/user/{user_id}/filter/{filter_id}",
24 1.1 => "/_matrix/client/v3/user/{user_id}/filter/{filter_id}",
25 }
26 }
27
28 #[request(error = crate::Error)]
30 pub struct Request {
31 #[ruma_api(path)]
33 pub user_id: OwnedUserId,
34
35 #[ruma_api(path)]
37 pub filter_id: String,
38 }
39
40 #[response(error = crate::Error)]
42 pub struct Response {
43 #[ruma_api(body)]
45 pub filter: FilterDefinition,
46 }
47
48 impl Request {
49 pub fn new(user_id: OwnedUserId, filter_id: String) -> Self {
51 Self { user_id, filter_id }
52 }
53 }
54
55 impl Response {
56 pub fn new(filter: FilterDefinition) -> Self {
58 Self { filter }
59 }
60 }
61
62 #[cfg(all(test, any(feature = "client", feature = "server")))]
63 mod tests {
64 #[cfg(feature = "client")]
65 #[test]
66 fn deserialize_response() {
67 use ruma_common::api::IncomingResponse;
68
69 let res = super::Response::try_from_http_response(
70 http::Response::builder().body(b"{}" as &[u8]).unwrap(),
71 )
72 .unwrap();
73 assert!(res.filter.is_empty());
74 }
75
76 #[cfg(feature = "server")]
77 #[test]
78 fn serialize_response() {
79 use ruma_common::api::OutgoingResponse;
80
81 use crate::filter::FilterDefinition;
82
83 let res = super::Response::new(FilterDefinition::default())
84 .try_into_http_response::<Vec<u8>>()
85 .unwrap();
86 assert_eq!(res.body(), b"{}");
87 }
88 }
89}