Use ruma-api-macros for the alias endpoints.
This commit is contained in:
parent
422043cf51
commit
11985ed337
@ -20,7 +20,7 @@ extern crate serde_json;
|
||||
/// Endpoints for the r0.x.x versions of the client API specification.
|
||||
pub mod r0 {
|
||||
pub mod account;
|
||||
// pub mod alias;
|
||||
pub mod alias;
|
||||
// pub mod config;
|
||||
// pub mod contact;
|
||||
// pub mod context;
|
||||
|
171
src/r0/alias.rs
171
src/r0/alias.rs
@ -1,152 +1,83 @@
|
||||
//! Endpoints for room aliases.
|
||||
|
||||
use ruma_identifiers::RoomAliasId;
|
||||
|
||||
/// [PUT /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-directory-room-roomalias)
|
||||
pub mod create_alias {
|
||||
use ruma_identifiers::RoomId;
|
||||
use ruma_api_macros::ruma_api;
|
||||
use ruma_identifiers::{RoomAliasId, RoomId};
|
||||
|
||||
/// This API endpoint's body parameters.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct BodyParams {
|
||||
pub room_id: RoomId,
|
||||
}
|
||||
|
||||
/// Details about this API endpoint.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Endpoint;
|
||||
|
||||
impl ::Endpoint for Endpoint {
|
||||
type BodyParams = BodyParams;
|
||||
type PathParams = super::PathParams;
|
||||
type QueryParams = ();
|
||||
type Response = ();
|
||||
|
||||
fn method() -> ::Method {
|
||||
::Method::Put
|
||||
ruma_api! {
|
||||
metadata {
|
||||
description: "Add an alias to a room.",
|
||||
method: Method::Put,
|
||||
name: "create_alias",
|
||||
path: "/_matrix/client/r0/directory/room/:room_alias",
|
||||
rate_limited: false,
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
fn request_path(params: Self::PathParams) -> String {
|
||||
format!("/_matrix/client/r0/directory/room/{}", params.room_alias)
|
||||
request {
|
||||
/// The room alias to set.
|
||||
#[ruma_api(path)]
|
||||
pub room_alias: RoomAliasId,
|
||||
/// The room ID to set.
|
||||
pub room_id: RoomId,
|
||||
}
|
||||
|
||||
fn router_path() -> &'static str {
|
||||
"/_matrix/client/r0/directory/room/:room_alias"
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
"create_alias"
|
||||
}
|
||||
|
||||
fn description() -> &'static str {
|
||||
"Add an alias to a room."
|
||||
}
|
||||
|
||||
fn requires_authentication() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn rate_limited() -> bool {
|
||||
false
|
||||
}
|
||||
response {}
|
||||
}
|
||||
}
|
||||
|
||||
/// [DELETE /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#delete-matrix-client-r0-directory-room-roomalias)
|
||||
pub mod delete_alias {
|
||||
/// Details about this API endpoint.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Endpoint;
|
||||
use ruma_api_macros::ruma_api;
|
||||
use ruma_identifiers::RoomAliasId;
|
||||
|
||||
impl ::Endpoint for Endpoint {
|
||||
type BodyParams = ();
|
||||
type PathParams = super::PathParams;
|
||||
type QueryParams = ();
|
||||
type Response = ();
|
||||
|
||||
fn method() -> ::Method {
|
||||
::Method::Delete
|
||||
ruma_api! {
|
||||
metadata {
|
||||
description: "Remove an alias from a room.",
|
||||
method: Method::Delete,
|
||||
name: "delete_alias",
|
||||
path: "/_matrix/client/r0/directory/room/:room_alias",
|
||||
rate_limited: false,
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
fn request_path(params: Self::PathParams) -> String {
|
||||
format!("/_matrix/client/r0/directory/room/{}", params.room_alias)
|
||||
request {
|
||||
/// The room alias to remove.
|
||||
#[ruma_api(path)]
|
||||
pub room_alias: RoomAliasId,
|
||||
}
|
||||
|
||||
fn router_path() -> &'static str {
|
||||
"/_matrix/client/r0/directory/room/:room_alias"
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
"delete_alias"
|
||||
}
|
||||
|
||||
fn description() -> &'static str {
|
||||
"Remove an alias from a room."
|
||||
}
|
||||
|
||||
fn requires_authentication() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn rate_limited() -> bool {
|
||||
false
|
||||
}
|
||||
response {}
|
||||
}
|
||||
}
|
||||
|
||||
/// [GET /_matrix/client/r0/directory/room/{roomAlias}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-directory-room-roomalias)
|
||||
pub mod get_alias {
|
||||
use ruma_identifiers::RoomId;
|
||||
use ruma_api_macros::ruma_api;
|
||||
use ruma_identifiers::{RoomAliasId, RoomId};
|
||||
|
||||
/// Details about this API endpoint.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Endpoint;
|
||||
|
||||
/// This API endpoint's response.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Response {
|
||||
pub room_id: RoomId,
|
||||
pub servers: Vec<String>,
|
||||
}
|
||||
|
||||
impl ::Endpoint for Endpoint {
|
||||
type BodyParams = ();
|
||||
type PathParams = super::PathParams;
|
||||
type QueryParams = ();
|
||||
type Response = Response;
|
||||
|
||||
fn method() -> ::Method {
|
||||
::Method::Get
|
||||
ruma_api! {
|
||||
metadata {
|
||||
description: "Resolve a room alias to a room ID.",
|
||||
method: Method::Get,
|
||||
name: "get_alias",
|
||||
path: "/_matrix/client/r0/directory/room/:room_alias",
|
||||
rate_limited: false,
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
fn request_path(params: Self::PathParams) -> String {
|
||||
format!("/_matrix/client/r0/directory/room/{}", params.room_alias)
|
||||
request {
|
||||
/// The room alias.
|
||||
#[ruma_api(path)]
|
||||
pub room_alias: RoomAliasId,
|
||||
}
|
||||
|
||||
fn router_path() -> &'static str {
|
||||
"/_matrix/client/r0/directory/room/:room_alias"
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
"get_alias"
|
||||
}
|
||||
|
||||
fn description() -> &'static str {
|
||||
"Resolve a room alias to a room ID."
|
||||
}
|
||||
|
||||
fn requires_authentication() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn rate_limited() -> bool {
|
||||
false
|
||||
response {
|
||||
/// The room ID for this room alias.
|
||||
pub room_id: RoomId,
|
||||
/// A list of servers that are aware of this room ID.
|
||||
pub servers: Vec<String>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// These API endpoints' path parameters.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct PathParams {
|
||||
pub room_alias: RoomAliasId,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user