Use ruma-api-macros for the alias endpoints.

This commit is contained in:
Jimmy Cuadra 2017-05-19 04:51:31 -07:00
parent 422043cf51
commit 11985ed337
2 changed files with 52 additions and 121 deletions

View File

@ -20,7 +20,7 @@ extern crate serde_json;
/// Endpoints for the r0.x.x versions of the client API specification. /// Endpoints for the r0.x.x versions of the client API specification.
pub mod r0 { pub mod r0 {
pub mod account; pub mod account;
// pub mod alias; pub mod alias;
// pub mod config; // pub mod config;
// pub mod contact; // pub mod contact;
// pub mod context; // pub mod context;

View File

@ -1,152 +1,83 @@
//! Endpoints for room aliases. //! 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) /// [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 { 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. ruma_api! {
#[derive(Clone, Debug, Deserialize, Serialize)] metadata {
pub struct BodyParams { 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,
}
request {
/// The room alias to set.
#[ruma_api(path)]
pub room_alias: RoomAliasId,
/// The room ID to set.
pub room_id: RoomId, pub room_id: RoomId,
} }
/// Details about this API endpoint. response {}
#[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
}
fn request_path(params: Self::PathParams) -> String {
format!("/_matrix/client/r0/directory/room/{}", params.room_alias)
}
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
}
} }
} }
/// [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) /// [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 { pub mod delete_alias {
/// Details about this API endpoint. use ruma_api_macros::ruma_api;
#[derive(Clone, Copy, Debug)] use ruma_identifiers::RoomAliasId;
pub struct Endpoint;
impl ::Endpoint for Endpoint { ruma_api! {
type BodyParams = (); metadata {
type PathParams = super::PathParams; description: "Remove an alias from a room.",
type QueryParams = (); method: Method::Delete,
type Response = (); name: "delete_alias",
path: "/_matrix/client/r0/directory/room/:room_alias",
fn method() -> ::Method { rate_limited: false,
::Method::Delete requires_authentication: true,
} }
fn request_path(params: Self::PathParams) -> String { request {
format!("/_matrix/client/r0/directory/room/{}", params.room_alias) /// The room alias to remove.
#[ruma_api(path)]
pub room_alias: RoomAliasId,
} }
fn router_path() -> &'static str { response {}
"/_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
}
} }
} }
/// [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) /// [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 { pub mod get_alias {
use ruma_identifiers::RoomId; use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomAliasId, RoomId};
/// Details about this API endpoint. ruma_api! {
#[derive(Clone, Copy, Debug)] metadata {
pub struct Endpoint; 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,
}
/// This API endpoint's response. request {
#[derive(Clone, Debug, Deserialize, Serialize)] /// The room alias.
pub struct Response { #[ruma_api(path)]
pub room_alias: RoomAliasId,
}
response {
/// The room ID for this room alias.
pub room_id: RoomId, pub room_id: RoomId,
/// A list of servers that are aware of this room ID.
pub servers: Vec<String>, pub servers: Vec<String>,
} }
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = super::PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Get
}
fn request_path(params: Self::PathParams) -> String {
format!("/_matrix/client/r0/directory/room/{}", params.room_alias)
}
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
}
} }
} }
/// These API endpoints' path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
pub room_alias: RoomAliasId,
}