pub mod api;
pub mod clients;
pub mod errors;
use crate::errors::{Error, Kind, Result};
use std::env;
use std::env::VarError;
pub const YUPDATES_API_TOKEN: &str = "YUPDATES_API_TOKEN";
pub const YUPDATES_API_URL: &str = "YUPDATES_API_URL";
pub const X_AUTH_TOKEN_HEADER: &str = "X-Auth-Token";
pub fn env_or_default_url() -> Result<String> {
match env::var(YUPDATES_API_URL) {
Ok(s) => {
if s.ends_with('/') {
Ok(s)
} else {
Ok(format!("{}/", s))
}
}
Err(e) => {
let err = match e {
VarError::NotPresent => {
format!(
"sorry, during the preview you need to set {}",
YUPDATES_API_URL
)
}
VarError::NotUnicode(_) => {
format!("{} is not valid unicode", YUPDATES_API_URL)
}
};
Err(Error {
kind: Kind::Config(err),
})
}
}
}
pub fn api_token() -> Result<String> {
match env::var(YUPDATES_API_TOKEN) {
Ok(s) => Ok(s),
Err(e) => {
let err = match e {
VarError::NotPresent => {
format!("API token is missing, set {}", YUPDATES_API_TOKEN)
}
VarError::NotUnicode(_) => {
format!("{} is not valid unicode", YUPDATES_API_URL)
}
};
Err(Error {
kind: Kind::Config(err),
})
}
}
}