client-api: Update config and contact endpoints to the new API standards

This commit is contained in:
Jonas Platte 2020-08-29 22:56:27 +02:00
parent cf9b83495c
commit d1f409bcb6
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
6 changed files with 162 additions and 20 deletions

View File

@ -15,16 +15,18 @@ ruma_api! {
requires_authentication: true,
}
#[non_exhaustive]
request: {
/// User ID of user for whom to retrieve data.
#[ruma_api(path)]
pub user_id: UserId,
pub user_id: &'a UserId,
/// Type of data to retrieve.
#[ruma_api(path)]
pub event_type: String,
pub event_type: &'a str,
}
#[non_exhaustive]
response: {
/// Account data content for the given type.
#[ruma_api(body)]
@ -33,3 +35,17 @@ ruma_api! {
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given user ID and event type.
pub fn new(user_id: &'a UserId, event_type: &'a str) -> Self {
Self { user_id, event_type }
}
}
impl Response {
/// Creates a new `Response` with the given account data.
pub fn new(account_data: Raw<AnyBasicEvent>) -> Self {
Self { account_data }
}
}

View File

@ -15,20 +15,22 @@ ruma_api! {
requires_authentication: true,
}
#[non_exhaustive]
request: {
/// User ID of user for whom to retrieve data.
#[ruma_api(path)]
pub user_id: UserId,
pub user_id: &'a UserId,
/// Room ID for which to retrieve data.
#[ruma_api(path)]
pub room_id: RoomId,
pub room_id: &'a RoomId,
/// Type of data to retrieve.
#[ruma_api(path)]
pub event_type: String,
pub event_type: &'a str,
}
#[non_exhaustive]
response: {
/// Account data content for the given type.
#[ruma_api(body)]
@ -37,3 +39,17 @@ ruma_api! {
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given user ID, room ID and event type.
pub fn new(user_id: &'a UserId, room_id: &'a RoomId, event_type: &'a str) -> Self {
Self { user_id, room_id, event_type }
}
}
impl Response {
/// Creates a new `Response` with the given account data.
pub fn new(account_data: Raw<AnyBasicEvent>) -> Self {
Self { account_data }
}
}

View File

@ -14,6 +14,7 @@ ruma_api! {
requires_authentication: true,
}
#[non_exhaustive]
request: {
/// Arbitrary JSON to store as config data.
///
@ -25,16 +26,32 @@ ruma_api! {
///
/// Custom types should be namespaced to avoid clashes.
#[ruma_api(path)]
pub event_type: String,
pub event_type: &'a str,
/// 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,
pub user_id: &'a UserId,
}
#[derive(Default)]
#[non_exhaustive]
response: {}
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given data, event type and user ID.
pub fn new(data: Box<RawJsonValue>, event_type: &'a str, user_id: &'a UserId) -> Self {
Self { data, event_type, user_id }
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Self
}
}

View File

@ -14,10 +14,11 @@ ruma_api! {
requires_authentication: true,
}
#[non_exhaustive]
request: {
/// Arbitrary JSON to store as config data.
///
/// To create a `Box<RawJsonValue>`, use `serde_json::value::to_raw_value`.
/// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`.
#[ruma_api(body)]
pub data: Box<RawJsonValue>,
@ -25,20 +26,41 @@ ruma_api! {
///
/// Custom types should be namespaced to avoid clashes.
#[ruma_api(path)]
pub event_type: String,
pub event_type: &'a str,
/// The ID of the room to set account_data on.
#[ruma_api(path)]
pub room_id: RoomId,
pub room_id: &'a 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,
pub user_id: &'a UserId,
}
#[derive(Default)]
#[non_exhaustive]
response: {}
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given data, event type, room ID and user ID.
pub fn new(
data: Box<RawJsonValue>,
event_type: &'a str,
room_id: &'a RoomId,
user_id: &'a UserId,
) -> Self {
Self { data, event_type, room_id, user_id }
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Self
}
}

View File

@ -16,8 +16,11 @@ ruma_api! {
requires_authentication: true,
}
#[derive(Default)]
#[non_exhaustive]
request: {}
#[non_exhaustive]
response: {
/// A list of third party identifiers the homeserver has associated with the user's
/// account.
@ -28,8 +31,26 @@ ruma_api! {
error: crate::Error
}
impl Request {
/// Creates an empty `Request`.
pub fn new() -> Self {
Self
}
}
impl Response {
/// Creates a new `Response` with the given third party identifiers.
pub fn new(threepids: Vec<ThirdPartyIdentifier>) -> Self {
Self { threepids }
}
}
/// An identifier external to Matrix.
///
/// To create an instance of this type, first create a `ThirdPartyIdentifierInit` and convert it to
/// this type using `ThirdPartyIdentifier::Init` / `.into()`.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
#[cfg_attr(test, derive(PartialEq))]
pub struct ThirdPartyIdentifier {
/// The third party identifier address.
@ -47,6 +68,32 @@ pub struct ThirdPartyIdentifier {
pub added_at: SystemTime,
}
/// Initial set of fields of `ThirdPartyIdentifier`.
///
/// This struct will not be updated even if additional fields are added to `ThirdPartyIdentifier`
/// in a new (non-breaking) release of the Matrix specification.
#[derive(Debug)]
pub struct ThirdPartyIdentifierInit {
/// The third party identifier address.
pub address: String,
/// The medium of third party identifier.
pub medium: Medium,
/// The time when the identifier was validated by the identity server.
pub validated_at: SystemTime,
/// The time when the homeserver associated the third party identifier with the user.
pub added_at: SystemTime,
}
impl From<ThirdPartyIdentifierInit> for ThirdPartyIdentifier {
fn from(init: ThirdPartyIdentifierInit) -> Self {
let ThirdPartyIdentifierInit { address, medium, validated_at, added_at } = init;
ThirdPartyIdentifier { address, medium, validated_at, added_at }
}
}
#[cfg(test)]
mod tests {
use std::time::{Duration, UNIX_EPOCH};

View File

@ -13,35 +13,59 @@ ruma_api! {
requires_authentication: false,
}
#[non_exhaustive]
request: {
/// Client-generated secret string used to protect this session.
pub client_secret: String,
pub client_secret: &'a str,
/// The email address.
pub email: String,
/// A URL for the identity server to redirect the user to after
/// validation is completed.
#[serde(skip_serializing_if = "Option::is_none")]
pub next_link: Option<String>,
pub email: &'a str,
/// Used to distinguish protocol level retries from requests to re-send
/// the email.
pub send_attempt: UInt,
/// A URL for the identity server to redirect the user to after
/// validation is completed.
#[serde(skip_serializing_if = "Option::is_none")]
pub next_link: Option<&'a str>,
/// The identity server to send the onward request to as a hostname with
/// an appended colon and port number if the port is not the default.
#[serde(skip_serializing_if = "Option::is_none")]
pub id_server: Option<String>,
pub id_server: Option<&'a str>,
/// An access token previously registered with the identity server.
///
/// Required if an `id_server` is supplied.
#[serde(skip_serializing_if = "Option::is_none")]
pub id_access_token: Option<String>,
pub id_access_token: Option<&'a str>,
}
#[derive(Default)]
#[non_exhaustive]
response: {}
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given client secret, email and send-attempt counter.
pub fn new(client_secret: &'a str, email: &'a str, send_attempt: UInt) -> Self {
Self {
client_secret,
email,
send_attempt,
next_link: None,
id_server: None,
id_access_token: None,
}
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Self
}
}