diff --git a/src/api/schemas.rs b/src/api/schemas.rs index ad7d297..65b4fe1 100644 --- a/src/api/schemas.rs +++ b/src/api/schemas.rs @@ -3,7 +3,7 @@ pub mod schemas { use serde::{Deserialize, Serialize}; use std::{collections::HashMap, fmt}; - use crate::errors::FieldFormatError; + use crate::{errors::FieldFormatError, URLBundle}; /** A struct that represents a well-formed email address. @@ -380,6 +380,76 @@ pub mod schemas { pub message: String, pub code: String, } + + #[derive(Serialize, Deserialize, Debug)] + pub struct UserObject { + id: String, + username: String, + discriminator: String, + avatar: Option, + bot: Option, + system: Option, + mfa_enabled: Option, + banner: Option, + accent_color: Option, + locale: String, + verified: Option, + email: Option, + flags: i8, + premium_type: Option, + public_flags: Option, + } + + #[derive(Debug)] + pub struct User { + logged_in: bool, + belongs_to: URLBundle, + token: String, + pub settings: UserSettings, + pub object: UserObject, + } + + impl User { + pub fn is_logged_in(&self) -> bool { + if self.logged_in == true { + true + } else { + false + } + } + + pub fn belongs_to(&self) -> URLBundle { + return self.belongs_to.clone(); + } + + pub fn token(&self) -> String { + return self.token.clone(); + } + + pub fn set_logged_in(&mut self, bool: bool) { + self.logged_in = bool; + } + + pub fn set_token(&mut self, token: String) { + self.token = token; + } + + pub fn new( + logged_in: bool, + belongs_to: URLBundle, + token: String, + settings: UserSettings, + object: UserObject, + ) -> User { + User { + logged_in, + belongs_to, + token, + settings, + object, + } + } + } } // I know that some of these tests are... really really basic and unneccessary, but sometimes, I diff --git a/src/instance.rs b/src/instance.rs index 702d25b..d606b42 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -1,5 +1,5 @@ use crate::api::limits::{Limit, LimitType, Limits}; -use crate::api::schemas::schemas::InstancePoliciesSchema; +use crate::api::schemas::schemas::{InstancePoliciesSchema, User}; use crate::errors::{FieldFormatError, InstanceServerError}; use crate::limit::LimitedRequester; use crate::URLBundle; @@ -17,7 +17,7 @@ pub struct Instance { pub requester: LimitedRequester, pub limits: Limits, //pub gateway: Gateway, - pub users: HashMap, + pub users: HashMap, } impl Instance { @@ -31,7 +31,7 @@ impl Instance { urls: URLBundle, requester: LimitedRequester, ) -> Result { - let users: HashMap = HashMap::new(); + let users: HashMap = HashMap::new(); let mut instance = Instance { urls: urls.clone(), instance_info: InstancePoliciesSchema::new(