Rankings
In the game there are different leaderboards based on:
Brawlers and Country
Players and Country
Club and Country
Ranked and Country (unsupported by the official API)
Working with it is very easy within the library, let start with the top-100 the best players:
// all 100 players at once
bsClient
.getPlayersRankings(
countryCode = CountryCode.GERMANY
)
.getOrElse { throw it } // rethrow for simplicity of example
?.forEach(::println) // just printing them
// for our example it shouldn't be null, but client returns
// nullable because some of the countries might not be supported
?: println("Specified country does not supported in the rankings")
// or via PagesIterator:
val bestPlayersIterator: PagesIterator<Player.Ranking> = bsClient
.getPlayersRankingsLazily(
countryCode = CountryCode.GLOBAL
)
bestPlayersIterator.forEachPage { result: Result<List<Player.Ranking>> ->
// retry until success
println(result.getOrElse { return@forEachPage })
}
You may read more about PagesIterator here.
The response contains:
@Serializable
public data class Ranking(
val tag: PlayerTag,
val name: PlayerName,
val icon: PlayerIcon,
val trophies: Trophies,
val rank: RankingPosition,
val club: Club.View,
)
To learn how to get avatars of the players – visit this section.
To learn how to get badges of the clubs – visit this section
Now let's move to the clubs:
// all 100 players at once
bsClient
.getClubsRankings(
countryCode = CountryCode.UKRAINE,
)
.getOrElse { throw it } // rethrow for simplicity of example
?.forEach(::println) // just printing them
// for our example it shouldn't be null, but client returns
// nullable because some of the countries might not be supported
?: println("Specified country does not supported in the rankings")
// or via PagesIterator:
val bestClubsIterator: PagesIterator<Club.Ranking> = bsClient
.getClubsRankingsLazily(
countryCode = CountryCode.GLOBAL,
count = Count.createUnsafe(20),
)
bestClubsIterator.asFlow()
.catch { e: Exception -> /* ... */ }
.collect { List<Club.Ranking> ->
// retry until success
println(result.getOrElse { return@forEachPage })
}
You may read more about PagesIterator here.
The output is the following:
@Serializable
public data class Ranking(
val clubTag: ClubTag,
val name: ClubName,
val trophies: Trophies,
val rank: RankingPosition,
)
Unfortunately, you will need to get club one by one to show any visuals. 😕
And finally the best players per brawler:
// all 100 players at once
bsClient
.getBrawlerRankings(
countryCode = CountryCode.POLAND,
brawlerId = BrawlerId.SHELLY,
)
.getOrElse { throw it } // rethrow for simplicity of example
?.forEach(::println) // just printing them
// for our example it shouldn't be null, but client returns
// nullable because some of the countries might not be supported
?: println("Specified country does not supported in the rankings")
// or via PagesIterator:
val bestShellyPlayersIterator: PagesIterator<Brawler.Ranking> = bsClient
.getBrawlerRankingsLazily(
countryCode = CountryCode.GLOBAL,
count = Count.createUnsafe(20),
)
// you may also map values with PagesIterator!
// maps to player name
.map { it.name }
bestShellyPlayersIterator.asFlow()
.catch { e: Exception -> /* ... */ }
.collect { List<Brawler.Ranking> ->
// retry until success
println(result.getOrElse { return@forEachPage })
}
You may read more about PagesIterator here.
Here is what you get:
@Serializable
public data class Ranking(
val id: BrawlerId,
val name: PlayerName,
val tag: PlayerTag,
val icon: PlayerIcon,
val trophies: Trophies,
val club: Club.View,
val rank: RankingPosition,
)
Last modified: 02 January 2025