#![cfg_attr(docsrs, feature(doc_cfg))]
pub mod error;
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub mod http;
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub mod mirror;
#[cfg(feature = "profile")]
#[cfg_attr(docsrs, doc(cfg(feature = "profile")))]
pub mod profile;
#[cfg(all(test, feature = "http"))]
#[path = "../tests/common/mod.rs"]
pub(crate) mod test_common;
#[cfg(feature = "http")]
pub(crate) mod util;
pub mod uuid;
#[cfg(feature = "curseforge")]
#[cfg_attr(docsrs, doc(cfg(feature = "curseforge")))]
pub mod curseforge;
#[cfg(feature = "modrinth")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth")))]
pub mod modrinth;
#[cfg(feature = "mojang")]
#[cfg_attr(docsrs, doc(cfg(feature = "mojang")))]
pub mod mojang;
#[cfg(feature = "yggdrasil")]
#[cfg_attr(docsrs, doc(cfg(feature = "yggdrasil")))]
pub mod yggdrasil;
#[cfg(feature = "blessing")]
#[cfg_attr(docsrs, doc(cfg(feature = "blessing")))]
pub mod blessing;
#[cfg(feature = "loaders")]
#[cfg_attr(docsrs, doc(cfg(feature = "loaders")))]
pub mod loaders;
#[cfg(feature = "bmclapi")]
#[cfg_attr(docsrs, doc(cfg(feature = "bmclapi")))]
pub mod bmclapi;
#[cfg(feature = "java")]
#[cfg_attr(docsrs, doc(cfg(feature = "java")))]
pub mod java;
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub use error::ApiStatusError;
#[cfg(feature = "yggdrasil")]
#[cfg_attr(docsrs, doc(cfg(feature = "yggdrasil")))]
pub use error::YggdrasilError;
pub use error::{Error, Result};
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub use http::{HttpClient, HttpClientBuilder, ResiliencePolicy};
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub use mirror::{Mirror, RewriteRule};
pub use uuid::McUuid;
pub mod reexports {
pub use ::uuid;
#[cfg(any(
feature = "curseforge",
feature = "modrinth",
feature = "mojang",
feature = "java"
))]
#[cfg_attr(
docsrs,
doc(cfg(any(
feature = "curseforge",
feature = "modrinth",
feature = "mojang",
feature = "java"
)))
)]
pub use jiff;
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub use reqwest;
#[cfg(feature = "yggdrasil-verify")]
#[cfg_attr(docsrs, doc(cfg(feature = "yggdrasil-verify")))]
pub use rsa;
pub use serde_json;
#[cfg(any(feature = "http", feature = "profile"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "http", feature = "profile"))))]
pub use url;
}
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
#[derive(Clone, Debug, Default)]
pub struct McApiBuilder {
http: HttpClientBuilder,
}
#[cfg(feature = "http")]
impl McApiBuilder {
#[must_use]
pub fn new() -> Self {
Self {
http: HttpClientBuilder::new(),
}
}
#[must_use]
pub fn user_agent(mut self, user_agent: impl Into<String>) -> Self {
self.http = self.http.user_agent(user_agent);
self
}
#[must_use]
pub fn mirror(mut self, mirror: Mirror) -> Self {
self.http = self.http.mirror(mirror);
self
}
#[must_use]
pub fn resilience(mut self, resilience: ResiliencePolicy) -> Self {
self.http = self.http.resilience(resilience);
self
}
#[must_use]
pub fn timeout(mut self, timeout: std::time::Duration) -> Self {
self.http = self.http.timeout(timeout);
self
}
#[must_use]
pub fn default_header(
mut self,
name: reqwest::header::HeaderName,
value: reqwest::header::HeaderValue,
) -> Self {
self.http = self.http.default_header(name, value);
self
}
#[must_use]
pub fn reqwest_client(mut self, client: reqwest::Client) -> Self {
self.http = self.http.reqwest_client(client);
self
}
pub fn build(self) -> Result<McApi> {
Ok(McApi::from_http(self.http.build()?))
}
}
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
#[derive(Clone, Debug)]
pub struct McApi {
http: HttpClient,
}
#[cfg(feature = "http")]
impl McApi {
pub fn new() -> Result<Self> {
Ok(Self {
http: HttpClient::new()?,
})
}
#[must_use]
pub fn builder() -> McApiBuilder {
McApiBuilder::new()
}
#[must_use]
pub const fn from_http(http: HttpClient) -> Self {
Self { http }
}
#[must_use]
pub fn http(&self) -> &HttpClient {
&self.http
}
#[cfg(feature = "mojang")]
#[cfg_attr(docsrs, doc(cfg(feature = "mojang")))]
#[must_use]
pub fn mojang(&self) -> mojang::MojangClient {
mojang::MojangClient::from_http(self.http.clone())
}
#[cfg(feature = "modrinth")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth")))]
#[must_use]
pub fn modrinth(&self) -> modrinth::ModrinthClient {
modrinth::ModrinthClient::from_http(self.http.clone())
}
#[cfg(feature = "curseforge")]
#[cfg_attr(docsrs, doc(cfg(feature = "curseforge")))]
pub fn curseforge(&self, api_key: Option<&str>) -> Result<curseforge::CurseForgeClient> {
curseforge::CurseForgeClient::from_http(self.http.clone(), api_key)
}
#[cfg(feature = "yggdrasil")]
#[cfg_attr(docsrs, doc(cfg(feature = "yggdrasil")))]
pub fn yggdrasil(&self, api_root: impl AsRef<str>) -> Result<yggdrasil::YggdrasilClient> {
yggdrasil::YggdrasilClient::from_http(self.http.clone(), api_root)
}
#[cfg(feature = "yggdrasil-authlib")]
#[cfg_attr(docsrs, doc(cfg(feature = "yggdrasil-authlib")))]
#[must_use]
pub fn authlib_injector(&self) -> yggdrasil::authlib_injector::AuthlibInjectorClient {
yggdrasil::authlib_injector::AuthlibInjectorClient::from_http(self.http.clone())
}
#[cfg(feature = "blessing")]
#[cfg_attr(docsrs, doc(cfg(feature = "blessing")))]
pub fn blessing(&self, site_url: impl AsRef<str>) -> Result<blessing::BlessingClient> {
blessing::BlessingClient::from_http(self.http.clone(), site_url)
}
#[cfg(feature = "loaders")]
#[cfg_attr(docsrs, doc(cfg(feature = "loaders")))]
#[must_use]
pub fn loaders(&self) -> loaders::LoadersClient {
loaders::LoadersClient::from_http(self.http.clone())
}
#[cfg(feature = "bmclapi")]
#[cfg_attr(docsrs, doc(cfg(feature = "bmclapi")))]
#[must_use]
pub fn bmclapi(&self) -> bmclapi::BmclapiClient {
bmclapi::BmclapiClient::from_http(self.http.clone())
}
#[cfg(feature = "java")]
#[cfg_attr(docsrs, doc(cfg(feature = "java")))]
#[must_use]
pub fn java(&self) -> java::JavaClient {
java::JavaClient::from_http(self.http.clone())
}
}
#[cfg(feature = "http")]
impl From<HttpClient> for McApi {
fn from(http: HttpClient) -> Self {
Self { http }
}
}