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

commonMain.net.folivo.trixnity.clientserverapi.client.ServerApiClient.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.server.GetCapabilities
import net.folivo.trixnity.clientserverapi.model.server.GetVersions
import net.folivo.trixnity.clientserverapi.model.server.Search
import net.folivo.trixnity.clientserverapi.model.server.WhoIs
import net.folivo.trixnity.core.model.UserId

interface ServerApiClient {
    /**
     * @see [GetVersions]
     */
    suspend fun getVersions(): Result

    /**
     * @see [GetCapabilities]
     */
    suspend fun getCapabilities(): Result

    /**
     * @see [Search]
     */
    suspend fun search(
        request: Search.Request,
        nextBatch: String? = null,
        asUserId: UserId? = null
    ): Result

    /**
     * @see [WhoIs]
     */
    suspend fun whoIs(
        userId: UserId,
        asUserId: UserId? = null
    ): Result
}

class ServerApiClientImpl(private val httpClient: MatrixClientServerApiHttpClient) : ServerApiClient {

    override suspend fun getVersions(): Result =
        httpClient.request(GetVersions)

    override suspend fun getCapabilities(): Result =
        httpClient.request(GetCapabilities)

    override suspend fun search(
        request: Search.Request,
        nextBatch: String?,
        asUserId: UserId?
    ): Result =
        httpClient.request(Search(nextBatch, asUserId), request)

    override suspend fun whoIs(
        userId: UserId,
        asUserId: UserId?
    ): Result =
        httpClient.request(WhoIs(userId, asUserId))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy