diff --git a/src/feed/mod.rs b/src/feed/mod.rs index 8b43067..f06df54 100644 --- a/src/feed/mod.rs +++ b/src/feed/mod.rs @@ -8,5 +8,10 @@ pub use get::get; type Feed = atom_syndication::Feed; +pub struct FeedEnv { + pub find: FeedFind, + pub get: FeedGet, +} + pub type FeedFind = fn(&str, &str) -> Result; pub type FeedGet = fn(&str) -> Result; diff --git a/src/fetch.rs b/src/fetch.rs index 1f95f96..d7f836e 100644 --- a/src/fetch.rs +++ b/src/fetch.rs @@ -3,6 +3,10 @@ use crate::prelude::*; use atom_syndication::Link; use std::process::Command; +pub struct FetchEnv { + pub download: FetchDownload, +} + pub type FetchDownload = fn(&Link) -> Result<()>; pub fn download(link: &Link) -> Result<()> { diff --git a/src/history/mod.rs b/src/history/mod.rs index e36428d..d6f7255 100644 --- a/src/history/mod.rs +++ b/src/history/mod.rs @@ -8,5 +8,10 @@ pub use find::find; type Link = atom_syndication::Link; +pub struct HistoryEnv { + pub find: HistoryFind, + pub add: HistoryAdd, +} + pub type HistoryFind = fn(&Link, &str) -> Result; pub type HistoryAdd = fn(&Link, &str) -> Result<()>; diff --git a/src/lib.rs b/src/lib.rs index ee239ca..ecaae86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,30 +5,27 @@ pub mod history; pub mod prelude; mod subscriptions; -use feed::{FeedFind, FeedGet}; -use fetch::FetchDownload; -use history::{HistoryAdd, HistoryFind}; +use feed::FeedEnv; +use fetch::FetchEnv; +use history::HistoryEnv; use prelude::*; -pub fn run( - subscriptions: &str, - history: &str, - site: &str, - feed_find: FeedFind, - feed_get: FeedGet, - history_find: HistoryFind, - history_add: HistoryAdd, - fetch_download: FetchDownload, -) -> Result<()> { +pub struct Env { + pub feed: FeedEnv, + pub history: HistoryEnv, + pub fetch: FetchEnv, +} + +pub fn run(subscriptions: &str, history: &str, site: &str, e: Env) -> Result<()> { for channel_name in subscriptions::lines_from(subscriptions)? { println!("Channel: {}", channel_name); - let feed_url = feed_find(site, &channel_name)?; - for entry in feed_get(&feed_url)?.entries() { + let feed_url = (e.feed.find)(site, &channel_name)?; + for entry in (e.feed.get)(&feed_url)?.entries() { if let Some(link) = entry.links().get(0).cloned() { - if !history_find(&link, history)? { + if !(e.history.find)(&link, history)? { println!("Downloading {}: {}", &channel_name, entry.title().as_str()); - fetch_download(&link)?; - history_add(&link, history)?; + (e.fetch.download)(&link)?; + (e.history.add)(&link, history)?; } } } diff --git a/src/main.rs b/src/main.rs index 3e4a741..41e7d98 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ use podal::prelude::*; +use podal::{feed::FeedEnv, fetch::FetchEnv, history::HistoryEnv}; + fn main() -> Result<()> { println!("Podal"); let subscriptions = "subscriptions.txt"; @@ -10,11 +12,20 @@ fn main() -> Result<()> { subscriptions, history, site, - podal::feed::find, - podal::feed::get, - podal::history::find, - podal::history::add, - podal::fetch::download, + podal::Env { + feed: FeedEnv { + find: podal::feed::find, + get: podal::feed::get, + }, + + history: HistoryEnv { + find: podal::history::find, + add: podal::history::add, + }, + fetch: FetchEnv { + download: podal::fetch::download, + }, + }, )?; println!("Done");