#![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 std::string::ToString;
use reqwest::{Client, Method};
use url::Url;
use uuid::Uuid;
use crate::enums::esport_locales::EsportsLocales;
use crate::enums::platform::Platform;
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::competitive_updates_v1::CompetitiveUpdatesV1;
use crate::response_types::content_v3::ContentV3;
use crate::response_types::esports_service_leagues::EsportsLeagues;
use crate::response_types::esports_service_schedule::EsportsSchedule;
use crate::response_types::esports_service_vods::EsportsVod;
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;
pub mod enums;
pub mod errors;
pub mod response_types;
pub mod utils;
const ESPORTS_API_KEY: &str = "0TvQnueqKa5mxJntVWt0w4LpLfEkrV1Ta8rQBb9Z";
pub async fn get_match_history_v1(
credentials_manager: &CredentialsManager,
http_client: &Client,
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/{puuid}",
region.to_shard(),
))?;
set_query_args(&mut url, query_args.into_iter());
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::new(),
)
.await
}
pub async fn get_match_details_v1(
credentials_manager: &CredentialsManager,
http_client: &Client,
region: Region,
match_id: &Uuid,
) -> Result<MatchDetailsV1, RequestError> {
let url = Url::from_str(&format!(
"https://pd.{}.a.pvp.net/match-details/v1/matches/{match_id}",
region.to_shard(),
))?;
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::new(),
)
.await
}
pub async fn get_mmr_details_v1(
credentials_manager: &CredentialsManager,
http_client: &Client,
region: Region,
puuid: &Uuid,
) -> Result<MMRDetailsV1, RequestError> {
let url = Url::from_str(&format!(
"https://pd.{}.a.pvp.net/mmr/v1/players/{puuid}",
region.to_shard(),
))?;
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::new(),
)
.await
}
pub async fn get_competitive_updates_v1(
credentials_manager: &CredentialsManager,
http_client: &Client,
region: Region,
puuid: &Uuid,
query_args: HashMap<CompetitiveUpdateQueryArg, String>,
) -> Result<CompetitiveUpdatesV1, RequestError> {
let mut url = Url::from_str(&format!(
"https://pd.{}.a.pvp.net/mmr/v1/players/{puuid}/competitiveupdates",
region.to_shard(),
))?;
set_query_args(&mut url, query_args.into_iter());
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::new(),
)
.await
}
pub async fn get_content_v3(
credentials_manager: &CredentialsManager,
http_client: &Client,
region: Region,
) -> Result<ContentV3, RequestError> {
let url = Url::from_str(&format!(
"https://shared.{}.a.pvp.net/content-service/v3/content",
region.to_shard(),
))?;
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::new(),
)
.await
}
pub async fn get_leaderboard_v1(
credentials_manager: &CredentialsManager,
http_client: &Client,
region: Region,
season: &Uuid,
query_args: HashMap<LeaderboardQueryArg, String>,
) -> Result<LeaderboardV1, RequestError> {
let queue = match credentials_manager.platform {
Platform::PC => "competitive",
Platform::XBOX | Platform::PlayStation => "console_competitive",
};
let mut url = Url::from_str(&format!(
"https://pd.{}.a.pvp.net/mmr/v1/leaderboards/affinity/{region}/queue/{queue}/season/{season}",
region.to_shard(),
))?;
set_query_args(&mut url, query_args.into_iter());
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::new(),
)
.await
}
pub async fn get_store_offers_v1(
credentials_manager: &CredentialsManager,
http_client: &Client,
region: Region,
) -> Result<StoreOffersV1, RequestError> {
let url = Url::from_str(&format!(
"https://pd.{}.a.pvp.net/store/v1/offers/",
region.to_shard(),
))?;
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::new(),
)
.await
}
pub async fn get_store_front_v2(
credentials_manager: &CredentialsManager,
http_client: &Client,
region: Region,
puuid: Uuid,
) -> Result<StoreFrontV2, RequestError> {
let url = Url::from_str(&format!(
"https://pd.{}.a.pvp.net/store/v2/storefront/{puuid}",
region.to_shard(),
))?;
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::new(),
)
.await
}
pub async fn get_account_aliases(
credentials_manager: &CredentialsManager,
http_client: &Client,
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,
Method::GET,
"",
&HashMap::new(),
)
.await
}
pub async fn get_esports_leagues(
credentials_manager: &CredentialsManager,
http_client: &Client,
locale: EsportsLocales,
) -> Result<EsportsLeagues, RequestError> {
let url = Url::from_str(&format!(
"https://esports-api.service.valorantesports.com/persisted/val/getLeagues?hl={locale}&sport=val"
))?;
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::from([("x-api-key".to_string(), ESPORTS_API_KEY.to_string())]),
)
.await
}
pub async fn get_esports_schedule(
credentials_manager: &CredentialsManager,
http_client: &Client,
locale: EsportsLocales,
) -> Result<EsportsSchedule, RequestError> {
let url = Url::from_str(&format!(
"https://esports-api.service.valorantesports.com/persisted/val/getSchedule?hl={locale}&sport=val"
))?;
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::from([("x-api-key".to_string(), ESPORTS_API_KEY.to_string())]),
)
.await
}
pub async fn get_esports_vods(
credentials_manager: &CredentialsManager,
http_client: &Client,
locale: EsportsLocales,
) -> Result<EsportsVod, RequestError> {
let url = Url::from_str(&format!(
"https://esports-api.service.valorantesports.com/persisted/val/getVods?hl={locale}&sport=val"
))?;
fetch_endpoint(
credentials_manager,
http_client,
url,
Method::GET,
"",
&HashMap::from([("x-api-key".to_string(), ESPORTS_API_KEY.to_string())]),
)
.await
}