rujira 0.4.1

This module provides an API for working with Jira
Documentation
//! # Rujira
//!
//! This module provides an API for working with Jira.
//! ## Example usage:
//! ```
//! use dotenv::dotenv;
//! use rujira::*;
//! use tracing_subscriber::{fmt, EnvFilter};
//!
//! #[tokio::main]
//! async fn main() {
//!     dotenv().ok();
//!     fmt()
//!         .with_env_filter(EnvFilter::from_default_env())
//!         .compact()
//!         .init();
//!     let bot = Rujira::new().from_env_handler();
//!     let Ok(me) = crate::api::myself::get(bot).apply().await else {
//!         todo!()
//!     };
//!     tracing::debug!(?me);
//! }
//! ```

use std::{env, sync::Arc};

pub mod agile;
pub mod api;
pub mod error;

/// This is the basic structure for interacting with Jira.
///
/// Through it you can initialize the connection directly via structure fields or via environment variables
///
/// ## Examples
/// ```
/// use rujira::Rujira;
/// let bot = Rujira::new().from_env_handler();
/// ```
#[derive(Default, Clone)]
pub struct Rujira {
    /// Jira url, default is http://localhost:8080
    pub url: Arc<str>,
    /// Enable debug logging
    pub debug: bool,
    /// Allow task creation
    pub task_create: bool,
    /// Token
    pub token: Arc<str>,
}

impl Rujira {
    /// Create a new bot
    pub fn new() -> Self {
        Self {
            url: Arc::from("http://localhost:8080"),
            ..Default::default()
        }
    }

    /// Create a new bot from environment variables
    pub fn from_env_handler(self) -> Self {
        let url = Arc::from(env::var("RUJIRA_URL").unwrap_or("http://localhost:8080".to_string()));
        let debug = env::var("RUJIRA_DEBUG")
            .ok()
            .and_then(|v| v.parse().ok())
            .unwrap_or(false);
        let task_create = env::var("RUJIRA_TASK_CREATE")
            .ok()
            .and_then(|v| v.parse().ok())
            .unwrap_or(false);
        let token = Arc::from(env::var("RUJIRA_TOKEN").expect("RUJIRA_TOKEN not set"));
        Self {
            url,
            debug,
            task_create,
            token,
        }
    }
}

trait Rub {
    fn to_static(self) -> &'static str;
}

impl Rub for bool {
    fn to_static(self) -> &'static str {
        if self {
            "true"
        } else {
            "false"
        }
    }
}

#[cfg(test)]
mod tests;