Use ruma-api-macros for the receipt endpoints.

This commit is contained in:
Jimmy Cuadra 2017-07-06 00:57:29 -07:00
parent beacb5f268
commit 651fe9b3e3
2 changed files with 29 additions and 61 deletions

View File

@ -31,8 +31,8 @@ pub mod r0 {
pub mod membership; pub mod membership;
pub mod presence; pub mod presence;
pub mod profile; pub mod profile;
// pub mod push; pub mod push;
// pub mod receipt; pub mod receipt;
// pub mod redact; // pub mod redact;
pub mod room; pub mod room;
// pub mod search; // pub mod search;

View File

@ -2,76 +2,44 @@
/// [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) /// [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid)
pub mod create_receipt { pub mod create_receipt {
use ruma_identifiers::{EventId, RoomId};
use std::fmt::{Display, Error as FmtError, Formatter}; use std::fmt::{Display, Error as FmtError, Formatter};
/// Details about this API endpoint. use ruma_api_macros::ruma_api;
#[derive(Clone, Copy, Debug)] use ruma_identifiers::{EventId, RoomId};
pub struct Endpoint;
/// This endpoint's path parameters. ruma_api! {
#[derive(Clone, Debug)] metadata {
pub struct PathParams { description: "Send a receipt event to a room.",
method: Method::Post,
name: "create_receipt",
path: "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id",
rate_limited: true,
requires_authentication: true,
}
request {
/// The event ID to acknowledge up to. /// The event ID to acknowledge up to.
#[ruma_api(path)]
pub event_id: EventId, pub event_id: EventId,
/// The type of receipt to send. /// The type of receipt to send.
#[ruma_api(path)]
pub receipt_type: ReceiptType, pub receipt_type: ReceiptType,
/// The room in which to send the event. /// The room in which to send the event.
#[ruma_api(path)]
pub room_id: RoomId, pub room_id: RoomId,
} }
response {}
}
/// The type of receipt. /// The type of receipt.
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum ReceiptType { pub enum ReceiptType {
/// m.read /// m.read
#[serde(rename = "m.read")]
Read, Read,
} }
/// This API endpoint's response.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct Response;
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = Response;
fn method() -> ::Method {
::Method::Post
}
fn request_path(params: Self::PathParams) -> String {
format!(
"/_matrix/client/r0/rooms/{}/receipt/{}/{}",
params.room_id,
params.receipt_type,
params.event_id
)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id"
}
fn name() -> &'static str {
"create_receipt"
}
fn description() -> &'static str {
"Send a receipt event to a room."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
true
}
}
impl Display for ReceiptType { impl Display for ReceiptType {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
match *self { match *self {