From e2406cc8f085d26b0c3c4ec24c975463d98f70ff Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 30 Aug 2020 22:44:27 +0200 Subject: [PATCH] client-api: Update directory endpoints to the new API standards --- .../src/r0/directory/get_public_rooms.rs | 20 +++++++++++++++++++ .../src/r0/directory/get_room_visibility.rs | 18 ++++++++++++++++- .../src/r0/directory/set_room_visibility.rs | 19 +++++++++++++++++- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/ruma-client-api/src/r0/directory/get_public_rooms.rs b/ruma-client-api/src/r0/directory/get_public_rooms.rs index 5c4995b3..a03bc0d0 100644 --- a/ruma-client-api/src/r0/directory/get_public_rooms.rs +++ b/ruma-client-api/src/r0/directory/get_public_rooms.rs @@ -14,6 +14,8 @@ ruma_api! { requires_authentication: false, } + #[derive(Default)] + #[non_exhaustive] request: { /// Limit for the number of results to return. #[serde(skip_serializing_if = "Option::is_none")] @@ -33,23 +35,41 @@ ruma_api! { pub server: Option<&'a str>, } + #[non_exhaustive] response: { /// A paginated chunk of public rooms. pub chunk: Vec, /// A pagination token for the response. + #[serde(skip_serializing_if = "Option::is_none")] pub next_batch: Option, /// A pagination token that allows fetching previous results. + #[serde(skip_serializing_if = "Option::is_none")] pub prev_batch: Option, /// An estimate on the total number of public rooms, if the server has an estimate. + #[serde(skip_serializing_if = "Option::is_none")] pub total_room_count_estimate: Option, } error: crate::Error } +impl<'a> Request<'a> { + /// Creates an empty `Request`. + pub fn new() -> Self { + Default::default() + } +} + +impl Response { + /// Creates a new `Response` with the given room list chunk. + pub fn new(chunk: Vec) -> Self { + Self { chunk, next_batch: None, prev_batch: None, total_room_count_estimate: None } + } +} + #[cfg(test)] mod tests { use std::convert::TryInto; diff --git a/ruma-client-api/src/r0/directory/get_room_visibility.rs b/ruma-client-api/src/r0/directory/get_room_visibility.rs index b9be8413..44320071 100644 --- a/ruma-client-api/src/r0/directory/get_room_visibility.rs +++ b/ruma-client-api/src/r0/directory/get_room_visibility.rs @@ -15,12 +15,14 @@ ruma_api! { requires_authentication: false, } + #[non_exhaustive] request: { /// The ID of the room of which to request the visibility. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, } + #[non_exhaustive] response: { /// Visibility of the room. pub visibility: Visibility, @@ -28,3 +30,17 @@ ruma_api! { error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given room ID. + pub fn new(room_id: &'a RoomId) -> Self { + Self { room_id } + } +} + +impl Response { + /// Creates a new `Response` with the given visibility. + pub fn new(visibility: Visibility) -> Self { + Self { visibility } + } +} diff --git a/ruma-client-api/src/r0/directory/set_room_visibility.rs b/ruma-client-api/src/r0/directory/set_room_visibility.rs index 1c6426ee..c21fc75a 100644 --- a/ruma-client-api/src/r0/directory/set_room_visibility.rs +++ b/ruma-client-api/src/r0/directory/set_room_visibility.rs @@ -15,16 +15,33 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// The ID of the room of which to set the visibility. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, /// New visibility setting for the room. pub visibility: Visibility, } + #[derive(Default)] + #[non_exhaustive] response: {} error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given room ID and visibility. + pub fn new(room_id: &'a RoomId, visibility: Visibility) -> Self { + Self { room_id, visibility } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +}