diff --git a/src/lib.rs b/src/lib.rs index d5a123f8..ca041618 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ pub mod r0 { pub mod media; pub mod membership; pub mod presence; -// pub mod profile; + pub mod profile; // pub mod push; // pub mod receipt; // pub mod redact; diff --git a/src/r0/profile.rs b/src/r0/profile.rs index a5aaff7d..5f49499c 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -2,303 +2,145 @@ /// [GET /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname) pub mod get_display_name { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - 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 display name of a user.", + method: Method::Get, + name: "get_display_name", + path: "/_matrix/client/r0/profile/:user_id/displayname", + rate_limited: false, + requires_authentication: false, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/profile/{}/displayname", - params.user_id - ) + request { + /// The user whose display name will be retrieved. + #[ruma_api(path)] + pub user_id: UserId } - fn router_path() -> &'static str { - "/_matrix/client/r0/profile/:user_id/displayname" - } - - fn name() -> &'static str { - "get_display_name" - } - - fn description() -> &'static str { - "Get the display name of a user." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false + response { + /// The user's display name, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option } } } - /// [PUT /_matrix/client/r0/profile/{userId}/displayname](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname) pub mod set_display_name { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Set the display name of the user.", + method: Method::Put, + name: "set_display_name", + path: "/_matrix/client/r0/profile/:user_id/displayname", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/profile/{}/displayname", - params.user_id - ) + request { + /// The new display name for the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, + /// The user whose display name will be set. + #[ruma_api(path)] + pub user_id: UserId, } - fn router_path() -> &'static str { - "/_matrix/client/r0/profile/:user_id/displayname" - } - - fn name() -> &'static str { - "set_display_name" - } - - fn description() -> &'static str { - "Set the display name of the user." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [GET /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url) pub mod get_avatar_url { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - 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 avatar URL of a user.", + method: Method::Get, + name: "get_avatar_url", + path: "/_matrix/client/r0/profile/:user_id/avatar_url", + rate_limited: false, + requires_authentication: false, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/profile/{}/avatar_url", - params.user_id - ) + request { + /// The user whose avatar URL will be retrieved. + #[ruma_api(path)] + pub user_id: UserId } - fn router_path() -> &'static str { - "/_matrix/client/r0/profile/:user_id/avatar_url" - } - - fn name() -> &'static str { - "get_avatar_url" - } - - fn description() -> &'static str { - "Get the avatar URL of a user." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false + response { + /// The user's avatar URL, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option } } } /// [PUT /_matrix/client/r0/profile/{userId}/avatar_url](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url) pub mod set_avatar_url { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = PathParams; - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Put + ruma_api! { + metadata { + description: "Set the avatar URL of the user.", + method: Method::Put, + name: "set_avatar_url", + path: "/_matrix/client/r0/profile/:user_id/avatar_url", + rate_limited: true, + requires_authentication: true, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/profile/{}/avatar_url", - params.user_id - ) + request { + /// The new avatar URL for the user. + pub avatar_url: String, + /// The user whose avatar URL will be set. + #[ruma_api(path)] + pub user_id: UserId } - fn router_path() -> &'static str { - "/_matrix/client/r0/profile/:user_id/avatar_url" - } - - fn name() -> &'static str { - "set_avatar_url" - } - - fn description() -> &'static str { - "Set the avatar URL of the user." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [GET /_matrix/client/r0/profile/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid) pub mod get_profile { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's path parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct PathParams { - pub user_id: UserId - } - - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option - } - - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Get + ruma_api! { + metadata { + description: "Get all profile information of an user.", + method: Method::Get, + name: "get_profile", + path: "/_matrix/client/r0/profile/:user_id", + rate_limited: false, + requires_authentication: false, } - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/profile/{}", - params.user_id - ) + request { + /// The user whose profile will be retrieved. + #[ruma_api(path)] + pub user_id: UserId } - fn router_path() -> &'static str { - "/_matrix/client/r0/profile/:user_id" - } - - fn name() -> &'static str { - "get_profile" - } - - fn description() -> &'static str { - "Get all profile information of an user." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false + response { + /// The user's avatar URL, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, + /// The user's display name, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option } } }