UrlBundle remove getters

This commit is contained in:
Vincent Junge 2023-06-20 02:59:18 +02:00
parent 9942a4b100
commit f614e93892
No known key found for this signature in database
17 changed files with 62 additions and 79 deletions

View File

@ -17,7 +17,7 @@ impl Instance {
) -> Result<UserMeta, ChorusLibError> { ) -> Result<UserMeta, ChorusLibError> {
let json_schema = json!(login_schema); let json_schema = json!(login_schema);
let client = Client::new(); let client = Client::new();
let endpoint_url = self.urls.get_api().to_string() + "/auth/login"; let endpoint_url = self.urls.api.clone() + "/auth/login";
let request_builder = client.post(endpoint_url).body(json_schema.to_string()); let request_builder = client.post(endpoint_url).body(json_schema.to_string());
// We do not have a user yet, and the UserRateLimits will not be affected by a login // We do not have a user yet, and the UserRateLimits will not be affected by a login
// request (since login is an instance wide limit), which is why we are just cloning the // request (since login is an instance wide limit), which is why we are just cloning the

View File

@ -25,7 +25,7 @@ impl Instance {
) -> Result<UserMeta, ChorusLibError> { ) -> Result<UserMeta, ChorusLibError> {
let json_schema = json!(register_schema); let json_schema = json!(register_schema);
let client = Client::new(); let client = Client::new();
let endpoint_url = self.urls.get_api().to_string() + "/auth/register"; let endpoint_url = self.urls.api.clone() + "/auth/register";
let request_builder = client.post(endpoint_url).body(json_schema.to_string()); let request_builder = client.post(endpoint_url).body(json_schema.to_string());
// We do not have a user yet, and the UserRateLimits will not be affected by a login // We do not have a user yet, and the UserRateLimits will not be affected by a login
// request (since register is an instance wide limit), which is why we are just cloning // request (since register is an instance wide limit), which is why we are just cloning
@ -59,8 +59,7 @@ impl Instance {
return Err(ChorusLibError::InvalidFormBodyError { error_type, error }); return Err(ChorusLibError::InvalidFormBodyError { error_type, error });
} }
let user_object = self.get_user(token.clone(), None).await.unwrap(); let user_object = self.get_user(token.clone(), None).await.unwrap();
let settings = let settings = UserMeta::get_settings(&token, &self.urls.api, &mut self.limits)
UserMeta::get_settings(&token, &self.urls.get_api().to_string(), &mut self.limits)
.await .await
.unwrap(); .unwrap();
let user = UserMeta::new( let user = UserMeta::new(

View File

@ -10,7 +10,7 @@ use crate::{
impl Channel { impl Channel {
pub async fn get(user: &mut UserMeta, channel_id: &str) -> Result<Channel, ChorusLibError> { pub async fn get(user: &mut UserMeta, channel_id: &str) -> Result<Channel, ChorusLibError> {
let url = user.belongs_to.borrow_mut().urls.get_api().to_string(); let url = user.belongs_to.borrow_mut().urls.api.clone();
let request = Client::new() let request = Client::new()
.get(format!("{}/channels/{}/", url, channel_id)) .get(format!("{}/channels/{}/", url, channel_id))
.bearer_auth(user.token()); .bearer_auth(user.token());
@ -47,7 +47,7 @@ impl Channel {
let request = Client::new() let request = Client::new()
.delete(format!( .delete(format!(
"{}/channels/{}/", "{}/channels/{}/",
user.belongs_to.borrow_mut().urls.get_api(), user.belongs_to.borrow_mut().urls.api,
self.id self.id
)) ))
.bearer_auth(user.token()); .bearer_auth(user.token());
@ -78,7 +78,7 @@ impl Channel {
let request = Client::new() let request = Client::new()
.patch(format!( .patch(format!(
"{}/channels/{}/", "{}/channels/{}/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
channel_id channel_id
)) ))
.bearer_auth(user.token()) .bearer_auth(user.token())

View File

@ -25,7 +25,7 @@ impl Message {
message: &mut MessageSendSchema, message: &mut MessageSendSchema,
files: Option<Vec<PartialDiscordFileAttachment>>, files: Option<Vec<PartialDiscordFileAttachment>>,
) -> Result<Message, crate::errors::ChorusLibError> { ) -> Result<Message, crate::errors::ChorusLibError> {
let url_api = user.belongs_to.borrow().urls.get_api().to_string(); let url_api = user.belongs_to.borrow().urls.api.clone();
if files.is_none() { if files.is_none() {
let request = Client::new() let request = Client::new()

View File

@ -28,7 +28,7 @@ impl types::Channel {
let url = { let url = {
format!( format!(
"{}/channels/{}/permissions/{}", "{}/channels/{}/permissions/{}",
user.belongs_to.borrow_mut().urls.get_api(), user.belongs_to.borrow_mut().urls.api,
channel_id, channel_id,
overwrite.id overwrite.id
) )
@ -68,7 +68,7 @@ impl types::Channel {
) -> Option<ChorusLibError> { ) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/channels/{}/permissions/{}", "{}/channels/{}/permissions/{}",
user.belongs_to.borrow_mut().urls.get_api(), user.belongs_to.borrow_mut().urls.api,
channel_id, channel_id,
overwrite_id overwrite_id
); );

View File

@ -33,7 +33,7 @@ impl ReactionMeta {
pub async fn delete_all(&self, user: &mut UserMeta) -> Option<ChorusLibError> { pub async fn delete_all(&self, user: &mut UserMeta) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/channels/{}/messages/{}/reactions/", "{}/channels/{}/messages/{}/reactions/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
self.channel_id, self.channel_id,
self.message_id self.message_id
); );
@ -64,7 +64,7 @@ impl ReactionMeta {
pub async fn get(&self, emoji: &str, user: &mut UserMeta) -> Option<ChorusLibError> { pub async fn get(&self, emoji: &str, user: &mut UserMeta) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/channels/{}/messages/{}/reactions/{}/", "{}/channels/{}/messages/{}/reactions/{}/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
self.channel_id, self.channel_id,
self.message_id, self.message_id,
emoji emoji
@ -98,7 +98,7 @@ impl ReactionMeta {
pub async fn delete_emoji(&self, emoji: &str, user: &mut UserMeta) -> Option<ChorusLibError> { pub async fn delete_emoji(&self, emoji: &str, user: &mut UserMeta) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/channels/{}/messages/{}/reactions/{}/", "{}/channels/{}/messages/{}/reactions/{}/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
self.channel_id, self.channel_id,
self.message_id, self.message_id,
emoji emoji
@ -136,7 +136,7 @@ impl ReactionMeta {
pub async fn create(&self, emoji: &str, user: &mut UserMeta) -> Option<ChorusLibError> { pub async fn create(&self, emoji: &str, user: &mut UserMeta) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/channels/{}/messages/{}/reactions/{}/@me/", "{}/channels/{}/messages/{}/reactions/{}/@me/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
self.channel_id, self.channel_id,
self.message_id, self.message_id,
emoji emoji
@ -165,7 +165,7 @@ impl ReactionMeta {
pub async fn remove(&self, emoji: &str, user: &mut UserMeta) -> Option<ChorusLibError> { pub async fn remove(&self, emoji: &str, user: &mut UserMeta) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/channels/{}/messages/{}/reactions/{}/@me/", "{}/channels/{}/messages/{}/reactions/{}/@me/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
self.channel_id, self.channel_id,
self.message_id, self.message_id,
emoji emoji
@ -202,7 +202,7 @@ impl ReactionMeta {
) -> Option<ChorusLibError> { ) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/channels/{}/messages/{}/reactions/{}/{}", "{}/channels/{}/messages/{}/reactions/{}/{}",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
self.channel_id, self.channel_id,
self.message_id, self.message_id,
emoji, emoji,

View File

@ -32,7 +32,7 @@ impl Guild {
user: &mut UserMeta, user: &mut UserMeta,
guild_create_schema: GuildCreateSchema, guild_create_schema: GuildCreateSchema,
) -> Result<Guild, ChorusLibError> { ) -> Result<Guild, ChorusLibError> {
let url = format!("{}/guilds/", user.belongs_to.borrow().urls.get_api()); let url = format!("{}/guilds/", user.belongs_to.borrow().urls.api);
let request = reqwest::Client::new() let request = reqwest::Client::new()
.post(url.clone()) .post(url.clone())
.bearer_auth(user.token.clone()) .bearer_auth(user.token.clone())
@ -67,7 +67,7 @@ impl Guild {
pub async fn delete(user: &mut UserMeta, guild_id: &str) -> Option<ChorusLibError> { pub async fn delete(user: &mut UserMeta, guild_id: &str) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/guilds/{}/delete/", "{}/guilds/{}/delete/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
guild_id guild_id
); );
let request = reqwest::Client::new() let request = reqwest::Client::new()
@ -97,7 +97,7 @@ impl Guild {
let mut belongs_to = user.belongs_to.borrow_mut(); let mut belongs_to = user.belongs_to.borrow_mut();
Channel::_create( Channel::_create(
&user.token, &user.token,
&format!("{}", belongs_to.urls.get_api()), &format!("{}", belongs_to.urls.api),
&self.id.to_string(), &self.id.to_string(),
schema, schema,
&mut user.limits, &mut user.limits,
@ -119,7 +119,7 @@ impl Guild {
let request = Client::new() let request = Client::new()
.get(format!( .get(format!(
"{}/guilds/{}/channels/", "{}/guilds/{}/channels/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
self.id self.id
)) ))
.bearer_auth(user.token()); .bearer_auth(user.token());
@ -157,7 +157,7 @@ impl Guild {
pub async fn get(user: &mut UserMeta, guild_id: &str) -> Result<Guild, ChorusLibError> { pub async fn get(user: &mut UserMeta, guild_id: &str) -> Result<Guild, ChorusLibError> {
let mut belongs_to = user.belongs_to.borrow_mut(); let mut belongs_to = user.belongs_to.borrow_mut();
Guild::_get( Guild::_get(
&format!("{}", belongs_to.urls.get_api()), &format!("{}", belongs_to.urls.api),
guild_id, guild_id,
&user.token, &user.token,
&mut user.limits, &mut user.limits,
@ -217,7 +217,7 @@ impl Channel {
let mut belongs_to = user.belongs_to.borrow_mut(); let mut belongs_to = user.belongs_to.borrow_mut();
Channel::_create( Channel::_create(
&user.token, &user.token,
&format!("{}", belongs_to.urls.get_api()), &format!("{}", belongs_to.urls.api),
guild_id, guild_id,
schema, schema,
&mut user.limits, &mut user.limits,

View File

@ -26,7 +26,7 @@ impl types::GuildMember {
) -> Result<types::GuildMember, ChorusLibError> { ) -> Result<types::GuildMember, ChorusLibError> {
let url = format!( let url = format!(
"{}/guilds/{}/members/{}/", "{}/guilds/{}/members/{}/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
guild_id, guild_id,
member_id member_id
); );
@ -59,7 +59,7 @@ impl types::GuildMember {
) -> Option<ChorusLibError> { ) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/guilds/{}/members/{}/roles/{}/", "{}/guilds/{}/members/{}/roles/{}/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
guild_id, guild_id,
member_id, member_id,
role_id role_id
@ -88,7 +88,7 @@ impl types::GuildMember {
) -> Option<crate::errors::ChorusLibError> { ) -> Option<crate::errors::ChorusLibError> {
let url = format!( let url = format!(
"{}/guilds/{}/members/{}/roles/{}/", "{}/guilds/{}/members/{}/roles/{}/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
guild_id, guild_id,
member_id, member_id,
role_id role_id

View File

@ -29,7 +29,7 @@ impl types::RoleObject {
) -> Result<Option<Vec<RoleObject>>, ChorusLibError> { ) -> Result<Option<Vec<RoleObject>>, ChorusLibError> {
let url = format!( let url = format!(
"{}/guilds/{}/roles/", "{}/guilds/{}/roles/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
guild_id guild_id
); );
let request = Client::new().get(url).bearer_auth(user.token()); let request = Client::new().get(url).bearer_auth(user.token());
@ -68,7 +68,7 @@ impl types::RoleObject {
) -> Result<RoleObject, ChorusLibError> { ) -> Result<RoleObject, ChorusLibError> {
let url = format!( let url = format!(
"{}/guilds/{}/roles/{}/", "{}/guilds/{}/roles/{}/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
guild_id, guild_id,
role_id role_id
); );
@ -98,7 +98,7 @@ impl types::RoleObject {
) -> Result<RoleObject, ChorusLibError> { ) -> Result<RoleObject, ChorusLibError> {
let url = format!( let url = format!(
"{}/guilds/{}/roles/", "{}/guilds/{}/roles/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
guild_id guild_id
); );
let body = to_string::<RoleCreateModifySchema>(&role_create_schema).map_err(|e| { let body = to_string::<RoleCreateModifySchema>(&role_create_schema).map_err(|e| {
@ -132,7 +132,7 @@ impl types::RoleObject {
) -> Result<RoleObject, ChorusLibError> { ) -> Result<RoleObject, ChorusLibError> {
let url = format!( let url = format!(
"{}/guilds/{}/roles/", "{}/guilds/{}/roles/",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
guild_id guild_id
); );
let body = to_string(&role_position_update_schema).map_err(|e| { let body = to_string(&role_position_update_schema).map_err(|e| {
@ -172,7 +172,7 @@ impl types::RoleObject {
) -> Result<RoleObject, ChorusLibError> { ) -> Result<RoleObject, ChorusLibError> {
let url = format!( let url = format!(
"{}/guilds/{}/roles/{}", "{}/guilds/{}/roles/{}",
user.belongs_to.borrow().urls.get_api(), user.belongs_to.borrow().urls.api,
guild_id, guild_id,
role_id role_id
); );

View File

@ -15,7 +15,7 @@ impl Instance {
&self, &self,
) -> Result<GeneralConfiguration, ChorusLibError> { ) -> Result<GeneralConfiguration, ChorusLibError> {
let client = Client::new(); let client = Client::new();
let endpoint_url = self.urls.get_api().to_string() + "/policies/instance/"; let endpoint_url = self.urls.api.clone() + "/policies/instance/";
let request = match client.get(&endpoint_url).send().await { let request = match client.get(&endpoint_url).send().await {
Ok(result) => result, Ok(result) => result,
Err(e) => { Err(e) => {
@ -33,7 +33,6 @@ impl Instance {
} }
let body = request.text().await.unwrap(); let body = request.text().await.unwrap();
let instance_policies_schema: GeneralConfiguration = from_str(&body).unwrap(); Ok(from_str::<GeneralConfiguration>(&body).unwrap())
Ok(instance_policies_schema)
} }
} }

View File

@ -311,7 +311,7 @@ pub mod limits {
/// TODO: Change this to return a Result and handle the errors properly. /// TODO: Change this to return a Result and handle the errors properly.
pub async fn check_limits(api_url: String) -> Limits { pub async fn check_limits(api_url: String) -> Limits {
let client = Client::new(); let client = Client::new();
let url_parsed = crate::URLBundle::parse_url(api_url) + "/policies/instance/limits"; let url_parsed = crate::UrlBundle::parse_url(api_url) + "/policies/instance/limits";
let result = client let result = client
.get(url_parsed) .get(url_parsed)
.send() .send()

View File

@ -23,7 +23,7 @@ impl UserMeta {
) -> Result<Vec<types::PublicUser>, ChorusLibError> { ) -> Result<Vec<types::PublicUser>, ChorusLibError> {
let url = format!( let url = format!(
"{}/users/{}/relationships/", "{}/users/{}/relationships/",
self.belongs_to.borrow().urls.get_api(), self.belongs_to.borrow().urls.api,
user_id user_id
); );
let request = Client::new().get(url).bearer_auth(self.token()); let request = Client::new().get(url).bearer_auth(self.token());
@ -42,7 +42,7 @@ impl UserMeta {
pub async fn get_relationships(&mut self) -> Result<Vec<types::Relationship>, ChorusLibError> { pub async fn get_relationships(&mut self) -> Result<Vec<types::Relationship>, ChorusLibError> {
let url = format!( let url = format!(
"{}/users/@me/relationships/", "{}/users/@me/relationships/",
self.belongs_to.borrow().urls.get_api() self.belongs_to.borrow().urls.api
); );
let request = Client::new().get(url).bearer_auth(self.token()); let request = Client::new().get(url).bearer_auth(self.token());
deserialize_response::<Vec<types::Relationship>>( deserialize_response::<Vec<types::Relationship>>(
@ -67,7 +67,7 @@ impl UserMeta {
) -> Option<ChorusLibError> { ) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/users/@me/relationships/", "{}/users/@me/relationships/",
self.belongs_to.borrow().urls.get_api() self.belongs_to.borrow().urls.api
); );
let body = to_string(&schema).unwrap(); let body = to_string(&schema).unwrap();
let request = Client::new().post(url).bearer_auth(self.token()).body(body); let request = Client::new().post(url).bearer_auth(self.token()).body(body);
@ -140,7 +140,7 @@ impl UserMeta {
pub async fn remove_relationship(&mut self, user_id: &str) -> Option<ChorusLibError> { pub async fn remove_relationship(&mut self, user_id: &str) -> Option<ChorusLibError> {
let url = format!( let url = format!(
"{}/users/@me/relationships/{}/", "{}/users/@me/relationships/{}/",
self.belongs_to.borrow().urls.get_api(), self.belongs_to.borrow().urls.api,
user_id user_id
); );
let request = Client::new().delete(url).bearer_auth(self.token()); let request = Client::new().delete(url).bearer_auth(self.token());

View File

@ -52,10 +52,7 @@ impl UserMeta {
return Err(ChorusLibError::PasswordRequiredError); return Err(ChorusLibError::PasswordRequiredError);
} }
let request = Client::new() let request = Client::new()
.patch(format!( .patch(format!("{}/users/@me/", self.belongs_to.borrow().urls.api))
"{}/users/@me/",
self.belongs_to.borrow().urls.get_api()
))
.body(to_string(&modify_schema).unwrap()) .body(to_string(&modify_schema).unwrap())
.bearer_auth(self.token()); .bearer_auth(self.token());
let user_updated = let user_updated =
@ -79,7 +76,7 @@ impl UserMeta {
let request = Client::new() let request = Client::new()
.post(format!( .post(format!(
"{}/users/@me/delete/", "{}/users/@me/delete/",
self.belongs_to.borrow().urls.get_api() self.belongs_to.borrow().urls.api
)) ))
.bearer_auth(self.token()); .bearer_auth(self.token());
handle_request_as_option(request, &mut self, crate::api::limits::LimitType::Ip).await handle_request_as_option(request, &mut self, crate::api::limits::LimitType::Ip).await
@ -91,7 +88,7 @@ impl User {
let mut belongs_to = user.belongs_to.borrow_mut(); let mut belongs_to = user.belongs_to.borrow_mut();
User::_get( User::_get(
&user.token(), &user.token(),
&format!("{}", belongs_to.urls.get_api()), &format!("{}", belongs_to.urls.api),
&mut belongs_to.limits, &mut belongs_to.limits,
id, id,
) )
@ -166,6 +163,6 @@ impl Instance {
token: String, token: String,
id: Option<&String>, id: Option<&String>,
) -> Result<User, ChorusLibError> { ) -> Result<User, ChorusLibError> {
User::_get(&token, self.urls.get_api(), &mut self.limits, id).await User::_get(&token, &self.urls.api, &mut self.limits, id).await
} }
} }

View File

@ -7,14 +7,14 @@ use serde::{Deserialize, Serialize};
use crate::api::limits::Limits; use crate::api::limits::Limits;
use crate::errors::{ChorusLibError, FieldFormatError}; use crate::errors::{ChorusLibError, FieldFormatError};
use crate::types::{GeneralConfiguration, User, UserSettings}; use crate::types::{GeneralConfiguration, User, UserSettings};
use crate::URLBundle; use crate::UrlBundle;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
/** /**
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.
*/ */
pub struct Instance { pub struct Instance {
pub urls: URLBundle, pub urls: UrlBundle,
pub instance_info: GeneralConfiguration, pub instance_info: GeneralConfiguration,
pub limits: Limits, pub limits: Limits,
} }
@ -26,7 +26,7 @@ impl Instance {
/// * `requester` - The [`LimitedRequester`] that will be used to make requests to the Spacebar server. /// * `requester` - The [`LimitedRequester`] that will be used to make requests to the Spacebar server.
/// # Errors /// # Errors
/// * [`InstanceError`] - If the instance cannot be created. /// * [`InstanceError`] - If the instance cannot be created.
pub async fn new(urls: URLBundle) -> Result<Instance, ChorusLibError> { pub async fn new(urls: UrlBundle) -> Result<Instance, ChorusLibError> {
let mut instance = Instance { let mut instance = Instance {
urls: urls.clone(), urls: urls.clone(),
// Will be overwritten in the next step // Will be overwritten in the next step

View File

@ -18,18 +18,18 @@ pub mod voice;
#[derive(Clone, Default, Debug, PartialEq, Eq)] #[derive(Clone, Default, Debug, PartialEq, Eq)]
/// A URLBundle is a struct which bundles together the API-, Gateway- and CDN-URLs of a Spacebar /// A URLBundle is a struct which bundles together the API-, Gateway- and CDN-URLs of a Spacebar
/// instance. /// instance.
pub struct URLBundle { pub struct UrlBundle {
pub api: String, pub api: String,
pub wss: String, pub wss: String,
pub cdn: String, pub cdn: String,
} }
impl URLBundle { impl UrlBundle {
pub fn new(api: String, wss: String, cdn: String) -> Self { pub fn new(api: String, wss: String, cdn: String) -> Self {
Self { Self {
api: URLBundle::parse_url(api), api: UrlBundle::parse_url(api),
wss: URLBundle::parse_url(wss), wss: UrlBundle::parse_url(wss),
cdn: URLBundle::parse_url(cdn), cdn: UrlBundle::parse_url(cdn),
} }
} }
@ -44,13 +44,13 @@ impl URLBundle {
let url = match Url::parse(&url) { let url = match Url::parse(&url) {
Ok(url) => { Ok(url) => {
if url.scheme() == "localhost" { if url.scheme() == "localhost" {
return URLBundle::parse_url(format!("http://{}", url)); return UrlBundle::parse_url(format!("http://{}", url));
} }
url url
} }
Err(ParseError::RelativeUrlWithoutBase) => { Err(ParseError::RelativeUrlWithoutBase) => {
let url_fmt = format!("http://{}", url); let url_fmt = format!("http://{}", url);
return URLBundle::parse_url(url_fmt); return UrlBundle::parse_url(url_fmt);
} }
Err(_) => panic!("Invalid URL"), Err(_) => panic!("Invalid URL"),
}; };
@ -61,18 +61,6 @@ impl URLBundle {
} }
url_string url_string
} }
pub fn get_api(&self) -> &str {
&self.api
}
pub fn get_cdn(&self) -> &str {
&self.cdn
}
pub fn get_wss(&self) -> &str {
&self.wss
}
} }
#[cfg(test)] #[cfg(test)]
@ -81,13 +69,13 @@ mod lib {
#[test] #[test]
fn test_parse_url() { fn test_parse_url() {
let mut result = URLBundle::parse_url(String::from("localhost:3000/")); let mut result = UrlBundle::parse_url(String::from("localhost:3000/"));
assert_eq!(result, String::from("http://localhost:3000")); assert_eq!(result, String::from("http://localhost:3000"));
result = URLBundle::parse_url(String::from("https://some.url.com/")); result = UrlBundle::parse_url(String::from("https://some.url.com/"));
assert_eq!(result, String::from("https://some.url.com")); assert_eq!(result, String::from("https://some.url.com"));
result = URLBundle::parse_url(String::from("https://some.url.com/")); result = UrlBundle::parse_url(String::from("https://some.url.com/"));
assert_eq!(result, String::from("https://some.url.com")); assert_eq!(result, String::from("https://some.url.com"));
result = URLBundle::parse_url(String::from("https://some.url.com")); result = UrlBundle::parse_url(String::from("https://some.url.com"));
assert_eq!(result, String::from("https://some.url.com")); assert_eq!(result, String::from("https://some.url.com"));
} }
} }

View File

@ -256,13 +256,13 @@ impl LimitedRequester {
mod rate_limit { mod rate_limit {
use serde_json::from_str; use serde_json::from_str;
use crate::{api::limits::Config, URLBundle}; use crate::{api::limits::Config, UrlBundle};
use super::*; use super::*;
#[tokio::test] #[tokio::test]
async fn run_into_limit() { async fn run_into_limit() {
let urls = URLBundle::new( let urls = UrlBundle::new(
String::from("http://localhost:3001/api/"), String::from("http://localhost:3001/api/"),
String::from("wss://localhost:3001/"), String::from("wss://localhost:3001/"),
String::from("http://localhost:3001/cdn"), String::from("http://localhost:3001/cdn"),
@ -289,7 +289,7 @@ mod rate_limit {
#[tokio::test] #[tokio::test]
async fn test_send_request() { async fn test_send_request() {
let urls = URLBundle::new( let urls = UrlBundle::new(
String::from("http://localhost:3001/api/"), String::from("http://localhost:3001/api/"),
String::from("wss://localhost:3001/"), String::from("wss://localhost:3001/"),
String::from("http://localhost:3001/cdn"), String::from("http://localhost:3001/cdn"),

View File

@ -4,12 +4,12 @@ use chorus::{
Channel, ChannelCreateSchema, Guild, GuildCreateSchema, RegisterSchema, Channel, ChannelCreateSchema, Guild, GuildCreateSchema, RegisterSchema,
RegisterSchemaOptions, RoleCreateModifySchema, RoleObject, RegisterSchemaOptions, RoleCreateModifySchema, RoleObject,
}, },
URLBundle, UrlBundle,
}; };
#[derive(Debug)] #[derive(Debug)]
pub struct TestBundle { pub struct TestBundle {
pub urls: URLBundle, pub urls: UrlBundle,
pub user: UserMeta, pub user: UserMeta,
pub instance: Instance, pub instance: Instance,
pub guild: Guild, pub guild: Guild,
@ -19,7 +19,7 @@ pub struct TestBundle {
// Set up a test by creating an Instance and a User. Reduces Test boilerplate. // Set up a test by creating an Instance and a User. Reduces Test boilerplate.
pub async fn setup() -> TestBundle { pub async fn setup() -> TestBundle {
let urls = URLBundle::new( let urls = UrlBundle::new(
"http://localhost:3001/api".to_string(), "http://localhost:3001/api".to_string(),
"ws://localhost:3001".to_string(), "ws://localhost:3001".to_string(),
"http://localhost:3001".to_string(), "http://localhost:3001".to_string(),