Compare commits
1 Commits
85fc9e2ca5
...
5b2a1b7547
Author | SHA1 | Date |
---|---|---|
kozabrada123 | 5b2a1b7547 |
|
@ -19,7 +19,6 @@ use crate::UrlBundle;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||||
/// The [`Instance`]; what you will be using to perform all sorts of actions on the Spacebar server.
|
/// The [`Instance`]; what you will be using to perform all sorts of actions on the Spacebar server.
|
||||||
///
|
|
||||||
/// If `limits_information` is `None`, then the instance will not be rate limited.
|
/// If `limits_information` is `None`, then the instance will not be rate limited.
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
pub urls: UrlBundle,
|
pub urls: UrlBundle,
|
||||||
|
@ -73,18 +72,8 @@ impl PartialEq for LimitsInformation {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
|
/// Creates a new [`Instance`] from the [relevant instance urls](UrlBundle). To create an Instance from one singular url, use [`Instance::from_root_url()`].
|
||||||
pub(crate) fn clone_limits_if_some(&self) -> Option<HashMap<LimitType, Limit>> {
|
async fn from_url_bundle(urls: UrlBundle) -> ChorusResult<Instance> {
|
||||||
if self.limits_information.is_some() {
|
|
||||||
return Some(self.limits_information.as_ref().unwrap().ratelimits.clone());
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new [`Instance`] from the [relevant instance urls](UrlBundle).
|
|
||||||
///
|
|
||||||
/// To create an Instance from one singular url, use [`Instance::new()`].
|
|
||||||
pub async fn from_url_bundle(urls: UrlBundle) -> ChorusResult<Instance> {
|
|
||||||
let is_limited: Option<LimitsConfiguration> = Instance::is_limited(&urls.api).await?;
|
let is_limited: Option<LimitsConfiguration> = Instance::is_limited(&urls.api).await?;
|
||||||
let limit_information;
|
let limit_information;
|
||||||
|
|
||||||
|
@ -114,9 +103,17 @@ impl Instance {
|
||||||
Ok(instance)
|
Ok(instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn clone_limits_if_some(&self) -> Option<HashMap<LimitType, Limit>> {
|
||||||
|
if self.limits_information.is_some() {
|
||||||
|
return Some(self.limits_information.as_ref().unwrap().ratelimits.clone());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new [`Instance`] by trying to get the [relevant instance urls](UrlBundle) from a root url.
|
/// Creates a new [`Instance`] by trying to get the [relevant instance urls](UrlBundle) from a root url.
|
||||||
|
/// Shorthand for `Instance::new(UrlBundle::from_root_domain(root_domain).await?)`.
|
||||||
///
|
///
|
||||||
/// Shorthand for `Instance::from_url_bundle(UrlBundle::from_root_domain(root_domain).await?)`.
|
/// If `limited` is `true`, then Chorus will track and enforce rate limits for this instance.
|
||||||
pub async fn new(root_url: &str) -> ChorusResult<Instance> {
|
pub async fn new(root_url: &str) -> ChorusResult<Instance> {
|
||||||
let urls = UrlBundle::from_root_url(root_url).await?;
|
let urls = UrlBundle::from_root_url(root_url).await?;
|
||||||
Instance::from_url_bundle(urls).await
|
Instance::from_url_bundle(urls).await
|
||||||
|
|
Loading…
Reference in New Issue