Crates.io | pandascore |
lib.rs | pandascore |
version | 0.5.3 |
source | src |
created_at | 2024-09-02 06:28:56.349646 |
updated_at | 2024-09-18 23:01:04.694074 |
description | A Rust client for the Pandascore API |
homepage | |
repository | https://github.com/ansg191/pandascore |
max_upload_size | |
id | 1360153 |
size | 282,131 |
Currently only supports the free tier of the API.
To search for a league by name:
use anyhow::Context;
use pandascore::{
endpoint::{all::leagues::ListLeagues, CollectionOptions},
Client,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let token = std::env::var("PANDASCORE_TOKEN").context("PANDASCORE_TOKEN missing")?;
let search = std::env::args().nth(1).unwrap_or_else(|| "LCK".to_owned());
let list_leagues = ListLeagues(CollectionOptions::new().search("name", search));
let client = Client::new(reqwest::Client::new(), token)?;
let response = client.execute(list_leagues).await?;
println!("{:#?}", response);
Ok(())
}
To get a player by ID or name:
use anyhow::Context;
use pandascore::{endpoint::all::players::GetPlayer, model::Identifier, Client};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let token = std::env::var("PANDASCORE_TOKEN").context("PANDASCORE_TOKEN missing")?;
let arg = std::env::args()
.nth(1)
.unwrap_or_else(|| "faker".to_owned());
let get_player = match arg.parse::<u64>() {
Ok(id) => GetPlayer(Identifier::Id(id)),
Err(_) => GetPlayer(Identifier::Slug(&arg)),
};
let client = Client::new(reqwest::Client::new(), token)?;
let response = client.execute(get_player).await?;
println!("{:#?}", response);
Ok(())
}