Use ruma-api-macros for the membership endpoints.

This commit is contained in:
Jimmy Cuadra 2017-07-03 16:41:25 -07:00
parent 7f78253539
commit 06ddfdd681
2 changed files with 146 additions and 403 deletions

View File

@ -29,7 +29,7 @@ pub mod r0 {
pub mod directory; pub mod directory;
pub mod filter; pub mod filter;
pub mod media; pub mod media;
// pub mod membership; pub mod membership;
// pub mod presence; // pub mod presence;
// pub mod profile; // pub mod profile;
// pub mod push; // pub mod push;

View File

@ -5,7 +5,8 @@ use ruma_signatures::Signatures;
// TODO: spec requires a nesting ThirdPartySigned { signed: Signed { mxid: ..., ... } } // TODO: spec requires a nesting ThirdPartySigned { signed: Signed { mxid: ..., ... } }
// for join_room_by_id_or_alias but not for join_room_by_id, inconsistency? // for join_room_by_id_or_alias but not for join_room_by_id, inconsistency?
/// A signature of an `m.third_party_invite` token to prove that this user owns a third party identity which has been invited to the room. /// A signature of an `m.third_party_invite` token to prove that this user owns a third party
/// identity which has been invited to the room.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ThirdPartySigned { pub struct ThirdPartySigned {
/// The Matrix ID of the invitee. /// The Matrix ID of the invitee.
@ -20,490 +21,232 @@ pub struct ThirdPartySigned {
/// [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite) /// [POST /_matrix/client/r0/rooms/{roomId}/invite](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite)
pub mod invite_user { pub mod invite_user {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{UserId, RoomId}; use ruma_identifiers::{UserId, RoomId};
/// The request body parameters. ruma_api! {
#[derive(Clone, Debug, Deserialize, Serialize)] metadata {
pub struct BodyParams { description: "Invite a user to a room.",
pub user_id: UserId, method: Method::Post,
} name: "invite_user",
path: "/_matrix/client/r0/rooms/:room_id/invite",
/// Details about this API endpoint. rate_limited: true,
#[derive(Clone, Copy, Debug)] requires_authentication: true,
pub struct Endpoint;
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
pub room_id: RoomId,
}
impl ::Endpoint for Endpoint {
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
} }
fn request_path(params: Self::PathParams) -> String { request {
format!( /// The room where the user should be invited.
"/_matrix/client/r0/rooms/{}/invite", #[ruma_api(path)]
params.room_id pub room_id: RoomId,
) /// The user to invite.
pub user_id: UserId,
} }
fn router_path() -> &'static str { response {}
"/_matrix/client/r0/rooms/:room_id/invite"
}
fn name() -> &'static str {
"invite_user"
}
fn description() -> &'static str {
"Invite a user to a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
true
}
} }
} }
/// [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias) /// [POST /_matrix/client/r0/join/{roomIdOrAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias)
pub mod join_room_by_id_or_alias { pub mod join_room_by_id_or_alias {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, RoomIdOrAliasId}; use ruma_identifiers::{RoomId, RoomIdOrAliasId};
use super::ThirdPartySigned; use super::ThirdPartySigned;
/// The request type. ruma_api! {
#[derive(Clone, Debug, Deserialize, Serialize)] metadata {
pub struct BodyParams { description: "Join a room using its ID or one of its aliases.",
#[serde(skip_serializing_if = "Option::is_none")] method: Method::Post,
pub third_party_signed: Option<ThirdPartySigned>, name: "join_room_by_id_or_alias",
} path: "/_matrix/client/r0/join/:room_id_or_alias",
rate_limited: true,
/// Details about this API endpoint. requires_authentication: true,
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
/// The response type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub room_id: RoomId,
}
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
pub room_id_or_alias: RoomIdOrAliasId,
}
impl ::Endpoint for Endpoint {
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Post
} }
fn request_path(params: Self::PathParams) -> String { request {
match params.room_id_or_alias { /// The room where the user should be invited.
RoomIdOrAliasId::RoomId(room_id) => { #[ruma_api(path)]
format!( pub room_id_or_alias: RoomIdOrAliasId,
"/_matrix/client/r0/join/{}", /// The signature of a `m.third_party_invite` token to prove that this user owns a third
room_id /// party identity which has been invited to the room.
) #[serde(skip_serializing_if = "Option::is_none")]
} pub third_party_signed: Option<ThirdPartySigned>,
RoomIdOrAliasId::RoomAliasId(room_alias_id) => {
format!(
"/_matrix/client/r0/join/{}",
room_alias_id
)
}
}
} }
fn router_path() -> &'static str { response {
"/_matrix/client/r0/join/:room_id_or_alias" /// The room that the user joined.
} pub room_id: RoomId,
fn name() -> &'static str {
"join_room_by_id_or_alias"
}
fn description() -> &'static str {
"Join a room using its ID or one of its aliases."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
true
} }
} }
} }
/// [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join) /// [POST /_matrix/client/r0/rooms/{roomId}/join](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join)
pub mod join_room_by_id { pub mod join_room_by_id {
use ruma_api_macros::ruma_api;
use ruma_identifiers::RoomId; use ruma_identifiers::RoomId;
use super::ThirdPartySigned; use super::ThirdPartySigned;
/// The request type. ruma_api! {
#[derive(Clone, Debug, Deserialize, Serialize)] metadata {
pub struct BodyParams { description: "Join a room using its ID.",
#[serde(skip_serializing_if = "Option::is_none")] method: Method::Post,
pub third_party_signed: Option<ThirdPartySigned>, name: "join_room_by_id",
} path: "/_matrix/client/r0/rooms/:room_id/join",
rate_limited: true,
/// Details about this API endpoint. requires_authentication: true,
#[derive(Clone, Copy, Debug)]
pub struct Endpoint;
/// The response type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub room_id: RoomId,
}
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
pub room_id: RoomId,
}
impl ::Endpoint for Endpoint {
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Post
} }
fn request_path(params: Self::PathParams) -> String { request {
format!( /// The room where the user should be invited.
"/_matrix/client/r0/rooms/{}/join", #[ruma_api(path)]
params.room_id pub room_id: RoomId,
) /// The signature of a `m.third_party_invite` token to prove that this user owns a third
/// party identity which has been invited to the room.
#[serde(skip_serializing_if = "Option::is_none")]
pub third_party_signed: Option<ThirdPartySigned>,
} }
fn router_path() -> &'static str { response {
"/_matrix/client/r0/rooms/:room_id/join" /// The room that the user joined.
} pub room_id: RoomId,
fn name() -> &'static str {
"join_room_by_id"
}
fn description() -> &'static str {
"Join a room using its ID."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
true
} }
} }
} }
/// [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget) /// [POST /_matrix/client/r0/rooms/{roomId}/forget](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget)
pub mod forget_room { pub mod forget_room {
use ruma_api_macros::ruma_api;
use ruma_identifiers::RoomId; use ruma_identifiers::RoomId;
/// Details about this API endpoint. ruma_api! {
#[derive(Clone, Copy, Debug)] metadata {
pub struct Endpoint; description: "Forget a room.",
method: Method::Post,
/// This API endpoint's path parameters. name: "forget_room",
#[derive(Clone, Debug, Deserialize, Serialize)] path: "/_matrix/client/r0/rooms/:room_id/forget",
pub struct PathParams { rate_limited: true,
pub room_id: RoomId, requires_authentication: true,
}
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
} }
fn request_path(params: Self::PathParams) -> String { request {
format!( /// The room to forget.
"/_matrix/client/r0/rooms/{}/forget", #[ruma_api(path)]
params.room_id pub room_id: RoomId,
)
} }
fn router_path() -> &'static str { response {}
"/_matrix/client/r0/rooms/:room_id/forget"
}
fn name() -> &'static str {
"forget_room"
}
fn description() -> &'static str {
"Forget a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
true
}
} }
} }
/// [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave) /// [POST /_matrix/client/r0/rooms/{roomId}/leave](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave)
pub mod leave_room { pub mod leave_room {
use ruma_api_macros::ruma_api;
use ruma_identifiers::RoomId; use ruma_identifiers::RoomId;
/// Details about this API endpoint. ruma_api! {
#[derive(Clone, Copy, Debug)] metadata {
pub struct Endpoint; description: "Leave a room.",
method: Method::Post,
/// This API endpoint's path parameters. name: "leave_room",
#[derive(Clone, Debug, Deserialize, Serialize)] path: "/_matrix/client/r0/rooms/:room_id/leave",
pub struct PathParams { rate_limited: true,
pub room_id: RoomId, requires_authentication: true,
}
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
} }
fn request_path(params: Self::PathParams) -> String { request {
format!( /// The room to leave.
"/_matrix/client/r0/rooms/{}/leave", #[ruma_api(path)]
params.room_id pub room_id: RoomId,
)
} }
fn router_path() -> &'static str { response {}
"/_matrix/client/r0/rooms/:room_id/leave"
}
fn name() -> &'static str {
"leave_room"
}
fn description() -> &'static str {
"Leave a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
true
}
} }
} }
/// [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick) /// [POST /_matrix/client/r0/rooms/{roomId}/kick](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick)
pub mod kick_user { pub mod kick_user {
use ruma_identifiers::RoomId; use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, UserId};
/// The request type. ruma_api! {
#[derive(Clone, Debug, Deserialize, Serialize)] metadata {
pub struct BodyParams { description: "Kick a user from a room.",
pub user_id: String, method: Method::Post,
#[serde(skip_serializing_if = "Option::is_none")] name: "kick_user",
pub reason: Option<String>, path: "/_matrix/client/r0/rooms/:room_id/kick",
} rate_limited: false,
requires_authentication: true,
/// 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 room_id: RoomId,
}
impl ::Endpoint for Endpoint {
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
} }
fn request_path(params: Self::PathParams) -> String { request {
format!( /// The reason for kicking the user.
"/_matrix/client/r0/rooms/{}/kick", #[serde(skip_serializing_if = "Option::is_none")]
params.room_id pub reason: Option<String>,
) /// The room to kick the user from.
#[ruma_api(path)]
pub room_id: RoomId,
/// The user to kick.
pub user_id: UserId,
} }
fn router_path() -> &'static str { response {}
"/_matrix/client/r0/rooms/:room_id/kick"
}
fn name() -> &'static str {
"kick_user"
}
fn description() -> &'static str {
"Kick a user from a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
} }
} }
/// [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban) /// [POST /_matrix/client/r0/rooms/{roomId}/unban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban)
pub mod unban_user { pub mod unban_user {
use ruma_identifiers::RoomId; use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, UserId};
/// The request type. ruma_api! {
#[derive(Clone, Debug, Deserialize, Serialize)] metadata {
pub struct BodyParams { description: "Unban a user from a room.",
pub user_id: String, method: Method::Post,
} name: "unban_user",
path: "/_matrix/client/r0/rooms/:room_id/unban",
/// Details about this API endpoint. rate_limited: false,
#[derive(Clone, Copy, Debug)] requires_authentication: true,
pub struct Endpoint;
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
pub room_id: RoomId,
}
impl ::Endpoint for Endpoint {
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
} }
fn request_path(params: Self::PathParams) -> String { request {
format!( /// The room to unban the user from.
"/_matrix/client/r0/rooms/{}/unban", #[ruma_api(path)]
params.room_id pub room_id: RoomId,
) /// The user to unban.
pub user_id: UserId,
} }
fn router_path() -> &'static str { response {}
"/_matrix/client/r0/rooms/:room_id/unban"
}
fn name() -> &'static str {
"unban_user"
}
fn description() -> &'static str {
"unban a user from a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
} }
} }
/// [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban) /// [POST /_matrix/client/r0/rooms/{roomId}/ban](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban)
pub mod ban_user { pub mod ban_user {
use ruma_identifiers::RoomId; use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, UserId};
/// The request type. ruma_api! {
#[derive(Clone, Debug, Deserialize, Serialize)] metadata {
pub struct BodyParams { description: "Ban a user from a room.",
#[serde(skip_serializing_if = "Option::is_none")] method: Method::Post,
pub reason: Option<String>, name: "ban_user",
pub user_id: String, path: "/_matrix/client/r0/rooms/:room_id/ban",
} rate_limited: false,
requires_authentication: true,
/// 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 room_id: RoomId,
}
impl ::Endpoint for Endpoint {
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
} }
fn request_path(params: Self::PathParams) -> String { request {
format!( /// The reason for banning the user.
"/_matrix/client/r0/rooms/{}/ban", #[serde(skip_serializing_if = "Option::is_none")]
params.room_id pub reason: Option<String>,
) /// The room to kick the user from.
#[ruma_api(path)]
pub room_id: RoomId,
/// The user to ban.
pub user_id: UserId,
} }
fn router_path() -> &'static str { response {}
"/_matrix/client/r0/rooms/:room_id/ban"
}
fn name() -> &'static str {
"ban_user"
}
fn description() -> &'static str {
"Ban a user from a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
} }
} }