diff --git a/Cargo.toml b/Cargo.toml index b973058a..8077931a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,4 +29,4 @@ rev = "3635fe51ac31b9ff899c70a0d1218caa8cf6a8dc" [dependencies.ruma-api-macros] git = "https://github.com/ruma/ruma-api-macros" -rev = "10f4647037c81cc3c35097f6156dd9706d38964a" +rev = "fc46b9a58b11d468d8b1ef51414d57d5e39f3332" diff --git a/src/lib.rs b/src/lib.rs index 3bbac1ce..7b63fad1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,9 +17,9 @@ extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; -// /// Endpoints for the r0.x.x versions of the client API specification. -// pub mod r0 { -// pub mod account; +/// Endpoints for the r0.x.x versions of the client API specification. +pub mod r0 { + pub mod account; // pub mod alias; // pub mod config; // pub mod contact; @@ -42,6 +42,6 @@ extern crate serde_json; // pub mod tag; // pub mod typing; // pub mod voip; -// } +} pub mod unversioned; diff --git a/src/r0/account.rs b/src/r0/account.rs index d532d62c..7daac47b 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -2,45 +2,76 @@ /// [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register) pub mod register { + use ruma_api_macros::ruma_api; use ruma_identifiers::UserId; - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - /// If true, the server binds the email used for authentication - /// to the Matrix ID with the ID Server. - #[serde(skip_serializing_if = "Option::is_none")] - pub bind_email: Option, - /// The desired password for the account. - /// - /// Should only be empty for guest accounts. - // TODO: the spec says nothing about when it is actually required. - #[serde(skip_serializing_if = "Option::is_none")] - pub password: Option, - /// local part of the desired Matrix ID. - /// - /// If omitted, the homeserver MUST generate a Matrix ID local part. - #[serde(skip_serializing_if = "Option::is_none")] - pub username: Option, - /// ID of the client device. - /// - /// If this does not correspond to a known client device, a new device will be created. - /// The server will auto-generate a device_id if this is not specified. - #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option, - /// A display name to assign to the newly-created device. - /// - /// Ignored if `device_id` corresponds to a known device. - #[serde(skip_serializing_if = "Option::is_none")] - pub initial_device_display_name: Option, - /// Additional authentication information for the user-interactive authentication API. - /// - /// Note that this information is not used to define how the registered user should be - /// authenticated, but is instead used to authenticate the register call itself. - /// It should be left empty, or omitted, unless an earlier call returned an response - /// with status code 401. - #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option + ruma_api! { + metadata { + description: "Register an account on this homeserver.", + method: Method::Post, + name: "register", + path: "/_matrix/client/r0/register", + rate_limited: true, + requires_authentication: false, + } + + request { + /// If true, the server binds the email used for authentication + /// to the Matrix ID with the ID Server. + #[serde(skip_serializing_if = "Option::is_none")] + pub bind_email: Option, + /// The desired password for the account. + /// + /// Should only be empty for guest accounts. + // TODO: the spec says nothing about when it is actually required. + #[serde(skip_serializing_if = "Option::is_none")] + pub password: Option, + /// local part of the desired Matrix ID. + /// + /// If omitted, the homeserver MUST generate a Matrix ID local part. + #[serde(skip_serializing_if = "Option::is_none")] + pub username: Option, + /// ID of the client device. + /// + /// If this does not correspond to a known client device, a new device will be created. + /// The server will auto-generate a device_id if this is not specified. + #[serde(skip_serializing_if = "Option::is_none")] + pub device_id: Option, + /// A display name to assign to the newly-created device. + /// + /// Ignored if `device_id` corresponds to a known device. + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_device_display_name: Option, + /// Additional authentication information for the user-interactive authentication API. + /// + /// Note that this information is not used to define how the registered user should be + /// authenticated, but is instead used to authenticate the register call itself. + /// It should be left empty, or omitted, unless an earlier call returned an response + /// with status code 401. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option, + /// Kind of account to register + /// + /// Defaults to `User` if ommited. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub kind: Option, + } + + response { + /// An access token for the account. + /// + /// This access token can then be used to authorize other requests. + pub access_token: String, + /// The hostname of the homeserver on which the account has been registered. + pub home_server: String, + /// The fully-qualified Matrix ID that has been registered. + pub user_id: UserId, + /// ID of the registered device. + /// + /// Will be the same as the corresponding parameter in the request, if one was specified. + pub device_id: String, + } } /// Additional authentication information for the user-interactive authentication API. @@ -53,20 +84,6 @@ pub mod register { session: Option } - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - /// This API endpoint's query string parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct QueryParams { - /// Kind of account to register - /// - /// Defaults to `User` if ommited. - #[serde(skip_serializing_if = "Option::is_none")] - pub kind: Option, - } - /// The kind of account being registered. #[derive(Copy, Clone, Debug, Deserialize, Serialize)] pub enum RegistrationKind { @@ -79,256 +96,110 @@ pub mod register { #[serde(rename="user")] User, } - - /// This API endpoint's response. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct Response { - /// An access token for the account. - /// - /// This access token can then be used to authorize other requests. - pub access_token: String, - /// The hostname of the homeserver on which the account has been registered. - pub home_server: String, - /// The fully-qualified Matrix ID that has been registered. - pub user_id: UserId, - /// ID of the registered device. - /// - /// Will be the same as the corresponding parameter in the request, if one was specified. - pub device_id: String - } - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = 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/register" - } - - fn name() -> &'static str { - "register" - } - - fn description() -> &'static str { - "Register an account on this homeserver." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - true - } - } } /// [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken) pub mod request_password_change_token { - // TODO: according to the spec, this does not has any params - // probably the spec's fault, as this would not make any sense. - // But the BodyParams here are probably wrong - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub client_secret: String, - pub email: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - pub send_attempt: u64, - } + use ruma_api_macros::ruma_api; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Request that a password change token is sent to the given email address.", + method: Method::Post, + name: "request_password_change_token", + path: "/_matrix/client/r0/account/password/email/requestToken", + rate_limited: false, + requires_authentication: false, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() + request { + /// TODO: This parameter is not documented in the spec. + pub client_secret: String, + /// TODO: This parameter is not documented in the spec. + pub email: String, + /// TODO: This parameter is not documented in the spec. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option, + /// TODO: This parameter is not documented in the spec. + pub send_attempt: u64, } - fn router_path() -> &'static str { - "/_matrix/client/r0/account/password/email/requestToken" - } - - fn name() -> &'static str { - "request_password_change_token" - } - - fn description() -> &'static str { - "Request that a password change token is sent to the given email address." - } - - fn requires_authentication() -> bool { - false - } - - fn rate_limited() -> bool { - false - } + response {} } } /// [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate) pub mod deactivate { - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + // TODO: missing request parameters - // TODO: missing BodyParams + use ruma_api_macros::ruma_api; - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = (); - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Deactivate the current user's account.", + method: Method::Post, + name: "deactivate", + path: "/_matrix/client/r0/account/deactivate", + rate_limited: true, + requires_authentication: true, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() - } + request {} - fn router_path() -> &'static str { - "/_matrix/client/r0/account/deactivate" - } - - fn name() -> &'static str { - "deactivate" - } - - fn description() -> &'static str { - "Deactivate the current user's account." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password) pub mod change_password { - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub new_password: String, - // TODO: missing `auth` field - } + use ruma_api_macros::ruma_api; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Change the password of the current user's account.", + method: Method::Post, + name: "change_password", + path: "/_matrix/client/r0/account/password", + rate_limited: true, + requires_authentication: true, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() + request { + /// The new password for the account. + pub new_password: String, + // TODO: missing `auth` field } - fn router_path() -> &'static str { - "/_matrix/client/r0/account/password" - } - - fn name() -> &'static str { - "change_password" - } - - fn description() -> &'static str { - "Change the password of the current user's account." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } } /// [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken) pub mod request_register_token { - /// This API endpoint's body parameters. - #[derive(Clone, Debug, Deserialize, Serialize)] - pub struct BodyParams { - pub client_secret: String, - pub email: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - pub send_attempt: u64, - } + use ruma_api_macros::ruma_api; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; - - impl ::Endpoint for Endpoint { - type BodyParams = BodyParams; - type PathParams = (); - type QueryParams = (); - type Response = (); - - fn method() -> ::Method { - ::Method::Post + ruma_api! { + metadata { + description: "Request a register token with a 3rd party email.", + method: Method::Post, + name: "request_register_token", + path: "/_matrix/client/r0/register/email/requestToken", + rate_limited: true, + requires_authentication: true, } - fn request_path(_params: Self::PathParams) -> String { - Self::router_path().to_string() + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// The ID server to send the onward request to as a hostname with an appended colon and port number if the port is not the default. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: u64, } - fn router_path() -> &'static str { - "/_matrix/client/r0/register/email/requestToken" - } - - fn name() -> &'static str { - "request_register_token" - } - - fn description() -> &'static str { - "Request a register token with a 3rd party email." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } + response {} } }