Skip to content

Users Devices

Endpoints

UserDevices

Source code in matrix_admin_sdk/endpoints/v2/user_devices.py
class UserDevices(Endpoint):
    def __int__(self, user_id: str, **kwargs):
        """
        Initialize UserDevices endpoint
        Args:
            user_id: fully-qualified user id: for example, @user:server.com
            **kwargs: keyword arguments to pass to Endpoint

        Returns: None

        """
        self.user_id = user_id
        super().__init__(**kwargs)

    async def get_all(self) -> UserDevicesModel:
        """
        Gets information about all devices for a specific user_id.

        Returns: UserDevicesModel

        """
        url = self.url(f"users/{self.user_id}/devices")
        result = await self.request(RequestMethods.GET, url)
        res: UserDevicesModel = UserDevicesModel.from_dict(result)
        return res

    async def delete_multiple(self, devices: List[str]) -> None:
        """
        Deletes the given devices for a specific user_id, and invalidates any
        access token associated with them.
        Args:
            devices: The list of device IDs to delete.

        Returns: None

        """
        url = self.url(f"users/{self.user_id}/delete_devices")
        data = {"devices": devices}
        await self.request(RequestMethods.POST, url, json=data)

    async def show(self, device_id: str) -> UserDeviceModel:
        """
        Gets information on a single device, by device_id for a specific user_id.
        Args:
            device_id: The device to retrieve.

        Returns:

        """
        url = self.url(f"users/{self.user_id}/devices/{device_id}")
        result = await self.request(RequestMethods.GET, url)
        res: UserDeviceModel = UserDeviceModel.from_dict(result)
        return res

    async def update(self, device_id: str, display_name: str) -> None:
        """
        Updates the metadata on the given device_id for a specific user_id.
        Args:
            device_id: The device to update.
            display_name: The new display name for this device. If not given,
                the display name is unchanged.

        Returns: None

        """
        url = self.url(f"users/{self.user_id}/devices/{device_id}")
        data = {"display_name": display_name}
        await self.request(RequestMethods.PUT, url, json=data)

    async def delete(self, device_id: str) -> None:
        """
        Deletes the given device_id for a specific user_id, and invalidates any
            access token associated with it.
        Args:
            device_id: The device to delete.

        Returns: None

        """
        url = self.url(f"users/{self.user_id}/devices/{device_id}")
        await self.request(RequestMethods.DELETE, url)

__int__(self, user_id, **kwargs) special

Initialize UserDevices endpoint

Parameters:

Name Type Description Default
user_id str

fully-qualified user id: for example, @user:server.com

required
**kwargs

keyword arguments to pass to Endpoint

{}
Source code in matrix_admin_sdk/endpoints/v2/user_devices.py
def __int__(self, user_id: str, **kwargs):
    """
    Initialize UserDevices endpoint
    Args:
        user_id: fully-qualified user id: for example, @user:server.com
        **kwargs: keyword arguments to pass to Endpoint

    Returns: None

    """
    self.user_id = user_id
    super().__init__(**kwargs)

delete(self, device_id) async

Deletes the given device_id for a specific user_id, and invalidates any access token associated with it.

Parameters:

Name Type Description Default
device_id str

The device to delete.

required
Source code in matrix_admin_sdk/endpoints/v2/user_devices.py
async def delete(self, device_id: str) -> None:
    """
    Deletes the given device_id for a specific user_id, and invalidates any
        access token associated with it.
    Args:
        device_id: The device to delete.

    Returns: None

    """
    url = self.url(f"users/{self.user_id}/devices/{device_id}")
    await self.request(RequestMethods.DELETE, url)

delete_multiple(self, devices) async

Deletes the given devices for a specific user_id, and invalidates any access token associated with them.

Parameters:

Name Type Description Default
devices List[str]

The list of device IDs to delete.

