diff --git a/src/lib.rs b/src/lib.rs index f2f6c29e..625d1a56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ pub mod r0 { // pub mod push; // pub mod receipt; // pub mod redact; -// pub mod room; + pub mod room; // pub mod search; pub mod send; // pub mod server; diff --git a/src/r0/room.rs b/src/r0/room.rs index 38f2f62d..de6fbf13 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -3,26 +3,40 @@ /// [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom) pub mod create_room { use ruma_identifiers::{RoomId, UserId}; + use ruma_api_macros::ruma_api; - /// The request type. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub creation_content: Option, - #[serde(skip_serializing_if = "Vec::is_empty")] - #[serde(default)] - pub invite: Vec, - #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub preset: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub room_alias_name: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub topic: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub visibility: Option, // TODO: should be an enum ["public", "private"] - // TODO: missing `invite_3pid`, `initial_state` + ruma_api! { + metadata { + description: "Create a new room.", + method: Method::Post, + name: "create_room", + path: "/_matrix/client/r0/createRoom", + rate_limited: false, + requires_authentication: true, + } + + request { + #[serde(skip_serializing_if = "Option::is_none")] + pub creation_content: Option, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub invite: Vec, + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub preset: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub room_alias_name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub topic: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub visibility: Option, // TODO: should be an enum ["public", "private"] + // TODO: missing `invite_3pid`, `initial_state` + } + + response { + pub room_id: RoomId, + } } /// Extra options to be added to the `m.room.create` event. @@ -33,16 +47,6 @@ pub mod create_room { pub federate: Option, } - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - /// The response type. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub room_id: RoomId, - } - /// A convenience parameter for setting a few default state events. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum RoomPreset { @@ -56,39 +60,4 @@ pub mod create_room { #[serde(rename="trusted_private_chat")] TrustedPrivateChat, } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Post - } - - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() - } - - fn router_path() -> &'static str { - "/_matrix/client/r0/createRoom" - } - - fn name() -> &'static str { - "create_room" - } - - fn description() -> &'static str { - "Create a new room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } - } }