diff --git a/Cargo.lock b/Cargo.lock index 49f3333..f6b0dd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -411,6 +411,7 @@ dependencies = [ "ics", "log", "minidom", + "once_cell", "reqwest", "sanitize-filename", "serde", @@ -549,9 +550,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.5.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "openssl" diff --git a/Cargo.toml b/Cargo.toml index c8b3fa4..1fa947a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ ical = { version = "0.6", features = ["serde-derive"] } ics = "0.5" chrono = { version = "0.4", features = ["serde"] } csscolorparser = { version = "0.5", features = ["serde"] } +once_cell = "1.8" [patch.crates-io] ical = { git = "https://github.com/daladim/ical-rs.git", branch = "ical_serde" } diff --git a/examples/provider-sync.rs b/examples/provider-sync.rs index b8b5234..602a74e 100644 --- a/examples/provider-sync.rs +++ b/examples/provider-sync.rs @@ -1,3 +1,5 @@ +//! This is an example of how kitchen-fridge can be used + use std::path::Path; use chrono::{Utc}; @@ -12,16 +14,22 @@ use kitchen_fridge::cache::Cache; use kitchen_fridge::CalDavProvider; use kitchen_fridge::traits::BaseCalendar; use kitchen_fridge::traits::CompleteCalendar; -use kitchen_fridge::settings::URL; -use kitchen_fridge::settings::USERNAME; -use kitchen_fridge::settings::PASSWORD; -use kitchen_fridge::settings::EXAMPLE_CREATED_CALENDAR_URL; -use kitchen_fridge::settings::EXAMPLE_EXISTING_CALENDAR_URL; use kitchen_fridge::utils::pause; const CACHE_FOLDER: &str = "test_cache/provider_sync"; +// TODO: change these values with yours +pub const URL: &str = "https://my.server.com/remote.php/dav/files/john"; +pub const USERNAME: &str = "username"; +pub const PASSWORD: &str = "secret_password"; + +pub const EXAMPLE_TASK_URL: &str = "https://my.server.com/remote.php/dav/calendars/john/6121A0BE-C2E0-4F16-A3FA-658E54E7062A/74439558-CDFF-426C-92CD-ECDDACE971B0.ics"; +pub const EXAMPLE_EXISTING_CALENDAR_URL: &str = "https://my.server.com/remote.php/dav/calendars/john/a_calendar_name/"; +pub const EXAMPLE_CREATED_CALENDAR_URL: &str = "https://my.server.com/remote.php/dav/calendars/john/a_calendar_that_we_have_created/"; + + + #[tokio::main] async fn main() { env_logger::init(); diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..80615ab --- /dev/null +++ b/src/config.rs @@ -0,0 +1,11 @@ +//! Support for compile-time configuration options + +use once_cell::sync::Lazy; + +/// Part of the ProdID string that describes the organization (example of a ProdID string: `-//ABC Corporation//My Product//EN`) +/// You can override it at compile-time with the `KITCHEN_FRIDGE_ICAL_ORG_NAME` environment variable, or keep the default value +pub static ORG_NAME: Lazy = Lazy::new(|| option_env!("KITCHEN_FRIDGE_ICAL_ORG_NAME").unwrap_or("My organization").to_string() ); + +/// Part of the ProdID string that describes the product name (example of a ProdID string: `-//ABC Corporation//My Product//EN`) +/// You can override it at compile-time with the `KITCHEN_FRIDGE_ICAL_PRODUCT_NAME` environment variable, or keep the default value +pub static PRODUCT_NAME: Lazy = Lazy::new(|| option_env!("KITCHEN_FRIDGE_ICAL_PRODUCT_NAME").unwrap_or("KitchenFridge").to_string() ); diff --git a/src/ical/builder.rs b/src/ical/builder.rs index 0b3b99c..05550e9 100644 --- a/src/ical/builder.rs +++ b/src/ical/builder.rs @@ -85,7 +85,7 @@ fn ical_to_ics_property(prop: IcalProperty) -> IcsProperty<'static> { mod tests { use super::*; use crate::Task; - use crate::settings::{ORG_NAME, PRODUCT_NAME}; + use crate::config::{ORG_NAME, PRODUCT_NAME}; #[test] fn test_ical_from_completed_task() { @@ -104,7 +104,7 @@ mod tests { COMPLETED:{}\r\n\ STATUS:COMPLETED\r\n\ END:VTODO\r\n\ - END:VCALENDAR\r\n", ORG_NAME, PRODUCT_NAME, uid, s_now, s_now, s_now, s_now); + END:VCALENDAR\r\n", *ORG_NAME, *PRODUCT_NAME, uid, s_now, s_now, s_now, s_now); assert_eq!(ical, expected_ical); } @@ -124,7 +124,7 @@ mod tests { SUMMARY:This is a task with ÜTF-8 characters\r\n\ STATUS:NEEDS-ACTION\r\n\ END:VTODO\r\n\ - END:VCALENDAR\r\n", ORG_NAME, PRODUCT_NAME, uid, s_now, s_now, s_now); + END:VCALENDAR\r\n", *ORG_NAME, *PRODUCT_NAME, uid, s_now, s_now, s_now); assert_eq!(ical, expected_ical); } diff --git a/src/ical/mod.rs b/src/ical/mod.rs index 2f5cecc..4931105 100644 --- a/src/ical/mod.rs +++ b/src/ical/mod.rs @@ -7,10 +7,10 @@ pub use parser::parse; mod builder; pub use builder::build_from; -use crate::settings::{ORG_NAME, PRODUCT_NAME}; +use crate::config::{ORG_NAME, PRODUCT_NAME}; pub fn default_prod_id() -> String { - format!("-//{}//{}//EN", ORG_NAME, PRODUCT_NAME) + format!("-//{}//{}//EN", *ORG_NAME, *PRODUCT_NAME) } diff --git a/src/lib.rs b/src/lib.rs index d446c4d..b16627b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ pub mod cache; pub use cache::Cache; pub mod ical; -pub mod settings; +pub mod config; pub mod utils; pub mod resource; diff --git a/src/settings.rs b/src/settings.rs deleted file mode 100644 index 47e8d56..0000000 --- a/src/settings.rs +++ /dev/null @@ -1,12 +0,0 @@ -// TODO: change these values with yours - -pub const URL: &str = "https://my.server.com/remote.php/dav/files/john"; -pub const USERNAME: &str = "username"; -pub const PASSWORD: &str = "secret_password"; - -pub const EXAMPLE_TASK_URL: &str = "https://my.server.com/remote.php/dav/calendars/john/6121A0BE-C2E0-4F16-A3FA-658E54E7062A/74439558-CDFF-426C-92CD-ECDDACE971B0.ics"; -pub const EXAMPLE_EXISTING_CALENDAR_URL: &str = "https://my.server.com/remote.php/dav/calendars/john/a_calendar_name/"; -pub const EXAMPLE_CREATED_CALENDAR_URL: &str = "https://my.server.com/remote.php/dav/calendars/john/a_calendar_that_we_have_created/"; - -pub const ORG_NAME: &str = "My organisation"; -pub const PRODUCT_NAME: &str = "My CalDAV client";