pub async fn get_champions(
client: &Client,
puuid: &str,
region: &str,
riot_api_key: &str,
) -> Result<Vec<HashMap<String, Value>>, Box<dyn Error + Send + Sync>>Expand description
⚙️ Function: Retrieves the top 10 champions for a player based on champion mastery.
This function sends a request to the Riot API to fetch the player’s top 10 champions based on their mastery score. The information returned includes champion mastery level and points for each champion.
§Parameters:
client: An instance of thereqwest::Clientused to send HTTP requests.puuid: The player’s unique PUUID (Player Unique Identifier), used to identify the player in Riot’s systems.region: A string representing the region (e.g.,euw1,na1,kr) where the player’s account is located.riot_api_key: The API key used to authenticate the request with the Riot API.
§Returns:
Result<Vec<HashMap<String, Value>>, Error>: A vector ofHashMapobjects, where each entry contains champion mastery details, or an error if the request fails.
§⚠️ Notes:
- The function returns the top 10 champions based on mastery points, but this count can be adjusted in the API URL.
- The information includes each champion’s ID, mastery level, and mastery points.
- The function requires a valid
puuidandregionfor the request to succeed.
§Example:
let top_champions = get_champions(&client, "abcd1234-efgh5678-ijkl91011-mnop1213", "euw1", riot_api_key).await?;The resulting top_champions vector will contain data like:
[
{
"championId": 157,
"championLevel": 7,
"championPoints": 500000
},
{
"championId": 238,
"championLevel": 6,
"championPoints": 350000
}
]