Use ruma-api-macros for the send endpoints.

This commit is contained in:
Jonas Platte 2017-06-29 03:35:41 +10:00
parent fb90929aa1
commit 5f880dfbb1
2 changed files with 68 additions and 155 deletions

View File

@ -35,7 +35,7 @@ pub mod r0 {
// pub mod redact;
// pub mod room;
// pub mod search;
// pub mod send;
pub mod send;
// pub mod server;
// pub mod session;
// pub mod sync;

View File

@ -2,193 +2,106 @@
/// [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype)
pub mod send_state_event_for_empty_key {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, EventId};
use ruma_events::EventType;
/// 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 event_type: EventType
}
/// This API endpoint's response.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub event_id: EventId,
}
impl ::Endpoint for Endpoint {
type BodyParams = ::serde_json::Value;
type PathParams = PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Put
ruma_api! {
metadata {
description: "Send a state event to a room associated with the empty state key.",
method: Method::Put,
name: "send_state_event_for_empty_key",
path: "/_matrix/client/r0/rooms/:room_id/state/:event_type",
rate_limited: false,
requires_authentication: true,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/state/{}",
params.room_id,
params.event_type
)
request {
/// The room to set the state in.
#[ruma_api(path)]
pub room_id: RoomId,
/// The type of event to send.
#[ruma_api(path)]
pub event_type: EventType,
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/state/:event_type"
}
fn name() -> &'static str {
"send_state_event_for_empty_key"
}
fn description() -> &'static str {
"Send a state event to a room associated with the empty state key."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
response {
/// A unique identifier for the event.
pub event_id: EventId,
}
}
}
/// [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey)
pub mod send_state_event_for_key {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, EventId};
use ruma_events::EventType;
/// 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 event_type: EventType,
pub state_key: String
}
/// This API endpoint's response.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub event_id: EventId,
}
impl ::Endpoint for Endpoint {
type BodyParams = ::serde_json::Value;
type PathParams = PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Put
ruma_api! {
metadata {
description: "Send a state event to a room associated with a given state key.",
method: Method::Put,
name: "send_state_event_for_key",
path: "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key",
rate_limited: false,
requires_authentication: true,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/state/{}/{}",
params.room_id,
params.event_type,
params.state_key
)
request {
/// The room to set the state in.
#[ruma_api(path)]
pub room_id: RoomId,
/// The type of event to send.
#[ruma_api(path)]
pub event_type: EventType,
/// The state_key for the state to send. Defaults to the empty string.
#[ruma_api(path)]
pub state_key: String,
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key"
}
fn name() -> &'static str {
"send_state_event_for_key"
}
fn description() -> &'static str {
"Send a state event to a room associated with a given state key."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
response {
/// A unique identifier for the event.
pub event_id: EventId,
}
}
}
/// [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid)
pub mod send_message_event {
use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, EventId};
use ruma_events::EventType;
/// 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 event_type: EventType,
pub txn_id: String
}
/// This API endpoint's response.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub event_id: EventId,
}
impl ::Endpoint for Endpoint {
type BodyParams = ::serde_json::Value;
type PathParams = PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Put
ruma_api! {
metadata {
description: "Send a message event to a room.",
method: Method::Put,
name: "send_message_event",
path: "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id",
rate_limited: false,
requires_authentication: true,
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/send/{}/{}",
params.room_id,
params.event_type,
params.txn_id
)
request {
/// The room to send the event to.
#[ruma_api(path)]
pub room_id: RoomId,
/// The type of event to send.
#[ruma_api(path)]
pub event_type: EventType,
/// The transaction ID for this event.
///
/// Clients should generate an ID unique across requests with the
/// same access token; it will be used by the server to ensure
/// idempotency of requests.
#[ruma_api(path)]
pub txn_id: String,
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id"
}
fn name() -> &'static str {
"send_message_event"
}
fn description() -> &'static str {
"Send a message event to a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
response {
/// A unique identifier for the event.
pub event_id: EventId,
}
}
}