Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vallum: add method to fetch all surveys #206

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions vallum/src/main/kotlin/Vallum.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Survey> =
getSurveysByProject("Hessenpoort")

@JvmOverloads
fun getSurveysByProject(project: String, includeInSimulation: Boolean? = true): List<Survey> {
val client = HttpClient(CIO) {
install(ContentNegotiation) {
json(Json {
ignoreUnknownKeys = true
})
fun getSurveysByProject(project: String, includeInSimulation: Boolean? = true): List<Survey> = runBlocking {
val accessToken = getAccessToken(client)
client.get(baseUrl.trimEnd('/') + "/company-surveys") {
parameter("project", project)
parameter("includeInSimulation", includeInSimulation)
headers {
append("Authorization", "Bearer $accessToken")
}
}
}.body<List<Survey>>()
}

return runBlocking {
val accessToken = getAccessToken(client)
client.get(baseUrl.trimEnd('/') + "/company-surveys") {
parameter("project", project)
parameter("includeInSimulation", includeInSimulation)
headers {
append("Authorization", "Bearer $accessToken")
}
}.body<List<Survey>>()
}
/**
* Get all surveys the account has access to and are configured to include in the simulation
*/
fun getAllEnabledSurveys(): List<Survey> = runBlocking {
val accessToken = getAccessToken(client)
client.get(baseUrl.trimEnd('/') + "/company-surveys") {
parameter("includeInSimulation", true)
headers {
append("Authorization", "Bearer $accessToken")
}
}.body<List<Survey>>()
}

private suspend fun getAccessToken(client: HttpClient): String {
Expand Down
Loading