From daf37063aa5de3cb2aee44934ed81c07a83cc2f1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 9 Aug 2020 00:32:26 +0200 Subject: [PATCH] Update ruma-appservice-api to new API conventions --- ruma-appservice-api/src/lib.rs | 2 +- .../src/v1/event/push_events.rs | 19 +++++++++++++++++-- .../src/v1/query/query_room_alias.rs | 16 +++++++++++++++- .../src/v1/query/query_user_id.rs | 16 +++++++++++++++- .../thirdparty/get_location_for_protocol.rs | 17 ++++++++++++++++- .../thirdparty/get_location_for_room_alias.rs | 16 +++++++++++++++- .../src/v1/thirdparty/get_protocol.rs | 16 +++++++++++++++- .../v1/thirdparty/get_user_for_protocol.rs | 17 ++++++++++++++++- .../src/v1/thirdparty/get_user_for_user_id.rs | 16 +++++++++++++++- 9 files changed, 125 insertions(+), 10 deletions(-) diff --git a/ruma-appservice-api/src/lib.rs b/ruma-appservice-api/src/lib.rs index 2b9f3c5c..fc0c0d01 100644 --- a/ruma-appservice-api/src/lib.rs +++ b/ruma-appservice-api/src/lib.rs @@ -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; diff --git a/ruma-appservice-api/src/v1/event/push_events.rs b/ruma-appservice-api/src/v1/event/push_events.rs index 7e974441..d6c02ebe 100644 --- a/ruma-appservice-api/src/v1/event/push_events.rs +++ b/ruma-appservice-api/src/v1/event/push_events.rs @@ -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>, + pub events: &'a [Raw], } 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]) -> Self { + Self { txn_id, events } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} diff --git a/ruma-appservice-api/src/v1/query/query_room_alias.rs b/ruma-appservice-api/src/v1/query/query_room_alias.rs index 078c02a8..2cd48f04 100644 --- a/ruma-appservice-api/src/v1/query/query_room_alias.rs +++ b/ruma-appservice-api/src/v1/query/query_room_alias.rs @@ -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 + } +} diff --git a/ruma-appservice-api/src/v1/query/query_user_id.rs b/ruma-appservice-api/src/v1/query/query_user_id.rs index 2b9f0ba4..154ba02a 100644 --- a/ruma-appservice-api/src/v1/query/query_user_id.rs +++ b/ruma-appservice-api/src/v1/query/query_user_id.rs @@ -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 + } +} diff --git a/ruma-appservice-api/src/v1/thirdparty/get_location_for_protocol.rs b/ruma-appservice-api/src/v1/thirdparty/get_location_for_protocol.rs index c4a0b420..a1624e1b 100644 --- a/ruma-appservice-api/src/v1/thirdparty/get_location_for_protocol.rs +++ b/ruma-appservice-api/src/v1/thirdparty/get_location_for_protocol.rs @@ -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, } } + +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) -> Self { + Self { locations } + } +} diff --git a/ruma-appservice-api/src/v1/thirdparty/get_location_for_room_alias.rs b/ruma-appservice-api/src/v1/thirdparty/get_location_for_room_alias.rs index 14aa3b9b..8cf6752c 100644 --- a/ruma-appservice-api/src/v1/thirdparty/get_location_for_room_alias.rs +++ b/ruma-appservice-api/src/v1/thirdparty/get_location_for_room_alias.rs @@ -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, } } + +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) -> Self { + Self { locations } + } +} diff --git a/ruma-appservice-api/src/v1/thirdparty/get_protocol.rs b/ruma-appservice-api/src/v1/thirdparty/get_protocol.rs index faf9ddbc..509c9c58 100644 --- a/ruma-appservice-api/src/v1/thirdparty/get_protocol.rs +++ b/ruma-appservice-api/src/v1/thirdparty/get_protocol.rs @@ -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 } + } +} diff --git a/ruma-appservice-api/src/v1/thirdparty/get_user_for_protocol.rs b/ruma-appservice-api/src/v1/thirdparty/get_user_for_protocol.rs index 6dfdc5eb..782200f0 100644 --- a/ruma-appservice-api/src/v1/thirdparty/get_user_for_protocol.rs +++ b/ruma-appservice-api/src/v1/thirdparty/get_user_for_protocol.rs @@ -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, } } + +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) -> Self { + Self { users } + } +} diff --git a/ruma-appservice-api/src/v1/thirdparty/get_user_for_user_id.rs b/ruma-appservice-api/src/v1/thirdparty/get_user_for_user_id.rs index d95b7093..7f145257 100644 --- a/ruma-appservice-api/src/v1/thirdparty/get_user_for_user_id.rs +++ b/ruma-appservice-api/src/v1/thirdparty/get_user_for_user_id.rs @@ -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, } } + +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) -> Self { + Self { users } + } +}