Use ruma-api-macros for the config endpoints.

This commit is contained in:
Jimmy Cuadra 2017-05-19 06:02:28 -07:00
parent 11985ed337
commit 088aed514e
3 changed files with 57 additions and 92 deletions

View File

@ -29,4 +29,4 @@ rev = "3635fe51ac31b9ff899c70a0d1218caa8cf6a8dc"
[dependencies.ruma-api-macros] [dependencies.ruma-api-macros]
git = "https://github.com/ruma/ruma-api-macros" git = "https://github.com/ruma/ruma-api-macros"
rev = "fc46b9a58b11d468d8b1ef51414d57d5e39f3332" rev = "58fab938b00d01aeb5e3e8c31731b4e479d5553d"

View File

@ -21,7 +21,7 @@ extern crate serde_json;
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;
// pub mod directory; // pub mod directory;

View File

@ -2,112 +2,77 @@
/// [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type) /// [PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-rooms-roomid-account-data-type)
pub mod set_room_account_data { pub mod set_room_account_data {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, UserId}; use ruma_identifiers::{RoomId, UserId};
use serde_json::Value;
/// Details about this API endpoint. ruma_api! {
#[derive(Clone, Copy, Debug)] metadata {
pub struct Endpoint; description: "Associate account data with a room.",
method: Method::Put,
name: "set_room_account_data",
path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type",
rate_limited: false,
requires_authentication: true,
}
/// This API endpoint's path parameters. request {
#[derive(Clone, Debug, Deserialize, Serialize)] /// Arbitrary JSON to store as config data.
pub struct PathParams { #[ruma_api(body)]
pub user_id: UserId, pub data: Value,
pub room_id: RoomId, /// The event type of the account_data to set.
///
/// Custom types should be namespaced to avoid clashes.
#[ruma_api(path)]
#[serde(rename = "type")]
pub event_type: String, pub event_type: String,
/// The ID of the room to set account_data on.
#[ruma_api(path)]
pub room_id: RoomId,
/// The ID of the user to set account_data for.
///
/// The access token must be authorized to make requests for this user ID.
#[ruma_api(path)]
pub user_id: UserId,
} }
impl ::Endpoint for Endpoint { response {}
type BodyParams = ::serde_json::Value;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Put
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/user/{}/rooms/{}/account_data/{}",
params.user_id,
params.room_id,
params.event_type
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:type"
}
fn name() -> &'static str {
"set_room_account_data"
}
fn description() -> &'static str {
"Associate account data with a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
} }
} }
/// [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type) /// [PUT /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-user-userid-account-data-type)
pub mod set_global_account_data { pub mod set_global_account_data {
use ruma_api_macros::ruma_api;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use serde_json::Value;
/// Details about this API endpoint. ruma_api! {
#[derive(Clone, Copy, Debug)] metadata {
pub struct Endpoint; description: "Sets global account data.",
method: Method::Put,
name: "set_global_account_data",
path: "/_matrix/client/r0/user/:user_id/account_data/:event_type",
rate_limited: false,
requires_authentication: true,
}
/// This API endpoint's path parameters. request {
#[derive(Clone, Debug, Deserialize, Serialize)] /// Arbitrary JSON to store as config data.
pub struct PathParams { #[ruma_api(body)]
pub user_id: UserId, pub data: Value,
/// The event type of the account_data to set.
///
/// Custom types should be namespaced to avoid clashes.
#[ruma_api(path)]
#[serde(rename = "type")]
pub event_type: String, pub event_type: String,
/// The ID of the user to set account_data for.
///
/// The access token must be authorized to make requests for this user ID.
#[ruma_api(path)]
pub user_id: UserId,
} }
impl ::Endpoint for Endpoint { response {}
type BodyParams = ::serde_json::Value;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Put
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/user/{}/account_data/{}",
params.user_id,
params.event_type
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/user/:user_id/account_data/:type"
}
fn name() -> &'static str {
"set_global_account_data"
}
fn description() -> &'static str {
"Sets global account data."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
} }
} }