diff --git a/CHANGELOG.md b/CHANGELOG.md index 67b38a61..aa76aac7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,4 +19,4 @@ Improvements: * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) * Update `r0::account::change_password` from r0.3.0 to r0.6.0 * Add optional `auth` field -* Add `r0::device::delete_devices` (introduced upstream in r0.4.0) +* Add `r0::device` endpoint diff --git a/src/r0/device.rs b/src/r0/device.rs index e15727b9..a2eae059 100644 --- a/src/r0/device.rs +++ b/src/r0/device.rs @@ -1,3 +1,24 @@ //! Endpoints for managing devices. -pub mod delete_devices; +use ruma_identifiers::DeviceId; +use js_int::UInt; +use serde::{Deserialize, Serialize}; + +pub mod bulk_delete_devices; +pub mod get_device; +pub mod get_devices; +pub mod set_device; +pub mod delete_device; + +/// Information about a registered device. +#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize)] +pub struct Device { + /// Device ID + pub device_id: DeviceId, + /// Public display name of the device. + pub display_name: Option, + /// Most recently seen IP address of the session. + pub ip: Option, + /// Unix timestamp that the session was last active. + pub last_seen: Option, +} diff --git a/src/r0/device/delete_devices.rs b/src/r0/device/bulk_delete_devices.rs similarity index 88% rename from src/r0/device/delete_devices.rs rename to src/r0/device/bulk_delete_devices.rs index 6f8795e9..d4e76962 100644 --- a/src/r0/device/delete_devices.rs +++ b/src/r0/device/bulk_delete_devices.rs @@ -5,10 +5,10 @@ use ruma_api::ruma_api; ruma_api! { metadata { - description: "Delete specified devices", + description: "Delete specified devices.", method: POST, path: "/_matrix/client/r0/delete_devices", - name: "delete_devices", + name: "bulk_delete_devices", rate_limited: false, requires_authentication: true, } diff --git a/src/r0/device/delete_device.rs b/src/r0/device/delete_device.rs new file mode 100644 index 00000000..cefb61c9 --- /dev/null +++ b/src/r0/device/delete_device.rs @@ -0,0 +1,25 @@ +//! [DELETE /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#delete-matrix-client-r0-devices-deviceid) + +use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; +use crate::r0::account::AuthenticationData; + +ruma_api! { + metadata { + description: "Delete a device for authenticated user.", + method: DELETE, + name: "delete_device", + path: "/_matrix/client/r0/devices/:device_id", + rate_limited: false, + requires_authentication: true, + } + + request { + #[ruma_api(path)] + device_id: DeviceId, + #[serde(skip_serializing_if = "Option::is_none")] + auth: Option, + } + + response {} +} \ No newline at end of file diff --git a/src/r0/device/get_device.rs b/src/r0/device/get_device.rs new file mode 100644 index 00000000..43f6dc55 --- /dev/null +++ b/src/r0/device/get_device.rs @@ -0,0 +1,25 @@ +//! [GET /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-devices-deviceid) + +use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; +use super::Device; + +ruma_api! { + metadata { + description: "Get a device for authenticated user.", + method: GET, + name: "get_device", + path: "/_matrix/client/r0/devices/:device_id", + rate_limited: false, + requires_authentication: true, + } + + request { + #[ruma_api(path)] + device_id: DeviceId, + } + + response { + device: Device, + } +} diff --git a/src/r0/device/get_devices.rs b/src/r0/device/get_devices.rs new file mode 100644 index 00000000..20746c85 --- /dev/null +++ b/src/r0/device/get_devices.rs @@ -0,0 +1,21 @@ +//! [GET /_matrix/client/r0/devices](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-devices) + +use ruma_api::ruma_api; +use super::Device; + +ruma_api! { + metadata { + description: "Get registered devices for authenticated user.", + method: GET, + name: "get_devices", + path: "/_matrix/client/r0/devices", + rate_limited: false, + requires_authentication: true, + } + + request {} + + response { + devices: Vec + } +} diff --git a/src/r0/device/set_device.rs b/src/r0/device/set_device.rs new file mode 100644 index 00000000..0d653e16 --- /dev/null +++ b/src/r0/device/set_device.rs @@ -0,0 +1,24 @@ +//! [PUT /_matrix/client/r0/devices/{deviceId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-devices-deviceid) + +use ruma_api::ruma_api; +use ruma_identifiers::DeviceId; + +ruma_api! { + metadata { + description: "Update metadata for a device.", + method: PUT, + name: "set_device", + path: "/_matrix/client/r0/devices/:device_id", + rate_limited: false, + requires_authentication: true, + } + + request { + #[ruma_api(path)] + device_id: DeviceId, + #[serde(skip_serializing_if = "Option::is_none")] + display_name: Option, + } + + response {} +} \ No newline at end of file