#![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 crate::enums::query_arg::{
CompetitiveUpdateQueryArg, LeaderboardQueryArg, MatchHistoryQueryArg,
};
use crate::enums::region::Region;
use crate::errors::response_error::RequestError;
use crate::response_types::account_aliases_v1::AccountAliasesV1;
use crate::response_types::competitve_updates_v1::CompetitveUpdatesV1;
use crate::response_types::content_v3::ContentV3;
use crate::response_types::leaderboard_v1::LeaderboardV1;
use crate::response_types::matchdetails_v1::MatchDetailsV1;
use crate::response_types::matchhistory_v1::MatchHistoryV1;
use crate::response_types::mmrdetails_v1::MMRDetailsV1;
use crate::response_types::store_front_v2::StoreFrontV2;
use crate::response_types::store_offers_v1::StoreOffersV1;
use crate::utils::credentials_manager::CredentialsManager;
use crate::utils::fetch::fetch_endpoint;
use crate::utils::functions::set_query_args;
use crate::utils::network::http_client::HttpClient;
use std::collections::HashMap;
use std::str::FromStr;
use url::Url;
use uuid::Uuid;
pub mod enums;
pub mod errors;
pub mod puuid_fetcher;
pub mod response_types;
pub mod utils;
#[cfg(feature = "puuid")]
pub use puuid_fetcher::PuuidFetcher;
pub async fn get_match_history_v1<T: HttpClient>(
credentials_manager: &CredentialsManager,
http_client: &T,
region: Region,
puuid: &Uuid,
query_args: HashMap<MatchHistoryQueryArg, String>,
) -> Result<MatchHistoryV1, RequestError> {
let mut url = Url::from_str(
format!(
"https://pd.{}.a.pvp.net/match-history/v1/history/{}",
region.to_shard(),
puuid
)
.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_match_details_v1<T: HttpClient>(
credentials_manager: &CredentialsManager,
http_client: &T,
region: Region,
match_id: &Uuid,
) -> Result<MatchDetailsV1, RequestError> {
let url = Url::from_str(
format!(
"https://pd.{}.a.pvp.net/match-details/v1/matches/{}",
region.to_shard(),
match_id
)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
&url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_mmr_details_v1<T: HttpClient>(
credentials_manager: &CredentialsManager,
http_client: &T,
region: Region,
puuid: &Uuid,
) -> Result<MMRDetailsV1, RequestError> {
let url = Url::from_str(
format!(
"https://pd.{}.a.pvp.net/mmr/v1/players/{}",
region.to_shard(),
puuid
)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
&url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_competitive_updates_v1<T: HttpClient>(
credentials_manager: &CredentialsManager,
http_client: &T,
region: Region,
puuid: &Uuid,
query_args: HashMap<CompetitiveUpdateQueryArg, String>,
) -> Result<CompetitveUpdatesV1, RequestError> {
let mut url = Url::from_str(
format!(
"https://pd.{}.a.pvp.net/mmr/v1/players/{}/competitiveupdates",
region.to_shard(),
puuid
)
.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_content_v3<T: HttpClient>(
credentials_manager: &CredentialsManager,
http_client: &T,
region: Region,
) -> Result<ContentV3, RequestError> {
let url = Url::from_str(
format!(
"https://shared.{}.a.pvp.net/content-service/v3/content",
region.to_shard(),
)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
&url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_leaderboard_v1<T: HttpClient>(
credentials_manager: &CredentialsManager,
http_client: &T,
region: Region,
season: &Uuid,
query_args: HashMap<LeaderboardQueryArg, String>,
) -> Result<LeaderboardV1, RequestError> {
let mut url = Url::from_str(
format!(
"https://pd.{}.a.pvp.net/mmr/v1/leaderboards/affinity/{}/queue/competitive/season/{}",
region.to_shard(),
region,
season
)
.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_store_offers_v1<T: HttpClient>(
credentials_manager: &CredentialsManager,
http_client: &T,
region: Region,
) -> Result<StoreOffersV1, RequestError> {
let url = Url::from_str(
format!(
"https://pd.{}.a.pvp.net/store/v1/offers/",
region.to_shard(),
)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
&url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_store_front_v2<T: HttpClient>(
credentials_manager: &CredentialsManager,
http_client: &T,
region: Region,
puuid: Uuid,
) -> Result<StoreFrontV2, RequestError> {
let url = Url::from_str(
format!(
"https://pd.{}.a.pvp.net/store/v2/storefront/{}",
region.to_shard(),
puuid,
)
.as_str(),
)?;
fetch_endpoint(
credentials_manager,
http_client,
&url,
"GET",
"",
&HashMap::new(),
)
.await
}
pub async fn get_account_aliases<T: HttpClient>(
credentials_manager: &CredentialsManager,
http_client: &T,
game_name: Option<&str>,
tag_line: Option<&str>,
) -> Result<AccountAliasesV1, RequestError> {
let mut url = Url::from_str("https://api.account.riotgames.com/aliases/v1/aliases")?;
if let Some(game_name) = game_name {
url.query_pairs_mut().append_pair("gameName", game_name);
}
if let Some(tag_line) = tag_line {
url.query_pairs_mut().append_pair("tagLine", tag_line);
}
fetch_endpoint(
credentials_manager,
http_client,
&url,
"GET",
"",
&HashMap::new(),
)
.await
}