diff --git a/hammond-data/src/models/queryables.rs b/hammond-data/src/models/queryables.rs index 5825a74..b659193 100644 --- a/hammond-data/src/models/queryables.rs +++ b/hammond-data/src/models/queryables.rs @@ -8,6 +8,12 @@ use reqwest::header::{ETag, LastModified}; use rss::Channel; use hyper; +// use futures::{future, Future, Stream}; +// use hyper::Client; +// use hyper::client::HttpConnector; +// use hyper::Method; +// use hyper::Uri; + use schema::{episode, podcast, source}; use feed::Feed; use errors::*; @@ -611,6 +617,14 @@ impl<'a> Source { self.http_etag = value.map(|x| x.to_string()); } + /// Helper method to easily save/"sync" current state of self to the Database. + pub fn save(&self) -> Result { + let db = connection(); + let tempdb = db.get()?; + + Ok(self.save_changes::(&*tempdb)?) + } + /// Extract Etag and LastModifier from req, and update self and the /// corresponding db row. fn update_etag(&mut self, req: &reqwest::Response) -> Result<()> { @@ -648,14 +662,6 @@ impl<'a> Source { Ok(()) } - /// Helper method to easily save/"sync" current state of self to the Database. - pub fn save(&self) -> Result { - let db = connection(); - let tempdb = db.get()?; - - Ok(self.save_changes::(&*tempdb)?) - } - /// `Feed` constructor. /// /// Fetches the latest xml Feed. diff --git a/hammond-data/src/pipeline.rs b/hammond-data/src/pipeline.rs index 8a26b10..e37897a 100644 --- a/hammond-data/src/pipeline.rs +++ b/hammond-data/src/pipeline.rs @@ -1,62 +1,48 @@ +use rss; + use hyper; -use std::io::{self, Write}; -use std::str::FromStr; -use futures::{Future, Stream}; use hyper::Client; use hyper::client::HttpConnector; use hyper::Method; use hyper::Uri; -use tokio_core::reactor::Core; use hyper_tls::HttpsConnector; -use rss; -// use errors::*; // use hyper::header::{ETag, LastModified}; +// use hyper::header::{ETag, LastModified}; + +use futures::{Future, Stream}; // use futures::future::join_all; +use tokio_core::reactor::Core; + +// use std::io::{self, Write}; +use std::str::FromStr; use Source; +// use errors::*; #[allow(dead_code)] -fn foo() { - let uri = "https://www.rust-lang.org/".parse().unwrap(); - let mut core = Core::new().unwrap(); - let handle = core.handle(); - let client = Client::configure() - .connector(HttpsConnector::new(4, &handle).unwrap()) - .build(&handle); - - let work = client.get(uri).and_then(|res| { - println!("Response: {}", res.status()); - - res.body() - .for_each(|chunk| io::stdout().write_all(&chunk).map_err(From::from)) - }); - - core.run(work).unwrap(); -} - -#[allow(dead_code)] -fn req_constructor( +fn request_constructor( + s: &Source, client: &mut Client>, - s: &mut Source, + ignore_etags: bool, ) -> Box> { use hyper::header::{EntityTag, HttpDate, IfModifiedSince, IfNoneMatch}; let uri = Uri::from_str(&s.uri()).unwrap(); let mut req = hyper::Request::new(Method::Get, uri); - // if !ignore_etags { - if let Some(foo) = s.http_etag() { - req.headers_mut().set(IfNoneMatch::Items(vec![ - EntityTag::new(true, foo.to_owned()), - ])); - } + if !ignore_etags { + if let Some(foo) = s.http_etag() { + req.headers_mut().set(IfNoneMatch::Items(vec![ + EntityTag::new(true, foo.to_owned()), + ])); + } - if let Some(foo) = s.last_modified() { - if let Ok(x) = foo.parse::() { - req.headers_mut().set(IfModifiedSince(x)); + if let Some(foo) = s.last_modified() { + if let Ok(x) = foo.parse::() { + req.headers_mut().set(IfModifiedSince(x)); + } } } - // } let work = client.request(req); Box::new(work) @@ -80,11 +66,7 @@ mod tests { use database::truncate_db; use Source; - - #[test] - fn test_foo() { - foo() - } + // use feed::Feed; #[test] fn test_bar() { @@ -98,15 +80,17 @@ mod tests { let url = "https://feeds.feedburner.com/InterceptedWithJeremyScahill"; let mut source = Source::from_url(url).unwrap(); - let channel = req_constructor(&mut client, &mut source) + let channel = request_constructor(&source, &mut client, false) .map(|res| { println!("Status: {}", res.status()); source.update_etag2(&res).unwrap(); res }) .and_then(|res| res_to_channel(res)); + // .map(|chan| Feed::from_channel_source(chan, source)); let chan = core.run(channel).unwrap(); + // let c = chan.wait().unwrap(); println!("{:?}", chan); }