barebones riot_api + middleware Riven hack

main
Zynh0722 2024-02-09 01:31:57 -08:00
commit d747d1a6fa
5 changed files with 1582 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
.env

1526
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

15
Cargo.toml Normal file
View File

@ -0,0 +1,15 @@
[package]
name = "lol-pairing-stat-fetcher-rs"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
async-trait = "0.1.77"
dotenvy = "0.15.7"
redis = "0.24.0"
reqwest = "0.11.24"
reqwest-middleware = { git = "https://git.zynh.me/Zynh0722/reqwest-middleware.git" }
riven = { git = "https://git.zynh.me/Zynh0722/Riven.git", branch = "feat-middleware" }
tokio = { version = "1.36.0", features = ["full"] }

1
example.env Normal file
View File

@ -0,0 +1 @@
RG_API_KEY=api_key_here

38
src/main.rs Normal file
View File

@ -0,0 +1,38 @@
use std::error::Error;
use reqwest_middleware::ClientBuilder;
use riven::{RiotApi, RiotApiConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let r_api = fetch_api()?;
let summoner = r_api
.summoner_v4()
.get_by_summoner_name(riven::consts::PlatformRoute::NA1, "RavenShade")
.await?;
println!("{:#?}", summoner);
Ok(())
}
fn fetch_api() -> Result<RiotApi, Box<dyn Error>> {
dotenvy::dotenv()?;
let rg_api_key: String = std::env::var("RG_API_KEY")?;
let mut default_headers = reqwest::header::HeaderMap::new();
default_headers.insert(
RiotApiConfig::RIOT_KEY_HEADER,
reqwest::header::HeaderValue::from_bytes(rg_api_key.as_ref()).unwrap(),
);
let c_builder = ClientBuilder::new(
reqwest::ClientBuilder::new()
.default_headers(default_headers)
.build()?,
);
let config = RiotApiConfig::with_client_builder(c_builder);
Ok(RiotApi::new(config))
}