diff options
Diffstat (limited to 'src/manager.rs')
-rw-r--r-- | src/manager.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/manager.rs b/src/manager.rs index 34e19be..5330d80 100644 --- a/src/manager.rs +++ b/src/manager.rs | |||
@@ -13,7 +13,7 @@ pub struct Manager { | |||
13 | } | 13 | } |
14 | 14 | ||
15 | impl Manager { | 15 | impl Manager { |
16 | pub async fn add_feed(&mut self, url: &str) -> Result<PullStatus, Error> { | 16 | fn add_feed(&mut self, url: &str) -> Result<&mut Feed, Error> { |
17 | let link = Url::parse(&url).map_err(|e| AddError::InvalidUrl(e.to_string()))?; | 17 | let link = Url::parse(&url).map_err(|e| AddError::InvalidUrl(e.to_string()))?; |
18 | 18 | ||
19 | // check if this feed is already present | 19 | // check if this feed is already present |
@@ -22,17 +22,24 @@ impl Manager { | |||
22 | } | 22 | } |
23 | 23 | ||
24 | // construct a new feed | 24 | // construct a new feed |
25 | let mut feed = Feed::new(link.clone()); | 25 | let feed = Feed::new(link.clone()); |
26 | |||
27 | let status = feed | ||
28 | .pull() | ||
29 | .await | ||
30 | .map_err(|pull_err| Error::Pull(link, pull_err))?; | ||
31 | 26 | ||
32 | // add new feed | 27 | // add new feed |
33 | self.feeds.push(feed); | 28 | self.feeds.push(feed); |
34 | 29 | ||
35 | Ok(status) | 30 | Ok(self.feeds.last_mut().unwrap()) |
31 | } | ||
32 | |||
33 | pub async fn add_feed_and_pull(&mut self, url: &str) -> Result<PullStatus, Error> { | ||
34 | let feed = self.add_feed(url)?; | ||
35 | feed.pull() | ||
36 | .await | ||
37 | .map_err(|pull_err| Error::Pull(feed.link.clone(), pull_err)) | ||
38 | } | ||
39 | |||
40 | pub async fn add_feeds_and_pull(&mut self, urls: &[&str]) -> Vec<Result<PullStatus, Error>> { | ||
41 | let add_results = urls.into_iter().map(|url| self.add_feed(&url)); | ||
42 | self.pull() | ||
36 | } | 43 | } |
37 | 44 | ||
38 | pub async fn pull(&mut self) -> Vec<Result<PullStatus, PullError>> { | 45 | pub async fn pull(&mut self) -> Vec<Result<PullStatus, PullError>> { |
@@ -71,6 +78,8 @@ impl Manager { | |||
71 | } | 78 | } |
72 | } | 79 | } |
73 | 80 | ||
81 | // an iterator over a combined list of feeds (assumes each feed is already a sorted list of | ||
82 | // entries) | ||
74 | struct EntryIterator<'e> { | 83 | struct EntryIterator<'e> { |
75 | all_entries: Vec<&'e [Entry]>, | 84 | all_entries: Vec<&'e [Entry]>, |
76 | } | 85 | } |