Crates.io | ggapi |
lib.rs | ggapi |
version | 0.2.5 |
source | src |
created_at | 2023-07-24 03:15:22.948432 |
updated_at | 2024-07-17 00:00:22.625203 |
description | A library for communicating with start.gg's API. |
homepage | https://crates.io/crates/ggapi |
repository | https://github.com/pyropm/ggapi |
max_upload_size | |
id | 924192 |
size | 219,489 |
A library for communicating with start.gg's API.
You can use helper functions to get values off of start.gg:
let data = ggapi::get_tournament_info(
"evo-2023","INSERT_TOKEN_HERE"
).await;
match data {
ggapi::GGResponse::Data(data) => {
println!("{}", data.tournament().name());
println!("{}", data.tournament().start_at().to_string());
println!("{}", data.tournament().slug());
println!("{}", data.tournament().short_slug());
}
ggapi::GGResponse::Error(data) => {
println!("ggapi error: {}", data);
}
}
Each helper function will get a small specific set of values instead of a large query. See the notes below to see the reasoning why.
These helper functions are what are some of the most common uses of the API and should be able to cope with even the largest tournaments effectively.
If these helper functions aren't enough, you can execute a query directly like so:
let query = r#"
query GetTournamentInfo($slug: String!) {
tournament(slug: $slug) {
id
name
slug
shortSlug
startAt
events {
id
name
phases {
id
name
phaseGroups(query: { page: 1, perPage: 100 }) {
nodes {
id
displayIdentifier
}
}
}
slug
}
}
}
"#;
let vars = Vars { slug: slug.to_string(), page: 1, per_page: 100 };
let data = execute_query(&token, &query, vars).await;
println!("{}", data.tournament().name());
println!("{}", data.tournament().start_at().to_string());
println!("{}", data.tournament().slug());
println!("{}", data.tournament().short_slug());
This example does the same as the helper function get_tournament_info(), but it lets you customize the query to your liking.
When using execute_query() directly like this, you are not guaranteed to get a safe value back. Aside from potential errors, you are likely to hit the 1000 object limit if you are working with a large tournament, so try and use the helper functions whenever possible!
If you want to help contribute to the project, pull requests are encouraged! Most of the aspects of this are relatively simple, but any amount of help is appreciated! Just try and follow the same style of the existing files, the convention is there and (mostly) consistent across the entire library.