Function fetch_core_build

Source
pub async fn fetch_core_build(
    champion_id: &str,
) -> Result<CoreBuildData, Box<dyn Error + Send + Sync>>
Expand description

⚙️ Function: Fetches core build data for a specific champion from League of Graphs.

This asynchronous function retrieves the core build item information for a given champion by making an HTTP request to League of Graphs. It then parses the HTML response to locate the core build section and extracts the items used in the build.

§Parameters:

  • champion_id: A string slice representing the champion’s identifier, used to build the URL for fetching the core build information.

§Returns:

  • Result<CoreBuildData, Error>: Returns a CoreBuildData struct containing the champion’s core build items if successful, or an error if something goes wrong during the HTTP request or parsing.

§Example:

This function is typically called to retrieve the core build data for a specific champion:

let core_build = fetch_core_build("Jinx").await?;
println!("{:?}", core_build);

§Notes:

  • The function makes an HTTP request to the League of Graphs page using the champion’s ID to construct the URL.
  • It parses the HTML to find the core build section by searching for an h3 element containing the text “Core Build”.
  • Once the core build header is found, the function searches for its parent element and the iconsRow div where the build items are listed.
  • The function calls extract_core_build to process the icons and return the items in the CoreBuildData structure.
  • If the core build header or the iconsRow div is not found, an error is returned.