#![deny(warnings)]
#![deny(unused)]
#![deny(clippy::expect_used)]
#![deny(clippy::get_unwrap)]
#![deny(clippy::exit)]
#![deny(clippy::indexing_slicing)]
#![deny(clippy::panic)]
#![deny(clippy::panic_in_result_fn)]
#![deny(clippy::unreachable)]
#![deny(clippy::unwrap_used)]
#![deny(clippy::unwrap_in_result)]
#![deny(clippy::print_stdout)]
#![allow(clippy::upper_case_acronyms)]
use std::collections::HashMap;
use std::str::FromStr;
use url::Url;
use uuid::Uuid;
use crate::enums::platform::Platform;
use crate::enums::query_arg::{ContentQueryArg, LeaderboardQueryArg};
use crate::enums::queue::Queue;
use crate::enums::region::Region;
use crate::errors::response_error::RequestError;
use crate::response_types::account_v1::AccountV1;
use crate::response_types::activeshards_v1::ActiveShardsV1;
use crate::response_types::content_v1::ContentV1;
use crate::response_types::leaderboard_v1::LeaderboardV1;
use crate::response_types::matchdetails_v1::MatchDetailsV1;
use crate::response_types::matchlists_v1::MatchListsV1;
use crate::response_types::platformdata_v1::PlatformDataV1;
use crate::response_types::recentmatches_v1::RecentMatchesV1;
use crate::utils::credentials_manager::CredentialsManager;
use crate::utils::fetch::fetch_endpoint;
use crate::utils::functions::set_query_args;
pub mod enums;
pub mod errors;
pub mod response_types;
pub mod utils;
pub async fn get_platform_data_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
region: Region,
) -> Result<PlatformDataV1, RequestError> {
let url = Url::from_str(
format!("https://{region}.api.riotgames.com/val/status/v1/platform-data",).as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_match_details_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
region: Region,
match_id: &Uuid,
) -> Result<MatchDetailsV1, RequestError> {
let url = Url::from_str(
format!("https://{region}.api.riotgames.com/val/match/v1/matches/{match_id}",).as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_match_details_console_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
region: Region,
match_id: &Uuid,
) -> Result<MatchDetailsV1, RequestError> {
let url = Url::from_str(
format!("https://{region}.api.riotgames.com/val/match/console/v1/matches/{match_id}",)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_match_lists_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
region: Region,
puuid: &str,
) -> Result<MatchListsV1, RequestError> {
let url = Url::from_str(
format!("https://{region}.api.riotgames.com/val/match/v1/matchlists/by-puuid/{puuid}",)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_match_lists_console_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
region: Region,
platform_type: Platform,
puuid: &str,
) -> Result<MatchListsV1, RequestError> {
let url = Url::from_str(
format!(
"https://{region}.api.riotgames.com/val/match/console/v1/matchlists/by-puuid/{puuid}?platformType={platform_type}",
)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_accounts_by_puuid_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
cluster: &str,
puuid: &str,
) -> Result<AccountV1, RequestError> {
let url = Url::from_str(
format!("https://{cluster}.api.riotgames.com/riot/account/v1/accounts/by-puuid/{puuid}",)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_accounts_by_name_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
cluster: &str,
name: &str,
tag: &str,
) -> Result<AccountV1, RequestError> {
let url = Url::from_str(
format!(
"https://{cluster}.api.riotgames.com/riot/account/v1/accounts/by-riot-id/{name}/{tag}",
)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_active_shards_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
cluster: &str,
puuid: &str,
) -> Result<ActiveShardsV1, RequestError> {
let url = Url::from_str(
format!(
"https://{cluster}.api.riotgames.com/riot/account/v1/active-shards/by-game/val/by-puuid/{puuid}",
)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_recent_matches_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
region: Region,
queue: Queue,
) -> Result<RecentMatchesV1, RequestError> {
let url = Url::from_str(
format!("https://{region}.api.riotgames.com/val/match/v1/recent-matches/by-queue/{queue}",)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_recent_matches_console_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
region: Region,
queue: Queue,
) -> Result<RecentMatchesV1, RequestError> {
let url = Url::from_str(
format!(
"https://{region}.api.riotgames.com/val/match/console/v1/recent-matches/by-queue/{queue}",
)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_content_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
region: Region,
query_args: &HashMap<ContentQueryArg, &str>,
) -> Result<ContentV1, RequestError> {
let mut url = Url::from_str(
format!("https://{region}.api.riotgames.com/val/content/v1/contents",).as_str(),
)?;
set_query_args(&mut url, query_args.iter());
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_leaderboard_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
region: Region,
act: &Uuid,
query_args: HashMap<LeaderboardQueryArg, String>,
) -> Result<LeaderboardV1, RequestError> {
let mut url = Url::from_str(
format!("https://{region}.api.riotgames.com/val/ranked/v1/leaderboards/by-act/{act}",)
.as_str(),
)?;
set_query_args(&mut url, query_args.into_iter());
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_leaderboard_console_v1(
credentials_manager: &CredentialsManager,
http_client: &reqwest::Client,
region: Region,
act: &Uuid,
query_args: HashMap<LeaderboardQueryArg, String>,
) -> Result<LeaderboardV1, RequestError> {
let mut url = Url::from_str(
format!(
"https://{region}.api.riotgames.com/val/console/ranked/v1/leaderboards/by-act/{act}",
)
.as_str(),
)?;
set_query_args(&mut url, query_args.into_iter());
fetch_endpoint(
credentials_manager,
http_client,
url,
"GET",
"",
&HashMap::new(),
)
.await
}