required
Source code in matrix_admin_sdk/endpoints/v2/user_devices.py
async def delete_multiple(self, devices: List[str]) -> None:
    """
    Deletes the given devices for a specific user_id, and invalidates any
    access token associated with them.
    Args:
        devices: The list of device IDs to delete.

    Returns: None

    """
    url = self.url(f"users/{self.user_id}/delete_devices")
    data = {"devices": devices}
    await self.request(RequestMethods.POST, url, json=data)

get_all(self) async

Gets information about all devices for a specific user_id.

Returns: UserDevicesModel

Source code in matrix_admin_sdk/endpoints/v2/user_devices.py
async def get_all(self) -> UserDevicesModel:
    """
    Gets information about all devices for a specific user_id.

    Returns: UserDevicesModel

    """
    url = self.url(f"users/{self.user_id}/devices")
    result = await self.request(RequestMethods.GET, url)
    res: UserDevicesModel = UserDevicesModel.from_dict(result)
    return res

show(self, device_id) async

Gets information on a single device, by device_id for a specific user_id.

Parameters:

Name Type Description Default
device_id str

The device to retrieve.

required
Source code in matrix_admin_sdk/endpoints/v2/user_devices.py
async def show(self, device_id: str) -> UserDeviceModel:
    """
    Gets information on a single device, by device_id for a specific user_id.
    Args:
        device_id: The device to retrieve.

    Returns:

    """
    url = self.url(f"users/{self.user_id}/devices/{device_id}")
    result = await self.request(RequestMethods.GET, url)
    res: UserDeviceModel = UserDeviceModel.from_dict(result)
    return res

update(self, device_id, display_name) async

Updates the metadata on the given device_id for a specific user_id.

Parameters:

Name Type Description Default
device_id str

The device to update.

required
display_name str

The new display name for this device. If not given, the display name is unchanged.

required
Source code in matrix_admin_sdk/endpoints/v2/user_devices.py
async def update(self, device_id: str, display_name: str) -> None:
    """
    Updates the metadata on the given device_id for a specific user_id.
    Args:
        device_id: The device to update.
        display_name: The new display name for this device. If not given,
            the display name is unchanged.

    Returns: None

    """
    url = self.url(f"users/{self.user_id}/devices/{device_id}")
    data = {"display_name": display_name}
    await self.request(RequestMethods.PUT, url, json=data)

Models

UserDevicesModel

UserDevicesModel

Attributes:

Name Type Description
devices list

An array of objects, each containing information about a device

total int

Total number of devices

Source code in matrix_admin_sdk/models/v2/user_devices.py
class UserDevicesModel(BaseModel):
    """
    UserDevicesModel
    Attributes:
        devices (list): An array of objects, each containing information about a device
        total (int): Total number of devices
    """

    devices: List[UserDeviceModel]
    total: int

    @classmethod
    def from_dict(cls, data: Dict[str, Any]):
        user_devices = [UserDeviceModel.from_dict(i) for i in data.get("devices", [])]
        return cls(devices=user_devices, total=data.get("total", 0))

UserDeviceModel

UserDeviceModel class

Attributes:

Name Type Description
device_id str

Identifier of device

display_name str

Display name set by the user for this device. Absent if no name has been set.

last_seen_ip str

The IP address where this device was last seen. (May be a few minutes out of date, for efficiency reasons).

last_seen_ts int

The timestamp (in milliseconds since the unix epoch) when this devices was last seen. (May be a few minutes out of date, for efficiency reasons).

user_id str

Owner of device.

Source code in matrix_admin_sdk/models/v2/user_devices.py
class UserDeviceModel(BaseModel):
    """
    UserDeviceModel class
    Attributes:
        device_id (str): Identifier of device
        display_name (str):  Display name set by the user for this device.
            Absent if no name has been set.
        last_seen_ip (str): The IP address where this device was last seen.
            (May be a few minutes out of date, for efficiency reasons).
        last_seen_ts (int): The timestamp (in milliseconds since the unix epoch)
            when this devices was last seen. (May be a few minutes out of date,
            for efficiency reasons).
        user_id (str): Owner of device.
    """

    device_id: str
    display_name: str
    last_seen_ip: str
    last_seen_ts: int
    user_id: str