pub mod v3 {
use ruma_common::{
api::{request, response, Metadata},
metadata, OwnedUserId,
};
use crate::filter::FilterDefinition;
const METADATA: Metadata = metadata! {
method: GET,
rate_limited: false,
authentication: AccessToken,
history: {
1.0 => "/_matrix/client/r0/user/:user_id/filter/:filter_id",
1.1 => "/_matrix/client/v3/user/:user_id/filter/:filter_id",
}
};
#[request(error = crate::Error)]
pub struct Request {
#[ruma_api(path)]
pub user_id: OwnedUserId,
#[ruma_api(path)]
pub filter_id: String,
}
#[response(error = crate::Error)]
pub struct Response {
#[ruma_api(body)]
pub filter: FilterDefinition,
}
impl Request {
pub fn new(user_id: OwnedUserId, filter_id: String) -> Self {
Self { user_id, filter_id }
}
}
impl Response {
pub fn new(filter: FilterDefinition) -> Self {
Self { filter }
}
}
#[cfg(all(test, any(feature = "client", feature = "server")))]
mod tests {
#[cfg(feature = "client")]
#[test]
fn deserialize_response() {
use ruma_common::api::IncomingResponse;
let res = super::Response::try_from_http_response(
http::Response::builder().body(b"{}" as &[u8]).unwrap(),
)
.unwrap();
assert!(res.filter.is_empty());
}
#[cfg(feature = "server")]
#[test]
fn serialize_response() {
use ruma_common::api::OutgoingResponse;
use crate::filter::FilterDefinition;
let res = super::Response::new(FilterDefinition::default())
.try_into_http_response::<Vec<u8>>()
.unwrap();
assert_eq!(res.body(), b"{}");
}
}
}