riot_api/lib.rs
1#![allow(unused, dead_code)]
2
3//! A crate to interact with the full Riot API in rust
4//!
5//! This crate provides the ability to fully interact with the Riot API using Rust. Each part is split out, although by default League
6//! is included with this crate. The breakout of features is intended to make the crate additive in a rust way.
7//!
8//! Explanation of features:
9//!
10//! ### no-default-features
11//! Interact simply with the Account endpoint and Riot Single Sign-On (RSSO). This is the base form of the crate
12//!
13//! ### default-features
14//! Interact with most features of League. Fetch matches, summoner information, champion information, queues, and more
15//!
16//! ### feature clash
17//! Enables the ability to interact with the Clash endpoint, for fetching information about player participation and
18//! performance in clash matches
19//!
20//! ### feature tournament
21//! Enables the ability to interact with the Tournament endpoint, for creating and managing content creator tournaments
22//! and generating tournament codes.
23//!
24//! ### feature tft (TODO)
25//! Allows interaction with the TFT endpoint, which enables fetching information on TFT matches and compositions
26//!
27//! ### feature val (TODO)
28//! Allows interaction with the Valorant endpoint, giving access to match information and performance
29//!
30//! ### Example
31//! Get a summoner by name & tagline, retrieve match ids, and then retrieve each match
32//!
33//! ```
34//! use riot_api::prelude::*;
35//!
36//! #[tokio::main]
37//! async fn main() {
38//! // Create a new API client
39//! let client = RiotApiClientBuilder::new()
40//! .api_key("YOUR_API_KEY".to_string())
41//! .default_platform(PlatformRouting::NA1) // Default platform is not required, but by default will be set to NA1
42//! .default_region(RegionRouting::AMERICAS) // Default region is not required, but by default will be set to Americas
43//! .build().unwrap();
44//!
45//! // Get the summoner by name#tag. Setting region to `None` will use the default region
46//! let summoner = client.account_by_riot_id(None, "MatrixSenpai".to_string(), "STDIN".to_string()).await.unwrap();
47//! // There are multiple optional params to include here, including count, start (for paging), start/end time, and more
48//! let match_ids = client.matches_by_puuid(None, summoner.puuid, None, None, None, None, None, None).await.unwrap();
49//!
50//! let mut matches = Vec::new();
51//! for match_id in match_ids.into_iter() {
52//! let match_item = client.match_by_id(None, match_id).await.unwrap();
53//! matches.push(match_item);
54//! }
55//! }
56
57pub mod endpoints;
58pub mod models;
59
60pub mod prelude {
61 pub use crate::models::{
62 RiotApiClient, RiotApiClientBuilder,
63 routing::*
64 };
65}
66
67#[cfg(test)]
68mod tests {
69 use crate::{
70 prelude::*,
71 models::tournament::{
72 ProviderRegistrationParamsV5,
73 TournamentRegistrationParamsV5,
74 TournamentCodeParamsV5,
75 GamePickType,
76 MapType,
77 SpectatorType,
78 }
79 };
80
81 pub(crate) struct TestEnvVars {
82 pub(crate) default_platform: PlatformRouting,
83 pub(crate) default_region: RegionRouting,
84 pub(crate) api_key: String,
85 pub(crate) test_game_name: String,
86 pub(crate) test_tag_line: String,
87 pub(crate) test_puuid: String,
88 pub(crate) test_summoner_id: String,
89 pub(crate) test_champion_id: i32,
90 pub(crate) test_match_id: String,
91
92 pub(crate) test_tournament_provider_id: i32,
93 pub(crate) test_tournament_region: String,
94 pub(crate) test_tournament_provider_url: String,
95 pub(crate) test_tournament_id: i32,
96 pub(crate) test_tournament_name: String,
97 pub(crate) test_tournament_lobby: String,
98 pub(crate) test_tournament_code: String,
99 pub(crate) test_tournament_provider_params: ProviderRegistrationParamsV5,
100 pub(crate) test_tournament_registration_params: TournamentRegistrationParamsV5,
101 pub(crate) test_tournament_code_params: TournamentCodeParamsV5,
102 }
103 impl Default for TestEnvVars {
104 fn default() -> Self {
105 use std::env::var;
106
107 Self {
108 default_platform: PlatformRouting::NA1,
109 default_region: RegionRouting::AMERICAS,
110 api_key: var("API_KEY").unwrap(),
111 test_game_name: var("TEST_GAME_NAME").unwrap(),
112 test_tag_line: var("TEST_TAG_LINE").unwrap(),
113 test_puuid: var("TEST_PUUID").unwrap(),
114 test_summoner_id: var("TEST_SUMMONER_ID").unwrap(),
115 test_champion_id: var("TEST_CHAMPION_ID").unwrap().parse().unwrap(),
116 test_match_id: var("TEST_MATCH_ID").unwrap(),
117 test_tournament_provider_id: var("TEST_TOURNAMENT_PROVIDER_ID").unwrap().parse().unwrap(),
118 test_tournament_region: var("TEST_TOURNAMENT_REGION").unwrap(),
119 test_tournament_provider_url: var("TEST_TOURNAMENT_PROVIDER_URL").unwrap(),
120 test_tournament_id: var("TEST_TOURNAMENT_ID").unwrap().parse().unwrap(),
121 test_tournament_name: var("TEST_TOURNAMENT_NAME").unwrap(),
122 test_tournament_lobby: var("TEST_TOURNAMENT_LOBBY").unwrap(),
123 test_tournament_code: var("TEST_TOURNAMENT_CODE").unwrap(),
124 test_tournament_provider_params: ProviderRegistrationParamsV5 {
125 region: var("TEST_TOURNAMENT_REGION").unwrap(),
126 url: var("TEST_TOURNAMENT_PROVIDER_URL").unwrap(),
127 },
128 test_tournament_registration_params: TournamentRegistrationParamsV5 {
129 provider_id: var("TEST_TOURNAMENT_PROVIDER_ID").unwrap().parse().unwrap(),
130 name: Some(var("TEST_TOURNAMENT_NAME").unwrap())
131 },
132 test_tournament_code_params: TournamentCodeParamsV5 {
133 allowed_participants: None,
134 metadata: None,
135 team_size: 1,
136 pick_type: GamePickType::TournamentDraft,
137 map_type: MapType::SummonersRift,
138 spectator_type: SpectatorType::LobbyOnly,
139 enough_players: true,
140 }
141 }
142 }
143 }
144
145 pub(crate) fn setup() -> (RiotApiClient, TestEnvVars) {
146 dotenv::dotenv().ok();
147
148 let client = reqwest::Client::new();
149 let test_vars = TestEnvVars::default();
150
151 let riot_client = RiotApiClientBuilder::new()
152 .default_region(test_vars.default_region.clone())
153 .default_platform(test_vars.default_platform.clone())
154 .riot_token(test_vars.api_key.clone())
155 .with_client(client)
156 .build();
157
158 (riot_client.unwrap(), test_vars)
159 }
160}