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.",
method: Method::Post,
name: "invite_user",
path: "/_matrix/client/r0/rooms/:room_id/invite",
rate_limited: true,
requires_authentication: true,
}
request {
/// The room where the user should be invited.
#[ruma_api(path)]
pub room_id: RoomId,
/// The user to invite.
pub user_id: UserId, pub user_id: UserId,
} }
/// Details about this API endpoint. response {}
#[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 {
format!(
"/_matrix/client/r0/rooms/{}/invite",
params.room_id
)
}
fn router_path() -> &'static str {
"/_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.",
method: Method::Post,
name: "join_room_by_id_or_alias",
path: "/_matrix/client/r0/join/:room_id_or_alias",
rate_limited: true,
requires_authentication: true,
}
request {
/// The room where the user should be invited.
#[ruma_api(path)]
pub room_id_or_alias: RoomIdOrAliasId,
/// 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")] #[serde(skip_serializing_if = "Option::is_none")]
pub third_party_signed: Option<ThirdPartySigned>, pub third_party_signed: Option<ThirdPartySigned>,
} }
/// Details about this API endpoint. response {
#[derive(Clone, Copy, Debug)] /// The room that the user joined.
pub struct Endpoint;
/// The response type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub room_id: RoomId, 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 {
match params.room_id_or_alias {
RoomIdOrAliasId::RoomId(room_id) => {
format!(
"/_matrix/client/r0/join/{}",
room_id
)
}
RoomIdOrAliasId::RoomAliasId(room_alias_id) => {
format!(
"/_matrix/client/r0/join/{}",
room_alias_id
)
}
}
}
fn router_path() -> &'static str {
"/_matrix/client/r0/join/:room_id_or_alias"
}
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.",
method: Method::Post,
name: "join_room_by_id",
path: "/_matrix/client/r0/rooms/:room_id/join",
rate_limited: true,
requires_authentication: true,
}
request {
/// The room where the user should be invited.
#[ruma_api(path)]
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")] #[serde(skip_serializing_if = "Option::is_none")]
pub third_party_signed: Option<ThirdPartySigned>, pub third_party_signed: Option<ThirdPartySigned>,
} }
/// Details about this API endpoint. response {
#[derive(Clone, Copy, Debug)] /// The room that the user joined.
pub struct Endpoint;
/// The response type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub room_id: RoomId, 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 {
format!(
"/_matrix/client/r0/rooms/{}/join",
params.room_id
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/join"
}
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,
name: "forget_room",
path: "/_matrix/client/r0/rooms/:room_id/forget",
rate_limited: true,
requires_authentication: true,
}
/// This API endpoint's path parameters. request {
#[derive(Clone, Debug, Deserialize, Serialize)] /// The room to forget.
pub struct PathParams { #[ruma_api(path)]
pub room_id: RoomId, pub room_id: RoomId,
} }
impl ::Endpoint for Endpoint { response {}
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/forget",
params.room_id
)
}
fn router_path() -> &'static str {
"/_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,
name: "leave_room",
path: "/_matrix/client/r0/rooms/:room_id/leave",
rate_limited: true,
requires_authentication: true,
}
/// This API endpoint's path parameters. request {
#[derive(Clone, Debug, Deserialize, Serialize)] /// The room to leave.
pub struct PathParams { #[ruma_api(path)]
pub room_id: RoomId, pub room_id: RoomId,
} }
impl ::Endpoint for Endpoint { response {}
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/leave",
params.room_id
)
}
fn router_path() -> &'static str {
"/_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,
name: "kick_user",
path: "/_matrix/client/r0/rooms/:room_id/kick",
rate_limited: false,
requires_authentication: true,
}
request {
/// The reason for kicking the user.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<String>, pub reason: Option<String>,
} /// The room to kick the user from.
#[ruma_api(path)]
/// 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, pub room_id: RoomId,
/// The user to kick.
pub user_id: UserId,
} }
impl ::Endpoint for Endpoint { response {}
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/kick",
params.room_id
)
}
fn router_path() -> &'static str {
"/_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",
rate_limited: false,
requires_authentication: true,
} }
/// Details about this API endpoint. request {
#[derive(Clone, Copy, Debug)] /// The room to unban the user from.
pub struct Endpoint; #[ruma_api(path)]
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
pub room_id: RoomId, pub room_id: RoomId,
/// The user to unban.
pub user_id: UserId,
} }
impl ::Endpoint for Endpoint { response {}
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/unban",
params.room_id
)
}
fn router_path() -> &'static str {
"/_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.",
method: Method::Post,
name: "ban_user",
path: "/_matrix/client/r0/rooms/:room_id/ban",
rate_limited: false,
requires_authentication: true,
}
request {
/// The reason for banning the user.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<String>, pub reason: Option<String>,
pub user_id: String, /// The room to kick the user from.
} #[ruma_api(path)]
/// 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, pub room_id: RoomId,
/// The user to ban.
pub user_id: UserId,
} }
impl ::Endpoint for Endpoint { response {}
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/ban",
params.room_id
)
}
fn router_path() -> &'static str {
"/_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
}
} }
} }