pub struct Sis<'a> { /* private fields */ }Expand description
This struct is used to login to the sis system and get the moodle session.
Implementations§
Source§impl<'a> Sis<'a>
impl<'a> Sis<'a>
Sourcepub fn new(
login_url: &str,
get_moodle_session_url: &str,
headers_builder: &'a (dyn HeadersBuilder + 'a),
) -> Self
pub fn new( login_url: &str, get_moodle_session_url: &str, headers_builder: &'a (dyn HeadersBuilder + 'a), ) -> Self
Create a new Sis instance
§Arguments
login_url- The login url of the sis system (It varies by university, for example in EELU it’s https://sis.eelu.edu.eg/studentLogin)get_moodle_session_url- The url to get the moodle session (It varies by university, for example in EELU it’s https://sis.eelu.edu.eg/getJCI)headers_builder- The headers builder to use (In most cases you can use the default one or you can create your own if you want more control)
§Example
#[tokio::main]
async fn main() {
let headers_builder = DefaultHeadersBuilder::new(
"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0".to_string(),
"https://sis.eelu.edu.eg/static/PortalStudent.html".to_string(),
);
let mut sis = Sis::new(
"https://sis.eelu.edu.eg/studentLogin",
"https://sis.eelu.edu.eg/getJCI",
&headers_builder,
);
// Use the sis instance here...
}Sourcepub async fn login(
&mut self,
username: &String,
password: &String,
usertype: UserType,
) -> Result<()>
pub async fn login( &mut self, username: &String, password: &String, usertype: UserType, ) -> Result<()>
Login to sis
§Arguments
username- The username of the userpassword- The password of the userusertype- The type of the user (Student or Staff or System user)
§Example
#[tokio::main]
async fn main() {
let username = std::env::var("SIS_USERNAME").unwrap();
let password = std::env::var("SIS_PASSWORD").unwrap();
// Crate Sis instance
let headers_builder = sis_login::headers_builder::DefaultHeadersBuilder::new(
"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0".to_string(),
"https://sis.eelu.edu.eg/static/PortalStudent.html".to_string()
);
let login_url: &str = "https://sis.eelu.edu.eg/studentLogin";
let get_moodle_session_url: &str = "https://sis.eelu.edu.eg/getJCI";
let mut sis = Sis::new(login_url, get_moodle_session_url, &headers_builder);
// Login to sis
match sis.login(&username, &password, UserType::Student).await {
Ok(_) => println!("Login Success"),
Err(err) => println!("Login Failed: {}", err),
}
}§Errors
SisError::SendRequestError- If there is an error while sending the request (e.g. network error)SisError::CreateClientError- If there is an error while creating the client (e.g. invalid url)SisError::AuthError- If the provided username or password is incorrectSisError::ParseLoginResultError- If there is an error while parsing the login result
Sourcepub async fn get_moodle_session(&self) -> Result<String>
pub async fn get_moodle_session(&self) -> Result<String>
Get Moodle Session URL
§Example
#[tokio::main]
async fn main() {
let username = std::env::var("SIS_USERNAME").unwrap();
let password = std::env::var("SIS_PASSWORD").unwrap();
// Crate Sis instance
let headers_builder = sis_login::headers_builder::DefaultHeadersBuilder::new(
"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0".to_string(),
"https://sis.eelu.edu.eg/static/PortalStudent.html".to_string()
);
let login_url: &str = "https://sis.eelu.edu.eg/studentLogin";
let get_moodle_session_url: &str = "https://sis.eelu.edu.eg/getJCI";
let mut sis = Sis::new(login_url, get_moodle_session_url, &headers_builder);
// Login to sis
match sis.login(&username, &password, UserType::Student).await {
Ok(_) => println!("Login Success"),
Err(err) => println!("Login Failed: {}", err),
}
// Get Moodle Session URL
match sis.get_moodle_session().await {
Ok(url) => println!("Moodle Session URL: {}", url),
Err(err) => println!("Error While Get Moodle Session URL: {}", err),
}
}§Errors
SisError::SendRequestError- If there is an error while sending the request (e.g. network error)SisError::CreateClientError- If there is an error while creating the client (e.g. invalid url)SisError::ParseLoginResultError- If there is an error while parsing the login result (e.g. invalid response)
Auto Trait Implementations§
impl<'a> Freeze for Sis<'a>
impl<'a> !RefUnwindSafe for Sis<'a>
impl<'a> !Send for Sis<'a>
impl<'a> !Sync for Sis<'a>
impl<'a> Unpin for Sis<'a>
impl<'a> !UnwindSafe for Sis<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more