From 995fa6e1aefd3e9ac610688a64c49ee0f9086e50 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 6 Jul 2017 23:26:52 -0700 Subject: [PATCH] Use ruma-api-macros for the tag endpoints. --- src/lib.rs | 2 +- src/r0/tag.rs | 207 ++++++++++++++++---------------------------------- 2 files changed, 65 insertions(+), 144 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c98becf0..7e183410 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,7 @@ pub mod r0 { pub mod server; pub mod session; pub mod sync; -// pub mod tag; + pub mod tag; // pub mod typing; // pub mod voip; } diff --git a/src/r0/tag.rs b/src/r0/tag.rs index 57754917..9f8b0370 100644 --- a/src/r0/tag.rs +++ b/src/r0/tag.rs @@ -2,177 +2,98 @@ /// [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-tags-tag) pub mod create_tag { - use ruma_identifiers::{UserId, RoomId}; + use ruma_api_macros::ruma_api; use ruma_events::tag::TagInfo; + use ruma_identifiers::{UserId, RoomId}; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId, - pub room_id: RoomId, - pub tag: String - } - - impl ::Endpoint for Endpoint { - type BodyParams = TagInfo; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Add a new tag to a room.", + method: Method::Put, + name: "create_tag", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/user/{}/rooms/{}/tags/{}", - params.user_id, - params.room_id, - params.tag - ) + request { + /// The room to tag. + #[ruma_api(path)] + pub room_id: RoomId, + /// The name of the tag to create. + #[ruma_api(path)] + pub tag: String, + /// Info about the tag. + #[ruma_api(body)] + pub tag_info: TagInfo, + /// The ID of the user creating the tag. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag" - } - - fn name() -> &'static str { - "create_tag" - } - - fn description() -> &'static str { - "Add a new tag to a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } } /// [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) pub mod get_tags { - use ruma_identifiers::{UserId, RoomId}; + use ruma_api_macros::ruma_api; use ruma_events::tag::TagEventContent; + use ruma_identifiers::{UserId, RoomId}; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId, - pub room_id: RoomId - } - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - pub tags: TagEventContent, - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Get the tags associated with a room.", + method: Method::Get, + name: "get_tags", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/user/{}/rooms/{}/tags", - params.user_id, - params.room_id - ) + request { + /// The room from which tags will be retrieved. + #[ruma_api(path)] + pub room_id: RoomId, + /// The user whose tags will be retrieved. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags" - } - - fn name() -> &'static str { - "get_tags" - } - - fn description() -> &'static str { - "Get the tags associated with a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false + response { + /// The user's tags for the room. + pub tags: TagEventContent, } } } /// [DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-user-userid-rooms-roomid-tags-tag) pub mod delete_tag { + use ruma_api_macros::ruma_api; use ruma_identifiers::{UserId, RoomId}; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId, - pub room_id: RoomId, - pub tag: String - } - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Delete + ruma_api! { + metadata { + description: "Remove a tag from a room.", + method: Method::Delete, + name: "delete_tag", + path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", + rate_limited: false, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/user/{}/rooms/{}/tags/{}", - params.user_id, - params.room_id, - params.tag - ) + request { + /// The tagged room. + #[ruma_api(path)] + pub room_id: RoomId, + /// The name of the tag to delete. + #[ruma_api(path)] + pub tag: String, + /// The user whose tag will be deleted. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag" - } - - fn name() -> &'static str { - "delete_tag" - } - - fn description() -> &'static str { - "Remove a tag from a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - false - } + response {} } }