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

com.deque.networking.interfaces.AccessTokenClient.kt Maven / Gradle / Ivy

The newest version!
package com.deque.networking.interfaces

import com.deque.axe.android.AxeResult
import com.deque.networking.models.DequeRetrofitBuilder
import com.deque.networking.models.auth.AccessToken
import com.deque.networking.models.devtools.AxeDevToolsAccessTokenInterface
import com.deque.networking.models.devtools.TagsSet
import com.deque.networking.models.devtools.serializable.AxeDevToolsResult
import com.deque.networking.models.devtools.serializable.AxeDevToolsResultKey
import com.deque.networking.models.devtools.serializable.AxeDevToolsResultSummaryResponse
import com.deque.networking.models.devtools.serializable.HealthCheck
import com.deque.networking.models.devtools.serializable.UserInfo

class AccessTokenClient(authSource: AccessToken?, backendUrl: String) :
    AxeDevToolsClient(authSource) {
    constructor(authSource: AccessToken) : this(authSource, DB_DEFAULT_URL)

    private val accessTokenInterface: AxeDevToolsAccessTokenInterface =
        DequeRetrofitBuilder(backendUrl).gzip().client(AxeDevToolsAccessTokenInterface::class.java)

    override suspend fun getResult(
        axeDevToolsResultKey: AxeDevToolsResultKey
    ): Result {
        val callResult = accessTokenInterface.getAxeDevToolsResultAxe(
            authSource?.getAuthHeader(),
            axeDevToolsResultKey.userId,
            axeDevToolsResultKey.packageName,
            axeDevToolsResultKey.resultId
        )

        val axeDevToolsResult = callResult.getOrNull()

        return if (axeDevToolsResult != null) {
            Result.success(
                AxeDevToolsResult(
                    axeDevToolsResult,
                    axeDevToolsResultKey
                )
            )
        } else {
            Result.failure(callResult.exceptionOrNull()!!)
        }
    }

    override suspend fun postResult(axeResult: AxeResult): Result {
        val callResult = accessTokenInterface.uploadResult(authSource?.getAuthHeader(), axeResult)
        val axeDevToolsResultKey = callResult.getOrNull()

        return if (axeDevToolsResultKey != null) {
            Result.success(
                axeDevToolsResultKey
            )
        } else {
            Result.failure(callResult.exceptionOrNull()!!)
        }
    }

    override suspend fun deleteResult(axeDevToolsResultKey: AxeDevToolsResultKey): Result {
        return accessTokenInterface.deleteResult(
            authSource?.getAuthHeader(),
            axeDevToolsResultKey.userId,
            axeDevToolsResultKey.packageName,
            axeDevToolsResultKey.resultId
        )
    }

    override suspend fun tag(
        axeDevToolsResultKey: AxeDevToolsResultKey,
        tags: TagsSet
    ): Result {
        return accessTokenInterface.postAxeDevToolsResultTag(
            authSource?.getAuthHeader(), axeDevToolsResultKey.userId,
            axeDevToolsResultKey.packageName,
            axeDevToolsResultKey.resultId,
            tags
        )
    }

    override suspend fun setScanName(
        axeDevToolsResultKey: AxeDevToolsResultKey,
        scanName: String
    ): Result {
        return accessTokenInterface.setScanName(
            authSource?.getAuthHeader(),
            axeDevToolsResultKey.userId,
            axeDevToolsResultKey.packageName,
            axeDevToolsResultKey.resultId,
            scanName
        )
    }

    override suspend fun getUserInfo(): Result {
        return accessTokenInterface.getUserInfo(authSource?.getAuthHeader())
    }

    override suspend fun getHealthCheck(): Result {
        return accessTokenInterface.getHealthCheck()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy