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 filter;
pub mod media;
// pub mod membership;
pub mod membership;
// pub mod presence;
// pub mod profile;
// pub mod push;

View File

@ -5,7 +5,8 @@ use ruma_signatures::Signatures;
// TODO: spec requires a nesting ThirdPartySigned { signed: Signed { mxid: ..., ... } }
// 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)]
pub struct ThirdPartySigned {
/// 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)
pub mod invite_user {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{UserId, RoomId};
/// The request body parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BodyParams {
pub user_id: UserId,
}
/// 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
ruma_api! {
metadata {
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,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/invite",
params.room_id
)
request {
/// The room where the user should be invited.
#[ruma_api(path)]
pub room_id: RoomId,
/// The user to invite.
pub user_id: UserId,
}
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
}
response {}
}
}
/// [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 {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, RoomIdOrAliasId};
use super::ThirdPartySigned;
/// The request type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BodyParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub third_party_signed: Option<ThirdPartySigned>,
}
/// Details about this API endpoint.
#[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
ruma_api! {
metadata {
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,
}
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
)
}
}
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")]
pub third_party_signed: Option<ThirdPartySigned>,
}
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
response {
/// The room that the user joined.
pub room_id: RoomId,
}
}
}
/// [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 {
use ruma_api_macros::ruma_api;
use ruma_identifiers::RoomId;
use super::ThirdPartySigned;
/// The request type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BodyParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub third_party_signed: Option<ThirdPartySigned>,
}
/// Details about this API endpoint.
#[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
ruma_api! {
metadata {
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,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/join",
params.room_id
)
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")]
pub third_party_signed: Option<ThirdPartySigned>,
}
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
response {
/// The room that the user joined.
pub room_id: RoomId,
}
}
}
/// [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 {
use ruma_api_macros::ruma_api;
use ruma_identifiers::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 room_id: RoomId,
}
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
ruma_api! {
metadata {
description: "Forget a room.",
method: Method::Post,
name: "forget_room",
path: "/_matrix/client/r0/rooms/:room_id/forget",
rate_limited: true,
requires_authentication: true,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/forget",
params.room_id
)
request {
/// The room to forget.
#[ruma_api(path)]
pub room_id: RoomId,
}
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
}
response {}
}
}
/// [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 {
use ruma_api_macros::ruma_api;
use ruma_identifiers::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 room_id: RoomId,
}
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
ruma_api! {
metadata {
description: "Leave a room.",
method: Method::Post,
name: "leave_room",
path: "/_matrix/client/r0/rooms/:room_id/leave",
rate_limited: true,
requires_authentication: true,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/leave",
params.room_id
)
request {
/// The room to leave.
#[ruma_api(path)]
pub room_id: RoomId,
}
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
}
response {}
}
}
/// [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 {
use ruma_identifiers::RoomId;
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, UserId};
/// The request type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BodyParams {
pub user_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<String>,
}
/// 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
ruma_api! {
metadata {
description: "Kick a user from a room.",
method: Method::Post,
name: "kick_user",
path: "/_matrix/client/r0/rooms/:room_id/kick",
rate_limited: false,
requires_authentication: true,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/kick",
params.room_id
)
request {
/// The reason for kicking the user.
#[serde(skip_serializing_if = "Option::is_none")]
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 {
"/_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
}
response {}
}
}
/// [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 {
use ruma_identifiers::RoomId;
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, UserId};
/// The request type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BodyParams {
pub user_id: String,
}
/// 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
ruma_api! {
metadata {
description: "Unban a user from a room.",
method: Method::Post,
name: "unban_user",
path: "/_matrix/client/r0/rooms/:room_id/unban",
rate_limited: false,
requires_authentication: true,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/unban",
params.room_id
)
request {
/// The room to unban the user from.
#[ruma_api(path)]
pub room_id: RoomId,
/// The user to unban.
pub user_id: UserId,
}
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
}
response {}
}
}
/// [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 {
use ruma_identifiers::RoomId;
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, UserId};
/// The request type.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BodyParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<String>,
pub user_id: String,
}
/// 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
ruma_api! {
metadata {
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,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/ban",
params.room_id
)
request {
/// The reason for banning the user.
#[serde(skip_serializing_if = "Option::is_none")]
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 {
"/_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
}
response {}
}
}