pub async fn login(
    username: String,
    password: String,
    endpoint: &str,
) -> Result<Client, Box<dyn Error>> {
    //
    // DEFINE DEFAULT HEADER VALUES.
    let content_type = String::from("application/json");
    let accept = String::from("text/plain");
    let accept_encoding = String::from("identity");
    let user_agent = String::from("duoalert_oxide");

    let mut login_json = HashMap::new();
    let mut login_headers = HeaderMap::new();

    //
    // ADD LOGIN HEADERS TO NEW CLIENT.
    println!("inserting login body...");
    login_json.insert("login", username);
    login_json.insert("password", password);
    println!("done.\n");

    println!("inserting login headers...");
    login_headers.insert("Content-Type", (&content_type).parse()?);
    login_headers.insert("Accept", (&accept).parse()?);
    login_headers.insert("Accept-Encoding", (&accept_encoding).parse()?);
    login_headers.insert("User-Agent", (&user_agent).parse()?);
    println!("done.\n");

    let client = Client::builder()
        .default_headers(login_headers.clone())
        .cookie_store(true)
        .build()?;

    println!("Posting auth request...");
    let resp: Response = client.post(endpoint).json(&login_json).send().await?;
    println!("done.\n");

    let response_headers = resp.headers();

    //
    // form Auth header with values
    login_headers.insert(
        "Authorization",
        (format!("Bearer {}", response_headers["jwt"].to_str()?)).parse()?,
    );

    Ok(client.clone())
}
//
/// `login()` returns a mutated client with set duolingo login headers and cookies.
///
/// it takes in a `username: &String`, `password: &String`, and a login `endpoint: &str`.
/// 
/// #### example:
/// ```
/// use duolingo_rs::{login};
/// use reqwest::Client;
///
/// fn main() {
///
///     //
///     // please FOR THE LOVE OF GOD don't hardcode your
///     // password in any app you make with this :(
///     let my_username: String = String::from("user0");
///     let my_password: String = String::from("unsafePa$5w0rd1234"); // grab this from a var or something
///
///     //
///     // use reqwest's Client to log in and set session cookies
///     let login_client = login(my_username,my_password,login_endpoint)?;
///    
///     // pass off the client anywhere you want now!
/// }
/// ```
`login()` returns a mutated client with set duolingo login headers and cookies.
` login () ` returns a mutated client with set duolingo login headers and cookies .
pub async fn login(
    username: String,
    password: String,
    endpoint: &str,
) -> Result<Client, Box<dyn Error>> {
    //
    // DEFINE DEFAULT HEADER VALUES.
    let content_type = String::from("application/json");
    let accept = String::from("text/plain");
    let accept_encoding = String::from("identity");
    let user_agent = String::from("duoalert_oxide");
    let mut login_json = HashMap::new();
    let mut login_headers = HeaderMap::new();
    //
    // ADD LOGIN HEADERS TO NEW CLIENT.
    println!("inserting login body...");
    login_json.insert("login", username);
    login_json.insert("password", password);
    println!("done.\n");
    println!("inserting login headers...");
    login_headers.insert("Content-Type", (&content_type).parse()?);
    login_headers.insert("Accept", (&accept).parse()?);
    login_headers.insert("Accept-Encoding", (&accept_encoding).parse()?);
    login_headers.insert("User-Agent", (&user_agent).parse()?);
    println!("done.\n");
    let client = Client::builder()
        .default_headers(login_headers.clone())
        .cookie_store(true)
        .build()?;
    println!("Posting auth request...");
    let resp: Response = client.post(endpoint).json(&login_json).send().await?;
    println!("done.\n");
    let response_headers = resp.headers();
    //
    // form Auth header with values
    login_headers.insert(
        "Authorization",
        (format!("Bearer {}", response_headers["jwt"].to_str()?)).parse()?,
    );
    Ok(client.clone())
}
pub async fn login ( username : String , password : String , endpoint : & str , ) -> Result < Client , Box < dyn Error > > { // // DEFINE DEFAULT HEADER VALUES. let content_type = String :: from ( " " ) ; let accept = String :: from ( " " ) ; let accept_encoding = String :: from ( " " ) ; let user_agent = String :: from ( " " ) ; let mut login_json = HashMap :: new ( ) ; let mut login_headers = HeaderMap :: new ( ) ; // // ADD LOGIN HEADERS TO NEW CLIENT. println ! ( " " ) ; login_json . insert ( " " , username ) ; login_json . insert ( " " , password ) ; println ! ( " \n " ) ; println ! ( " " ) ; login_headers . insert ( " " , ( & content_type ) . parse ( ) ? ) ; login_headers . insert ( " " , ( & accept ) . parse ( ) ? ) ; login_headers . insert ( " " , ( & accept_encoding ) . parse ( ) ? ) ; login_headers . insert ( " " , ( & user_agent ) . parse ( ) ? ) ; println ! ( " \n " ) ; let client = Client :: builder ( ) . default_headers ( login_headers . clone ( ) ) . cookie_store ( true ) . build ( ) ? ; println ! ( " " ) ; let resp : Response = client . post ( endpoint ) . json ( & login_json ) . send ( ) . await ? ; println ! ( " \n " ) ; let response_headers = resp . headers ( ) ; // // form Auth header with values login_headers . insert ( " " , ( format ! ( " " response_headers [ " " ] to_str ( ) ) ) . parse ( ) ? , ) ; Ok ( client . clone ( ) ) }
`login()` returns a mutated client with set duolingo login headers and cookies.
` login () ` returns a mutated client with set duolingo login headers and cookies .
username
String
password
String
endpoint
&str
username
String
password
String
endpoint
&str
example:
```
use duolingo_rs::{login};
use reqwest::Client.

fn main() {

please FOR THE LOVE OF GOD don't hardcode your
password in any app you make with this :(
let my_username: String = String::from("user0");
let my_password: String = String::from("unsafePa$5w0rd1234"); // grab this from a var or something

use reqwest's Client to log in and set session cookies
let login_client = login(my_username,my_password,login_endpoint)?.

pass off the client anywhere you want now.
` ` ` use duolingo_rs :: { login } ; use reqwest :: Client . fn main () { please FOR THE LOVE OF GOD don ' t hardcode your password in any app you make with this : ( let my_username : String = String :: from ( " user0 " ) ; let my_password : String = String :: from ( " unsafePa$5w0rd1234 " ) ; // grab this from a var or something use reqwest ' s Client to log in and set session cookies let login_client = login ( my_username my_password login_endpoint ) ? . pass off the client anywhere you want now .