commonMain.com.bselzer.gw2.v2.client.instance.AchievementClient.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.achievement.Achievement
import com.bselzer.gw2.v2.model.achievement.AchievementId
import com.bselzer.gw2.v2.model.achievement.category.AchievementCategory
import com.bselzer.gw2.v2.model.achievement.category.AchievementCategoryId
import com.bselzer.gw2.v2.model.achievement.daily.Dailies
import com.bselzer.gw2.v2.model.achievement.group.AchievementGroup
import com.bselzer.gw2.v2.model.achievement.group.AchievementGroupId
import io.ktor.client.*
/**
* The achievement client.
*
* @see the wiki
*/
class AchievementClient(httpClient: HttpClient, configuration: Gw2ClientConfiguration) : BaseClient(httpClient, configuration) {
private companion object {
const val ACHIEVEMENTS = "achievements"
const val DAILY = "daily"
const val TOMORROW = "tomorrow"
const val GROUPS = "groups"
const val CATEGORIES = "categories"
}
/**
* @return the ids of all achievements
* @see the wiki
*/
suspend fun ids(): List = getIds(path = ACHIEVEMENTS)
/**
* @return the achievement associated with the [id]
* @see the wiki
*/
suspend fun achievement(id: AchievementId, language: Language? = null): Achievement = getSingleById(id, ACHIEVEMENTS, instance = { Achievement(id = it) }) {
language(language)
}
/**
* @return the achievements associated with the [ids]
* @see the wiki
*/
suspend fun achievements(ids: Collection, language: Language? = null): List =
chunkedIds(ids, ACHIEVEMENTS, instance = { Achievement(id = it) }) {
language(language)
}
/**
* @return today's dailies
* @see the wiki
*/
suspend fun dailiesForToday(): Dailies = getSingle(path = "${ACHIEVEMENTS}/${DAILY}", instance = { Dailies() })
/**
* @return tomorrow's dailies
* @see the wiki
*/
suspend fun dailiesForTomorrow(): Dailies = getSingle(path = "${ACHIEVEMENTS}/${DAILY}/${TOMORROW}", instance = { Dailies() })
/**
* @return the ids of all achievement groups
* @see the wiki
*/
suspend fun groupIds(): List = getIds(path = "${ACHIEVEMENTS}/${GROUPS}")
/**
* @return the achievement group associated with the [id]
* @see the wiki
*/
suspend fun group(id: AchievementGroupId, language: Language? = null): AchievementGroup =
getSingleById(id, "${ACHIEVEMENTS}/${GROUPS}", instance = { AchievementGroup(id = it) }) {
language(language)
}
/**
* @return the achievement groups associated with the [ids]
* @see the wiki
*/
suspend fun groups(ids: Collection, language: Language? = null): List =
chunkedIds(ids, "${ACHIEVEMENTS}/${GROUPS}", instance = { AchievementGroup(id = it) }) {
language(language)
}
/**
* @return all the achievement groups
* @see the wiki
*/
suspend fun groups(language: Language? = null): List = allIds("${ACHIEVEMENTS}/${GROUPS}") {
language(language)
}
/**
* @return the ids of all achievement categories
* @see the wiki
*/
suspend fun categoryIds(): List = getIds(path = "${ACHIEVEMENTS}/${CATEGORIES}")
/**
* @return the achievement category associated with the [id]
* @see the wiki
*/
suspend fun category(id: AchievementCategoryId, language: Language? = null): AchievementCategory =
getSingleById(id, "${ACHIEVEMENTS}/${CATEGORIES}", instance = { AchievementCategory(id = it) }) {
language(language)
}
/**
* @return the achievement categories associated with the [ids]
* @see the wiki
*/
suspend fun categories(ids: Collection, language: Language? = null): List =
chunkedIds(ids, "${ACHIEVEMENTS}/${CATEGORIES}", instance = { AchievementCategory(id = it) }) {
language(language)
}
/**
* @return all the achievement categories
* @see the wiki
*/
suspend fun categories(language: Language? = null): List =
allIds("${ACHIEVEMENTS}/${CATEGORIES}") {
language(language)
}
}