#![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;
pub 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 = "java")]
#[cfg_attr(docsrs, doc(cfg(feature = "java")))]
pub mod java;
#[cfg(feature = "slp")]
#[cfg_attr(docsrs, doc(cfg(feature = "slp")))]
pub mod slp;
pub use error::{Error, Result};
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub use error::{RateLimitInfo, parse_rate_limit_headers};
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub use http::{HttpConfig, HttpCore, HttpCoreBuilder, ResiliencePolicy};
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub use mirror::{Mirror, RewriteRule};
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub use util::deserialize_optional_url;
pub use util::{encode_path_segment, trim_trailing_slash};
pub use uuid::McUuid;
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
#[derive(Clone, Debug)]
pub struct McApi {
http: HttpCore,
}
#[cfg(feature = "http")]
impl McApi {
pub fn new() -> Result<Self> {
Ok(Self {
http: HttpCore::new()?,
})
}
pub const fn from_http(http: HttpCore) -> Self {
Self { http }
}
pub fn builder() -> McApiBuilder {
McApiBuilder {
http: HttpCore::builder(),
}
}
pub fn http(&self) -> &HttpCore {
&self.http
}
#[cfg(feature = "mojang")]
#[cfg_attr(docsrs, doc(cfg(feature = "mojang")))]
pub fn mojang(&self) -> mojang::MojangClient {
mojang::MojangClient::from_http(self.http.clone())
}
#[cfg(feature = "modrinth")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth")))]
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 Into<String>) -> yggdrasil::YggdrasilClient {
yggdrasil::YggdrasilClient::from_http(self.http.clone(), api_root)
}
#[cfg(feature = "yggdrasil-authlib")]
#[cfg_attr(docsrs, doc(cfg(feature = "yggdrasil-authlib")))]
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 Into<String>) -> blessing::BlessingClient {
blessing::BlessingClient::from_http(self.http.clone(), site_url)
}
#[cfg(feature = "loaders")]
#[cfg_attr(docsrs, doc(cfg(feature = "loaders")))]
pub fn loaders(&self) -> loaders::LoadersClient {
loaders::LoadersClient::from_http(self.http.clone())
}
#[cfg(feature = "java")]
#[cfg_attr(docsrs, doc(cfg(feature = "java")))]
pub fn java(&self) -> java::JavaClient {
java::JavaClient::from_http(self.http.clone())
}
#[cfg(feature = "slp")]
#[cfg_attr(docsrs, doc(cfg(feature = "slp")))]
pub fn slp(&self) -> slp::SlpClient {
slp::SlpClient::new()
}
}
#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
#[derive(Clone, Debug, Default)]
pub struct McApiBuilder {
http: HttpCoreBuilder,
}
#[cfg(feature = "http")]
impl McApiBuilder {
pub fn user_agent(mut self, user_agent: impl Into<String>) -> Self {
self.http = self.http.user_agent(user_agent);
self
}
pub fn mirror(mut self, mirror: Mirror) -> Self {
self.http = self.http.mirror(mirror);
self
}
pub fn resilience(mut self, resilience: ResiliencePolicy) -> Self {
self.http = self.http.resilience(resilience);
self
}
pub fn timeout(mut self, timeout: std::time::Duration) -> Self {
self.http = self.http.timeout(timeout);
self
}
pub fn with_client(mut self, client: reqwest::Client) -> Self {
self.http = self.http.with_client(client);
self
}
pub fn build(self) -> Result<McApi> {
Ok(McApi {
http: self.http.build()?,
})
}
}