commonMain.com.bselzer.gw2.v2.client.instance.BackstoryClient.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of v2-client Show documentation
Show all versions of v2-client Show documentation
Ktor client for v2 endpoints of the Guild Wars 2 API.
The newest version!
package com.bselzer.gw2.v2.client.instance
import com.bselzer.gw2.v2.client.extension.language
import com.bselzer.gw2.v2.client.model.Language
import com.bselzer.gw2.v2.model.backstory.answer.BackstoryAnswer
import com.bselzer.gw2.v2.model.backstory.answer.BackstoryAnswerId
import com.bselzer.gw2.v2.model.backstory.question.BackstoryQuestion
import com.bselzer.gw2.v2.model.backstory.question.BackstoryQuestionId
import io.ktor.client.*
/**
* The backstory client.
* @see the wiki
*/
class BackstoryClient(httpClient: HttpClient, configuration: Gw2ClientConfiguration) : BaseClient(httpClient, configuration) {
internal companion object {
const val BACKSTORY = "backstory"
const val ANSWERS = "answers"
const val QUESTIONS = "questions"
}
/**
* @return the ids of the available answers
* @see the wiki
*/
suspend fun answerIds(): List = getIds(path = "${BACKSTORY}/${ANSWERS}")
/**
* @return the answer associated with the [id]
* @see the wiki
*/
suspend fun answer(id: BackstoryAnswerId, language: Language? = null): BackstoryAnswer =
getSingleById(id, "${BACKSTORY}/${ANSWERS}", instance = { BackstoryAnswer(id = it) }) {
language(language)
}
/**
* @return the answers associated with the [ids]
* @see the wiki
*/
suspend fun answers(ids: Collection, language: Language? = null): List =
chunkedIds(ids, "${BACKSTORY}/${ANSWERS}", instance = { BackstoryAnswer(id = it) }) {
language(language)
}
/**
* @return all the answers
* @see the wiki
*/
suspend fun answers(language: Language? = null): List = allIds("${BACKSTORY}/${ANSWERS}") {
language(language)
}
/**
* @return the ids of the available questions
* @see the wiki
*/
suspend fun questionIds(): List = getIds(path = "${BACKSTORY}/${QUESTIONS}")
/**
* @return the question associated with the [id]
* @see the wiki
*/
suspend fun question(id: BackstoryQuestionId, language: Language? = null): BackstoryQuestion =
getSingleById(id, "${BACKSTORY}/${QUESTIONS}", instance = { BackstoryQuestion(id = it) }) {
language(language)
}
/**
* @return the questions associated with the [ids]
* @see the wiki
*/
suspend fun questions(ids: Collection, language: Language? = null): List =
chunkedIds(ids, "${BACKSTORY}/${QUESTIONS}", instance = { BackstoryQuestion(id = it) }) {
language(language)
}
/**
* @return all the questions
* @see the wiki
*/
suspend fun questions(language: Language? = null): List = allIds("${BACKSTORY}/${QUESTIONS}") {
language(language)
}
}