commonMain.com.bselzer.gw2.v2.client.instance.PvpClient.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.bearer
import com.bselzer.gw2.v2.client.extension.language
import com.bselzer.gw2.v2.client.model.Language
import com.bselzer.gw2.v2.client.model.Token
import com.bselzer.gw2.v2.model.pvp.amulet.PvpAmulet
import com.bselzer.gw2.v2.model.pvp.amulet.PvpAmuletId
import com.bselzer.gw2.v2.model.pvp.game.PvpGame
import com.bselzer.gw2.v2.model.pvp.game.PvpGameId
import com.bselzer.gw2.v2.model.pvp.hero.PvpHero
import com.bselzer.gw2.v2.model.pvp.hero.PvpHeroId
import com.bselzer.gw2.v2.model.pvp.leaderboard.PvpLeaderboard
import com.bselzer.gw2.v2.model.pvp.rank.PvpRank
import com.bselzer.gw2.v2.model.pvp.rank.PvpRankId
import com.bselzer.gw2.v2.model.pvp.season.PvpSeason
import com.bselzer.gw2.v2.model.pvp.season.PvpSeasonId
import com.bselzer.gw2.v2.model.pvp.standing.PvpStandings
import com.bselzer.gw2.v2.model.pvp.stat.PvpStats
import com.bselzer.gw2.v2.scope.core.Permission
import com.bselzer.gw2.v2.scope.core.Requirement
import com.bselzer.gw2.v2.scope.core.Scope
import io.ktor.client.*
/**
* The player vs. player client.
* @see the wiki
*/
@Scope(Requirement.OPTIONAL, Permission.ACCOUNT, Permission.PVP)
class PvpClient(httpClient: HttpClient, configuration: Gw2ClientConfiguration) : BaseClient(httpClient, configuration) {
private companion object {
const val PVP = "pvp"
const val STATS = "stats"
const val GAMES = "games"
const val STANDINGS = "standings"
const val RANKS = "ranks"
const val SEASONS = "seasons"
const val LEADERBOARDS = "leaderboards"
const val LADDER = "ladder"
const val HEROES = "heroes"
const val AMULETS = "amulets"
}
/**
* @return an account's PvP stats
* @see the wiki
*/
@Scope(Requirement.REQUIRED, Permission.ACCOUNT, Permission.PVP)
suspend fun stats(token: Token? = null): PvpStats = getSingle(path = "${PVP}/${STATS}", instance = { PvpStats() }) {
bearer(token)
}
/**
* @return the ids of the most recently played games. Limited to at most 10 games.
* @see the wiki
*/
@Scope(Requirement.REQUIRED, Permission.ACCOUNT, Permission.PVP)
suspend fun gameIds(token: Token? = null): List = getList(path = "${PVP}/${GAMES}") {
bearer(token)
}
/**
* @return the game associated with the [id]
* @see the wiki
*/
@Scope(Requirement.REQUIRED, Permission.ACCOUNT, Permission.PVP)
suspend fun game(id: PvpGameId, token: Token? = null): PvpGame = getSingleById(id, "${PVP}/${GAMES}", instance = { PvpGame(id = it) }) {
bearer(token)
}
/**
* @return the games associated with the [ids]
* @see the wiki
*/
@Scope(Requirement.REQUIRED, Permission.ACCOUNT, Permission.PVP)
suspend fun games(ids: Collection, token: Token? = null): List = chunkedIds(ids, "${PVP}/${GAMES}", instance = { PvpGame(id = it) }) {
bearer(token)
}
/**
* @return the most recently played games. Limited to at most 10 games.
* @see the wiki
*/
@Scope(Requirement.REQUIRED, Permission.ACCOUNT, Permission.PVP)
suspend fun games(token: Token? = null): List = allIds("${PVP}/${GAMES}") {
bearer(token)
}
/**
* @return the pip and division standings
* @see the wiki
*/
@Scope(Requirement.REQUIRED, Permission.ACCOUNT, Permission.PVP)
suspend fun standings(token: Token? = null): PvpStandings = getSingle(path = "${PVP}/${STANDINGS}", instance = { PvpStandings() }) {
bearer(token)
}
/**
* @return the ids of the available ranks
* @see the wiki
*/
suspend fun rank(id: PvpRankId, language: Language? = null): PvpRank = getSingleById(id, "${PVP}/${RANKS}", instance = { PvpRank(id = it) }) {
language(language)
}
/**
* @return the ranks associated with the [ids]
* @see the wiki
*/
suspend fun ranks(language: Language? = null): List = allIds("${PVP}/${RANKS}") {
language(language)
}
/**
* @return the ids of all the PvP League seasons
* @see