All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.net.folivo.trixnity.clientserverapi.client.DeviceApiClient.kt Maven / Gradle / Ivy

There is a newer version: 4.11.2
Show newest version
package net.folivo.trixnity.clientserverapi.client

import net.folivo.trixnity.clientserverapi.model.devices.*
import net.folivo.trixnity.core.model.UserId

interface DeviceApiClient {
    /**
     * @see [GetDevices]
     */
    suspend fun getDevices(asUserId: UserId? = null): Result>

    /**
     * @see [GetDevice]
     */
    suspend fun getDevice(deviceId: String, asUserId: UserId? = null): Result

    /**
     * @see [UpdateDevice]
     */
    suspend fun updateDevice(
        deviceId: String,
        displayName: String,
        asUserId: UserId? = null
    ): Result

    /**
     * @see [DeleteDevices]
     */
    suspend fun deleteDevices(devices: List, asUserId: UserId? = null): Result>

    /**
     * @see [DeleteDevice]
     */
    suspend fun deleteDevice(deviceId: String, asUserId: UserId? = null): Result>
}

class DeviceApiClientImpl(
    private val httpClient: MatrixClientServerApiHttpClient
) : DeviceApiClient {

    override suspend fun getDevices(asUserId: UserId?): Result> =
        httpClient.request(GetDevices(asUserId)).map { it.devices }

    override suspend fun getDevice(deviceId: String, asUserId: UserId?): Result =
        httpClient.request(GetDevice(deviceId, asUserId))

    override suspend fun updateDevice(
        deviceId: String,
        displayName: String,
        asUserId: UserId?
    ): Result =
        httpClient.request(UpdateDevice(deviceId, asUserId), UpdateDevice.Request(displayName))

    override suspend fun deleteDevices(devices: List, asUserId: UserId?): Result> =
        httpClient.uiaRequest(DeleteDevices(asUserId), DeleteDevices.Request(devices))

    override suspend fun deleteDevice(deviceId: String, asUserId: UserId?): Result> =
        httpClient.uiaRequest(DeleteDevice(deviceId, asUserId))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy