dns-wrapper 0.1.6

An API wrapper for Diplomacy and Strife
Documentation
use std::sync::RwLock;

pub mod output;
pub mod nation_resources;

/// This is a global struct that stores the api key.
/// Usage:
/// ```ignore
/// use dns-wrapper::api::ApiKey;
/// ApiKey.set_apikey("APIKEY");
/// ```
///
/// Should not be needed, but you can retrieve your api key with:
/// ```ignore
/// let api_key = ApiKey::get_apikey().ok_or("API key not set");
/// ```
pub struct ApiKey;

static API_KEY: RwLock<Option<String>> = RwLock::new(None);

impl ApiKey {
    // Function to set an API Key
    pub fn set_apikey(key: &str) {
        let mut api_key = API_KEY.write().unwrap();
        *api_key = Some(key.to_string())
    }

    // Retrieves a clone of the API Key
    pub fn get_apikey() -> Option<String> {
        let api_key = API_KEY.read().unwrap();
        api_key.clone()
    }
}