Merge pull request #57 from iinuwa/feature/devices-endpoint
Add devices endpoints
This commit is contained in:
commit
aa9b3178d2
@ -19,3 +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` endpoints
|
||||
|
@ -6,6 +6,7 @@ pub mod appservice;
|
||||
pub mod config;
|
||||
pub mod contact;
|
||||
pub mod context;
|
||||
pub mod device;
|
||||
pub mod directory;
|
||||
pub mod filter;
|
||||
pub mod media;
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::UserId;
|
||||
use ruma_identifiers::{DeviceId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::AuthenticationData;
|
||||
@ -37,7 +37,7 @@ ruma_api! {
|
||||
/// If this does not correspond to a known client device, a new device will be created.
|
||||
/// The server will auto-generate a device_id if this is not specified.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub device_id: Option<String>,
|
||||
pub device_id: Option<DeviceId>,
|
||||
/// A display name to assign to the newly-created device.
|
||||
///
|
||||
/// Ignored if `device_id` corresponds to a known device.
|
||||
@ -71,7 +71,7 @@ ruma_api! {
|
||||
/// ID of the registered device.
|
||||
///
|
||||
/// Will be the same as the corresponding parameter in the request, if one was specified.
|
||||
pub device_id: String,
|
||||
pub device_id: DeviceId,
|
||||
}
|
||||
}
|
||||
|
||||
|
24
src/r0/device.rs
Normal file
24
src/r0/device.rs
Normal file
@ -0,0 +1,24 @@
|
||||
//! Endpoints for managing devices.
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::DeviceId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod delete_device;
|
||||
pub mod delete_devices;
|
||||
pub mod get_device;
|
||||
pub mod get_devices;
|
||||
pub mod update_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<String>,
|
||||
/// Most recently seen IP address of the session.
|
||||
pub ip: Option<String>,
|
||||
/// Unix timestamp that the session was last active.
|
||||
pub last_seen: Option<UInt>,
|
||||
}
|
25
src/r0/device/delete_device.rs
Normal file
25
src/r0/device/delete_device.rs
Normal file
@ -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 crate::r0::account::AuthenticationData;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::DeviceId;
|
||||
|
||||
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<AuthenticationData>,
|
||||
}
|
||||
|
||||
response {}
|
||||
}
|
27
src/r0/device/delete_devices.rs
Normal file
27
src/r0/device/delete_devices.rs
Normal file
@ -0,0 +1,27 @@
|
||||
//! [POST /_matrix/client/r0/delete_devices](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-delete-devices)
|
||||
|
||||
use crate::r0::account::AuthenticationData;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::DeviceId;
|
||||
|
||||
ruma_api! {
|
||||
metadata {
|
||||
description: "Delete specified devices.",
|
||||
method: POST,
|
||||
path: "/_matrix/client/r0/delete_devices",
|
||||
name: "delete_devices",
|
||||
rate_limited: false,
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
request {
|
||||
/// List of devices to delete.
|
||||
devices: Vec<DeviceId>,
|
||||
|
||||
/// Additional authentication information for the user-interactive authentication API.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
auth: Option<AuthenticationData>,
|
||||
}
|
||||
|
||||
response {}
|
||||
}
|
25
src/r0/device/get_device.rs
Normal file
25
src/r0/device/get_device.rs
Normal file
@ -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 super::Device;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::DeviceId;
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
21
src/r0/device/get_devices.rs
Normal file
21
src/r0/device/get_devices.rs
Normal file
@ -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 super::Device;
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
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<Device>,
|
||||
}
|
||||
}
|
24
src/r0/device/update_device.rs
Normal file
24
src/r0/device/update_device.rs
Normal file
@ -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: "update_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<String>,
|
||||
}
|
||||
|
||||
response {}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
//! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-login)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::UserId;
|
||||
use ruma_identifiers::{DeviceId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
ruma_api! {
|
||||
@ -30,7 +30,7 @@ ruma_api! {
|
||||
pub address: Option<String>,
|
||||
/// ID of the client device
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub device_id: Option<String>,
|
||||
pub device_id: Option<DeviceId>,
|
||||
}
|
||||
|
||||
response {
|
||||
|
Loading…
x
Reference in New Issue
Block a user