jira-terminal 2.5.0

This is a command line application that can be used as a personal productivity tool for interacting with JIRA
use crate::{api, prelude::Result};

/// Get the user account id from email provided by user while config creation.
/// For most of the API Call, user email will not be valid due to recent changes in GDPR policies.
/// This function will fetch the unique account id for provided email.
///
/// # Arguments
///
/// * configuration - JSON Object for config stored in config file.
///
/// # Example
///
/// ```
/// let account_id = get_username(&configuration);
/// ```
pub fn get_username(configuration: &json::JsonValue) -> Result<String> {
    let url = format!(
        "user/search?query={}",
        configuration["email"].as_str().unwrap()
    );
    let api_request = api::request::ApiRequest {
        url,
        username: configuration["email"].as_str().unwrap().to_string(),
        password: configuration["token"].as_str().unwrap().to_string(),
        json: json::object! {},
        namespace: configuration["namespace"].as_str().unwrap().to_string(),
        version: configuration["jira-version"]
            .as_str()
            .unwrap_or("")
            .to_string()
            .parse::<u8>()
            .unwrap_or(3),
        auth_mode: configuration["auth_mode"]
            .as_str()
            .unwrap_or("Basic")
            .to_string(),
    };
    let response = api::get(api_request).unwrap();
    match response[0]["accountId"].as_str() {
        Some(acc_id) => Ok(String::from(acc_id)),
        None => Err("Authentication Failed".into()),
    }
}