From dfb45a762f7f16dce16b7ae087ab3f2a0c3b9eea Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 19 May 2017 21:25:18 -0700 Subject: [PATCH] Use ruma-api-macros for the directory endpoints. --- src/lib.rs | 2 +- src/r0/directory.rs | 94 +++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 55 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1c580537..ec0780b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ pub mod r0 { pub mod config; pub mod contact; pub mod context; -// pub mod directory; + pub mod directory; // pub mod filter; // pub mod media; // pub mod membership; diff --git a/src/r0/directory.rs b/src/r0/directory.rs index cd7aa498..9190d11e 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -3,67 +3,53 @@ /// [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) pub mod get_public_rooms { use ruma_identifiers::{RoomId, RoomAliasId}; + use ruma_api_macros::ruma_api; + + ruma_api! { + metadata { + description: "Get the list of rooms in this homeserver's public directory.", + method: Method::Get, + name: "get_public_rooms", + path: "/_matrix/client/r0/publicRooms", + rate_limited: false, + requires_authentication: false, + } + + request {} + + response { + /// A pagination token for the response. + pub start: String, + /// A paginated chunk of public rooms. + pub chunk: Vec, + /// A pagination token for the response. + pub end: String + } + } /// A chunk of the response, describing one room #[derive(Clone, Debug, Deserialize, Serialize)] pub struct PublicRoomsChunk { - pub world_readable: bool, - #[serde(skip_serializing_if = "Option::is_none")] - pub topic: Option, - pub num_joined_members: u64, + /// Aliases of the room. + pub aliases: Vec, + /// The URL for the room's avatar, if one is set. #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, - pub room_id: RoomId, + /// Whether guest users may join the room and participate in it. + /// + /// If they can, they will be subject to ordinary power level rules like any other user. pub guest_can_join: bool, - pub aliases: Vec, + /// The name of the room, if any. #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option - } - - /// This API response type - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub start: String, - pub chunk: Vec, - pub end: String - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = (); - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get - } - - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() - } - - fn router_path() -> &'static str { - "/_matrix/client/r0/publicRooms" - } - - fn name() -> &'static str { - "get_public_rooms" - } - - fn description() -> &'static str { - "Get the list of rooms in this homeserver's public directory." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false - } + pub name: Option, + /// The number of members joined to the room. + pub num_joined_members: u64, + /// The ID of the room. + pub room_id: RoomId, + /// The topic of the room, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub topic: Option, + /// Whether the room may be viewed by guest users without joining. + pub world_readable: bool, } }