rowrap 0.0.0

A wrapper for the Roblox API.
Documentation
use anyhow::{anyhow, Error};
use crate::utils::is_cookie_valid;

pub struct Session {
    cookie: Option<String>,
}

impl Session {
    pub fn new() -> Session {
        Session { cookie: None }
    }

    pub async fn set_cookie(&mut self, cookie: String) -> Result<(), Error> {
        if is_cookie_valid(&cookie).await? {
            self.cookie = Some(cookie);
            return Ok(());
        };

        Err(anyhow!("Failed to set Cookie: Invalid Cookie."))
    }

    pub fn get_cookie(&self) -> Option<&String> {
        self.cookie.as_ref()
    }
}

impl Default for Session {
    fn default() -> Self {
        Self::new()
    }
}