diff --git a/vallum/src/main/kotlin/Vallum.kt b/vallum/src/main/kotlin/Vallum.kt index 590b8084..0fa50075 100644 --- a/vallum/src/main/kotlin/Vallum.kt +++ b/vallum/src/main/kotlin/Vallum.kt @@ -23,29 +23,40 @@ constructor( private val baseUrl: String = "https://ztor.zero.zenmo.com", private val tokenUrl: String = "https://keycloak.zenmo.com/realms/zenmo/protocol/openid-connect/token", ) { + private val client = HttpClient(CIO) { + install(ContentNegotiation) { + json(Json { + ignoreUnknownKeys = true + }) + } + } + fun getHessenpoortSurveys(): List = getSurveysByProject("Hessenpoort") @JvmOverloads - fun getSurveysByProject(project: String, includeInSimulation: Boolean? = true): List { - val client = HttpClient(CIO) { - install(ContentNegotiation) { - json(Json { - ignoreUnknownKeys = true - }) + fun getSurveysByProject(project: String, includeInSimulation: Boolean? = true): List = runBlocking { + val accessToken = getAccessToken(client) + client.get(baseUrl.trimEnd('/') + "/company-surveys") { + parameter("project", project) + parameter("includeInSimulation", includeInSimulation) + headers { + append("Authorization", "Bearer $accessToken") } - } + }.body>() + } - return runBlocking { - val accessToken = getAccessToken(client) - client.get(baseUrl.trimEnd('/') + "/company-surveys") { - parameter("project", project) - parameter("includeInSimulation", includeInSimulation) - headers { - append("Authorization", "Bearer $accessToken") - } - }.body>() - } + /** + * Get all surveys the account has access to and are configured to include in the simulation + */ + fun getAllEnabledSurveys(): List = runBlocking { + val accessToken = getAccessToken(client) + client.get(baseUrl.trimEnd('/') + "/company-surveys") { + parameter("includeInSimulation", true) + headers { + append("Authorization", "Bearer $accessToken") + } + }.body>() } private suspend fun getAccessToken(client: HttpClient): String {