diff --git a/Cargo.toml b/Cargo.toml index 1fd6b44..5eb3450 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,15 @@ [package] name="stc" -version="0.0.1" +version="0.0.2" authors=["Adrian Malacoda "] [dependencies] -log = "0.3.6" -env_logger = "0.4.0" +log = "0.4.1" +env_logger = "0.5.10" sqlite = "0.23.4" -select = "0.3.0" - -# 26 February 2017: Would ideally like to use up-to-date libraries here -# but this depends on openssl 0.9.7 which conflicts with the openssl 0.7.17 dependency -# used in tenquestionmarks (ultimately brought in by discord-rs which uses hyper 0.9). So, as a necessary evil, -# we need to keep to those versions as well to be compatible with tenquestionmarks. -#reqwest = "0.4.0" -hyper = "0.9.18" -serde_json = "0.9" +select = "0.4.2" +reqwest = "0.8.5" +serde_json = "1.0.17" retry = { git = "https://github.com/jimmycuadra/retry", rev = "3fa812e650d64ede61ea243fb83ef1a222ff0f84" } mopa = "0.2.2" -linked-hash-map = "0.4.1" +linked-hash-map = "0.5.1" diff --git a/src/lib.rs b/src/lib.rs index b264b60..37e1f83 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -extern crate hyper; +extern crate reqwest; extern crate select; extern crate serde_json; extern crate retry; diff --git a/src/searchers/mediawiki.rs b/src/searchers/mediawiki.rs index 095c0e1..b151b33 100644 --- a/src/searchers/mediawiki.rs +++ b/src/searchers/mediawiki.rs @@ -1,9 +1,8 @@ use Link; use searchers::Searcher; -use hyper; -use hyper::Client; -use hyper::status::StatusCode; +use reqwest; +use reqwest::StatusCode; use select::document::Document; use select::predicate::Name; @@ -42,14 +41,12 @@ impl Link for WikiPage { } pub struct MediawikiSearcher { - client: Client, baseurl: String } impl MediawikiSearcher { pub fn new (url: String) -> MediawikiSearcher { MediawikiSearcher { - client: Client::new(), baseurl: url } } @@ -58,10 +55,10 @@ impl MediawikiSearcher { let mut contents = String::new(); let api_url = &format!("{}{}", self.baseurl, name); let mut response = retry(Fixed::from_millis(RETRY_WAIT_MILLIS).take(NUM_RETRIES), || { - self.client.get(api_url).send() + reqwest::get(api_url) })?; - match response.status { + match response.status() { StatusCode::Ok => { response.read_to_string(&mut contents)?; Result::Ok(contents) @@ -74,7 +71,7 @@ impl MediawikiSearcher { fn parse_entry (&self, page: String) -> Result { let document = Document::from(&page[..]); - let page_name = String::from(document.find(Name("h1")).iter().next().expect("expected h1").text()); + let page_name = String::from(document.find(Name("h1")).into_iter().next().expect("expected h1").text()); let page_url = format!("{}{}", self.baseurl, page_name.replace(" ", "_")); Result::Ok(WikiPage { @@ -92,13 +89,13 @@ impl Searcher for MediawikiSearcher { #[derive(Debug)] enum Error { - Http(hyper::error::Error), + Http(reqwest::Error), Io(std::io::Error), Other(String) } -impl From for Error { - fn from (error: hyper::error::Error) -> Error { +impl From for Error { + fn from (error: reqwest::Error) -> Error { Error::Http(error) } } @@ -109,8 +106,8 @@ impl From for Error { } } -impl From> for Error { - fn from (err: retry::Error) -> Error { +impl From> for Error { + fn from (err: retry::Error) -> Error { match err { retry::Error::Operation { error, total_delay, tries } => { Error::Http(error) diff --git a/src/searchers/yugioh.rs b/src/searchers/yugioh.rs index 852dd25..8404469 100644 --- a/src/searchers/yugioh.rs +++ b/src/searchers/yugioh.rs @@ -1,8 +1,7 @@ use Link; use searchers::Searcher; -use hyper; -use hyper::Client; +use reqwest; use serde_json; use serde_json::Value; @@ -48,22 +47,18 @@ impl Link for YugiohCard { } } -pub struct YugiohSearcher { - client: Client -} +pub struct YugiohSearcher {} impl YugiohSearcher { pub fn new () -> YugiohSearcher { - YugiohSearcher { - client: Client::new() - } + YugiohSearcher {} } fn do_search (&self, name: &str) -> Result { let mut contents = String::new(); let api_url = &format!("http://yugiohprices.com/api/card_data/{}", name); let mut response = retry(Fixed::from_millis(RETRY_WAIT_MILLIS).take(NUM_RETRIES), || { - self.client.get(api_url).send() + reqwest::get(api_url) })?; response.read_to_string(&mut contents)?; Result::Ok(contents) @@ -102,14 +97,14 @@ impl Searcher for YugiohSearcher { #[derive(Debug)] enum Error { - Http(hyper::error::Error), + Http(reqwest::Error), Io(std::io::Error), Json(serde_json::Error), Other(String) } -impl From for Error { - fn from (error: hyper::error::Error) -> Error { +impl From for Error { + fn from (error: reqwest::Error) -> Error { Error::Http(error) } } @@ -126,8 +121,8 @@ impl From for Error { } } -impl From> for Error { - fn from (err: retry::Error) -> Error { +impl From> for Error { + fn from (err: retry::Error) -> Error { match err { retry::Error::Operation { error, total_delay, tries } => { Error::Http(error)