ruma_client_api/device/update_device.rs
1//! `PUT /_matrix/client/*/devices/{deviceId}`
2//!
3//! Update metadata for a device, or create a new device.
4//!
5//! Only application services can use this endpoint to create new devices.
6
7pub mod v3 {
8 //! `/v3/` ([spec])
9 //!
10 //! [spec]: https://spec.matrix.org/latest/client-server-api/#put_matrixclientv3devicesdeviceid
11
12 use ruma_common::{
13 OwnedDeviceId,
14 api::{auth_scheme::AccessToken, request, response},
15 metadata,
16 };
17
18 metadata! {
19 method: PUT,
20 rate_limited: false,
21 authentication: AccessToken,
22 history: {
23 1.0 => "/_matrix/client/r0/devices/{device_id}",
24 1.1 => "/_matrix/client/v3/devices/{device_id}",
25 }
26 }
27
28 /// Request type for the `update_device` endpoint.
29 #[request(error = crate::Error)]
30 pub struct Request {
31 /// The device to update or create.
32 #[ruma_api(path)]
33 pub device_id: OwnedDeviceId,
34
35 /// The new display name for this device.
36 ///
37 /// If this is `None`, the display name won't be changed.
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub display_name: Option<String>,
40 }
41
42 /// Response type for the `update_device` endpoint.
43 #[response(error = crate::Error)]
44 #[derive(Default)]
45 pub struct Response {}
46
47 impl Request {
48 /// Creates a new `Request` with the given device ID.
49 pub fn new(device_id: OwnedDeviceId) -> Self {
50 Self { device_id, display_name: None }
51 }
52 }
53
54 impl Response {
55 /// Creates an empty `Response`.
56 pub fn new() -> Self {
57 Self {}
58 }
59 }
60}