From 31328355b1c6a2b04b0d81ca0c2d6ecb0a66bea0 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 22 Nov 2017 06:25:34 +0200 Subject: [PATCH] Methods renaming, Api changes. --- hammond-data/src/feed.rs | 17 ++++++++++------- hammond-data/src/models/insertables.rs | 2 +- hammond-data/src/models/queryables.rs | 2 +- hammond-downloader/src/downloader.rs | 4 ++-- hammond-gtk/src/widgets/podcast.rs | 4 ++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/hammond-data/src/feed.rs b/hammond-data/src/feed.rs index 234dd4d..c4349e1 100644 --- a/hammond-data/src/feed.rs +++ b/hammond-data/src/feed.rs @@ -1,5 +1,5 @@ use rayon::prelude::*; -use diesel::Identifiable; +use diesel::{Identifiable, QueryResult}; use rss; use dbqueries; @@ -16,7 +16,7 @@ pub struct Feed { impl Feed { pub fn from_source(s: Source) -> Result { - s.refresh() + s.into_feed() } pub fn from_channel_source(chan: rss::Channel, s: Source) -> Feed { @@ -27,16 +27,19 @@ impl Feed { } fn index(&self) -> Result<()> { - let pd = self.index_channel()?; + let pd = self.get_podcast()?; self.index_channel_items(&pd)?; Ok(()) } - pub fn index_channel(&self) -> Result { - let pd = parser::new_podcast(&self.channel, *self.source.id()); - // Convert NewPodcast to Podcast - pd.into_podcast() + pub fn index_channel(&self) -> QueryResult<()> { + let new_pd = parser::new_podcast(&self.channel, *self.source.id()); + new_pd.index() + } + + pub fn get_podcast(&self) -> Result { + parser::new_podcast(&self.channel, *self.source.id()).into_podcast() } // TODO: Refactor transcactions and find a way to do it in parallel. diff --git a/hammond-data/src/models/insertables.rs b/hammond-data/src/models/insertables.rs index 8213471..68d3ebd 100644 --- a/hammond-data/src/models/insertables.rs +++ b/hammond-data/src/models/insertables.rs @@ -91,7 +91,7 @@ impl NewPodcast { Ok(dbqueries::get_podcast_from_title(&self.title)?) } - fn index(&self) -> QueryResult<()> { + pub fn index(&self) -> QueryResult<()> { let pd = dbqueries::get_podcast_from_title(&self.title); match pd { diff --git a/hammond-data/src/models/queryables.rs b/hammond-data/src/models/queryables.rs index 260f9fb..f896533 100644 --- a/hammond-data/src/models/queryables.rs +++ b/hammond-data/src/models/queryables.rs @@ -277,7 +277,7 @@ impl<'a> Source { self.save_changes::(&*tempdb) } - pub fn refresh(mut self) -> Result { + pub fn into_feed(mut self) -> Result { use reqwest::header::{ETag, EntityTag, Headers, HttpDate, LastModified}; let mut headers = Headers::new(); diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index 4028671..1d7034b 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -208,9 +208,9 @@ mod tests { fn test_cache_image() { let pd = Source::from_url("http://www.newrustacean.com/feed.xml") .unwrap() - .refresh() + .into_feed() .unwrap() - .index_channel() + .get_podcast() .unwrap(); let img_path = cache_image(&pd); diff --git a/hammond-gtk/src/widgets/podcast.rs b/hammond-gtk/src/widgets/podcast.rs index 3bdb995..0f5da0e 100644 --- a/hammond-gtk/src/widgets/podcast.rs +++ b/hammond-gtk/src/widgets/podcast.rs @@ -125,9 +125,9 @@ mod tests { fn test_get_pixbuf_from_path() { let pd = Source::from_url("http://www.newrustacean.com/feed.xml") .unwrap() - .refresh() + .into_feed() .unwrap() - .index_channel() + .get_podcast() .unwrap(); let pxbuf = get_pixbuf_from_path(&pd);