Sis

Struct Sis 

Source
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>

Source

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...
}
Source

pub async fn login( &mut self, username: &String, password: &String, usertype: UserType, ) -> Result<()>

Login to sis

§Arguments
  • username - The username of the user
  • password - The password of the user
  • usertype - 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 incorrect
  • SisError::ParseLoginResultError - If there is an error while parsing the login result
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more