From 961d45a581414541006bf7d13823eba99d3dfb11 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 29 Aug 2020 23:13:42 +0200 Subject: [PATCH] client-api: Update device endpoints to the new API standards --- ruma-client-api/src/r0/device/delete_device.rs | 17 +++++++++++++++++ ruma-client-api/src/r0/device/delete_devices.rs | 17 +++++++++++++++++ ruma-client-api/src/r0/device/get_device.rs | 16 ++++++++++++++++ ruma-client-api/src/r0/device/get_devices.rs | 17 +++++++++++++++++ ruma-client-api/src/r0/device/update_device.rs | 17 +++++++++++++++++ 5 files changed, 84 insertions(+) diff --git a/ruma-client-api/src/r0/device/delete_device.rs b/ruma-client-api/src/r0/device/delete_device.rs index c2098991..adb64db4 100644 --- a/ruma-client-api/src/r0/device/delete_device.rs +++ b/ruma-client-api/src/r0/device/delete_device.rs @@ -15,6 +15,7 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// The device to delete. #[ruma_api(path)] @@ -25,7 +26,23 @@ ruma_api! { pub auth: Option>, } + #[derive(Default)] + #[non_exhaustive] response: {} error: UiaaResponse } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given device ID. + pub fn new(device_id: &'a DeviceId) -> Self { + Self { device_id, auth: None } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} diff --git a/ruma-client-api/src/r0/device/delete_devices.rs b/ruma-client-api/src/r0/device/delete_devices.rs index 7cdda999..fd2952a1 100644 --- a/ruma-client-api/src/r0/device/delete_devices.rs +++ b/ruma-client-api/src/r0/device/delete_devices.rs @@ -15,6 +15,7 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// List of devices to delete. pub devices: &'a [DeviceIdBox], @@ -24,7 +25,23 @@ ruma_api! { pub auth: Option>, } + #[derive(Default)] + #[non_exhaustive] response: {} error: UiaaResponse } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given device list. + pub fn new(devices: &'a [DeviceIdBox]) -> Self { + Self { devices, auth: None } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} diff --git a/ruma-client-api/src/r0/device/get_device.rs b/ruma-client-api/src/r0/device/get_device.rs index bd210607..909304ed 100644 --- a/ruma-client-api/src/r0/device/get_device.rs +++ b/ruma-client-api/src/r0/device/get_device.rs @@ -14,12 +14,14 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// The device to retrieve. #[ruma_api(path)] pub device_id: &'a DeviceId, } + #[non_exhaustive] response: { /// Information about the device. #[ruma_api(body)] @@ -28,3 +30,17 @@ ruma_api! { error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given device ID. + pub fn new(device_id: &'a DeviceId) -> Self { + Self { device_id } + } +} + +impl Response { + /// Creates a new `Response` with the given device. + pub fn new(device: Device) -> Self { + Self { device } + } +} diff --git a/ruma-client-api/src/r0/device/get_devices.rs b/ruma-client-api/src/r0/device/get_devices.rs index 01f1cc97..461ede65 100644 --- a/ruma-client-api/src/r0/device/get_devices.rs +++ b/ruma-client-api/src/r0/device/get_devices.rs @@ -13,8 +13,11 @@ ruma_api! { requires_authentication: true, } + #[derive(Default)] + #[non_exhaustive] request: {} + #[non_exhaustive] response: { /// A list of all registered devices for this user pub devices: Vec, @@ -22,3 +25,17 @@ 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 devices. + pub fn new(devices: Vec) -> Self { + Self { devices } + } +} diff --git a/ruma-client-api/src/r0/device/update_device.rs b/ruma-client-api/src/r0/device/update_device.rs index a5e7ba56..00a4832f 100644 --- a/ruma-client-api/src/r0/device/update_device.rs +++ b/ruma-client-api/src/r0/device/update_device.rs @@ -13,6 +13,7 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// The device to update. #[ruma_api(path)] @@ -24,7 +25,23 @@ ruma_api! { pub display_name: Option, } + #[derive(Default)] + #[non_exhaustive] response: {} error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given device ID. + pub fn new(device_id: &'a DeviceId) -> Self { + Self { device_id, display_name: None } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +}