shyam-jokes-cli-blocking 1.1.1

Shyam's joke teller cli

pub fn get_joke(
    category:&String ,
    racist: &bool,
    sexist: &bool,
    religious: &bool,
    contains: &String,
) -> Result<String, String> {

    let mut final_url = format!(
        "https://sv443.net/jokeapi/v2/joke/{}/Search?contains={}",
        category,
        contains
    );
    final_url = final_url + build_blacklist(&racist, &sexist, &religious).as_str();

    let response = reqwest::blocking::get(&final_url);
    match response {
        Ok(response) => {
            Ok(response.text().unwrap())
        }
        Err(err) => {
            eprintln!("Error occurred while getting the joke {}", err);
            Err(err.to_string())
        }
    }
}

fn build_blacklist(racist: &bool, sexist: &bool, religious: &bool) -> String {
    let mut flags = Vec::new();
    if *racist {
        flags.push("racist");
    }
    if *sexist {
        flags.push("sexist");
    }
    if *religious {
        flags.push("religious");
    }
    if !flags.is_empty()
    {
        return "&blacklistFlags=".to_string() + &flags.join(",")
    }
    String::from("")
}