Update ruma-appservice-api to new API conventions

This commit is contained in:
Jonas Platte 2020-08-09 00:32:26 +02:00
parent a0a1987bbf
commit daf37063aa
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
9 changed files with 125 additions and 10 deletions

View File

@ -1,7 +1,7 @@
//! Crate ruma_appservice_api contains serializable types for the requests and responses for each
//! endpoint in the [Matrix](https://matrix.org/) application service API specification. These
//! types can be shared by application service and server code.
#![warn(missing_copy_implementations, missing_debug_implementations, missing_docs)]
#![allow(clippy::new_without_default)]
pub mod v1;

View File

@ -19,11 +19,26 @@ ruma_api! {
///
/// Homeservers generate these IDs and they are used to ensure idempotency of results.
#[ruma_api(path)]
pub txn_id: String,
pub txn_id: &'a str,
/// A list of events.
#[ruma_api(body)]
pub events: Vec<Raw<AnyEvent>>,
pub events: &'a [Raw<AnyEvent>],
}
response: {}
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given transaction ID and list of events.
pub fn new(txn_id: &'a str, events: &'a [Raw<AnyEvent>]) -> Self {
Self { txn_id, events }
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Self
}
}

View File

@ -16,8 +16,22 @@ ruma_api! {
request: {
/// The room alias being queried.
#[ruma_api(path)]
pub room_alias: RoomAliasId,
pub room_alias: &'a RoomAliasId,
}
response: {}
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given room alias.
pub fn new(room_alias: &'a RoomAliasId) -> Self {
Self { room_alias }
}
}
impl Response {
/// Create an empty `Response`.
pub fn new() -> Self {
Self
}
}

View File

@ -16,8 +16,22 @@ ruma_api! {
request: {
/// The user ID being queried.
#[ruma_api(path)]
pub user_id: UserId,
pub user_id: &'a UserId,
}
response: {}
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given user id.
pub fn new(user_id: &'a UserId) -> Self {
Self { user_id }
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Self
}
}

View File

@ -19,7 +19,8 @@ ruma_api! {
request: {
/// The protocol used to communicate to the third party network.
#[ruma_api(path)]
pub protocol: String,
pub protocol: &'a str,
/// One or more custom fields to help identify the third party location.
// The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352.
#[ruma_api(query_map)]
@ -32,3 +33,17 @@ ruma_api! {
pub locations: Vec<Location>,
}
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given protocol.
pub fn new(protocol: &'a str) -> Self {
Self { protocol, fields: BTreeMap::new() }
}
}
impl Response {
/// Creates a new `Response` with the given locations.
pub fn new(locations: Vec<Location>) -> Self {
Self { locations }
}
}

View File

@ -18,7 +18,7 @@ ruma_api! {
request: {
/// The Matrix room alias to look up.
#[ruma_api(query)]
pub alias: RoomAliasId,
pub alias: &'a RoomAliasId,
}
response: {
@ -27,3 +27,17 @@ ruma_api! {
pub locations: Vec<Location>,
}
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given room alias id.
pub fn new(alias: &'a RoomAliasId) -> Self {
Self { alias }
}
}
impl Response {
/// Creates a new `Response` with the given locations.
pub fn new(locations: Vec<Location>) -> Self {
Self { locations }
}
}

View File

@ -17,7 +17,7 @@ ruma_api! {
request: {
/// The name of the protocol.
#[ruma_api(path)]
pub protocol: String,
pub protocol: &'a str,
}
response: {
@ -26,3 +26,17 @@ ruma_api! {
pub protocol: Protocol,
}
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given protocol name.
pub fn new(protocol: &'a str) -> Self {
Self { protocol }
}
}
impl Response {
/// Creates a new `Response` with the given protocol.
pub fn new(protocol: Protocol) -> Self {
Self { protocol }
}
}

View File

@ -19,7 +19,8 @@ ruma_api! {
request: {
/// The protocol used to communicate to the third party network.
#[ruma_api(path)]
pub protocol: String,
pub protocol: &'a str,
/// One or more custom fields that are passed to the AS to help identify the user.
// The specification is incorrect for this parameter. See matrix-org/matrix-doc#2352.
#[ruma_api(query_map)]
@ -32,3 +33,17 @@ ruma_api! {
pub users: Vec<User>,
}
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given protocol name.
pub fn new(protocol: &'a str) -> Self {
Self { protocol, fields: BTreeMap::new() }
}
}
impl Response {
/// Creates a new `Response` with the given users.
pub fn new(users: Vec<User>) -> Self {
Self { users }
}
}

View File

@ -18,7 +18,7 @@ ruma_api! {
request: {
/// The Matrix User ID to look up.
#[ruma_api(query)]
pub userid: UserId,
pub userid: &'a UserId,
}
response: {
@ -27,3 +27,17 @@ ruma_api! {
pub users: Vec<User>,
}
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given user id.
pub fn new(userid: &'a UserId) -> Self {
Self { userid }
}
}
impl Response {
/// Creates a new `Response` with the given users.
pub fn new(users: Vec<User>) -> Self {
Self { users }
}
}