new version of STC. Finally update to reqwest and update all dependencies.

This commit is contained in:
Adrian Malacoda 2018-05-06 03:01:48 -05:00
parent 450cec8b48
commit c7235acdef
4 changed files with 27 additions and 41 deletions

View File

@ -1,21 +1,15 @@
[package] [package]
name="stc" name="stc"
version="0.0.1" version="0.0.2"
authors=["Adrian Malacoda <adrian.malacoda@monarch-pass.net>"] authors=["Adrian Malacoda <adrian.malacoda@monarch-pass.net>"]
[dependencies] [dependencies]
log = "0.3.6" log = "0.4.1"
env_logger = "0.4.0" env_logger = "0.5.10"
sqlite = "0.23.4" sqlite = "0.23.4"
select = "0.3.0" select = "0.4.2"
reqwest = "0.8.5"
# 26 February 2017: Would ideally like to use up-to-date libraries here serde_json = "1.0.17"
# 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"
retry = { git = "https://github.com/jimmycuadra/retry", rev = "3fa812e650d64ede61ea243fb83ef1a222ff0f84" } retry = { git = "https://github.com/jimmycuadra/retry", rev = "3fa812e650d64ede61ea243fb83ef1a222ff0f84" }
mopa = "0.2.2" mopa = "0.2.2"
linked-hash-map = "0.4.1" linked-hash-map = "0.5.1"

View File

@ -1,4 +1,4 @@
extern crate hyper; extern crate reqwest;
extern crate select; extern crate select;
extern crate serde_json; extern crate serde_json;
extern crate retry; extern crate retry;

View File

@ -1,9 +1,8 @@
use Link; use Link;
use searchers::Searcher; use searchers::Searcher;
use hyper; use reqwest;
use hyper::Client; use reqwest::StatusCode;
use hyper::status::StatusCode;
use select::document::Document; use select::document::Document;
use select::predicate::Name; use select::predicate::Name;
@ -42,14 +41,12 @@ impl Link for WikiPage {
} }
pub struct MediawikiSearcher { pub struct MediawikiSearcher {
client: Client,
baseurl: String baseurl: String
} }
impl MediawikiSearcher { impl MediawikiSearcher {
pub fn new (url: String) -> MediawikiSearcher { pub fn new (url: String) -> MediawikiSearcher {
MediawikiSearcher { MediawikiSearcher {
client: Client::new(),
baseurl: url baseurl: url
} }
} }
@ -58,10 +55,10 @@ impl MediawikiSearcher {
let mut contents = String::new(); let mut contents = String::new();
let api_url = &format!("{}{}", self.baseurl, name); let api_url = &format!("{}{}", self.baseurl, name);
let mut response = retry(Fixed::from_millis(RETRY_WAIT_MILLIS).take(NUM_RETRIES), || { 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 => { StatusCode::Ok => {
response.read_to_string(&mut contents)?; response.read_to_string(&mut contents)?;
Result::Ok(contents) Result::Ok(contents)
@ -74,7 +71,7 @@ impl MediawikiSearcher {
fn parse_entry (&self, page: String) -> Result<WikiPage, Error> { fn parse_entry (&self, page: String) -> Result<WikiPage, Error> {
let document = Document::from(&page[..]); 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(" ", "_")); let page_url = format!("{}{}", self.baseurl, page_name.replace(" ", "_"));
Result::Ok(WikiPage { Result::Ok(WikiPage {
@ -92,13 +89,13 @@ impl Searcher<WikiPage> for MediawikiSearcher {
#[derive(Debug)] #[derive(Debug)]
enum Error { enum Error {
Http(hyper::error::Error), Http(reqwest::Error),
Io(std::io::Error), Io(std::io::Error),
Other(String) Other(String)
} }
impl From<hyper::error::Error> for Error { impl From<reqwest::Error> for Error {
fn from (error: hyper::error::Error) -> Error { fn from (error: reqwest::Error) -> Error {
Error::Http(error) Error::Http(error)
} }
} }
@ -109,8 +106,8 @@ impl From<std::io::Error> for Error {
} }
} }
impl From<retry::Error<hyper::Error>> for Error { impl From<retry::Error<reqwest::Error>> for Error {
fn from (err: retry::Error<hyper::Error>) -> Error { fn from (err: retry::Error<reqwest::Error>) -> Error {
match err { match err {
retry::Error::Operation { error, total_delay, tries } => { retry::Error::Operation { error, total_delay, tries } => {
Error::Http(error) Error::Http(error)

View File

@ -1,8 +1,7 @@
use Link; use Link;
use searchers::Searcher; use searchers::Searcher;
use hyper; use reqwest;
use hyper::Client;
use serde_json; use serde_json;
use serde_json::Value; use serde_json::Value;
@ -48,22 +47,18 @@ impl Link for YugiohCard {
} }
} }
pub struct YugiohSearcher { pub struct YugiohSearcher {}
client: Client
}
impl YugiohSearcher { impl YugiohSearcher {
pub fn new () -> YugiohSearcher { pub fn new () -> YugiohSearcher {
YugiohSearcher { YugiohSearcher {}
client: Client::new()
}
} }
fn do_search (&self, name: &str) -> Result<String, Error> { fn do_search (&self, name: &str) -> Result<String, Error> {
let mut contents = String::new(); let mut contents = String::new();
let api_url = &format!("http://yugiohprices.com/api/card_data/{}", name); let api_url = &format!("http://yugiohprices.com/api/card_data/{}", name);
let mut response = retry(Fixed::from_millis(RETRY_WAIT_MILLIS).take(NUM_RETRIES), || { 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)?; response.read_to_string(&mut contents)?;
Result::Ok(contents) Result::Ok(contents)
@ -102,14 +97,14 @@ impl Searcher<YugiohCard> for YugiohSearcher {
#[derive(Debug)] #[derive(Debug)]
enum Error { enum Error {
Http(hyper::error::Error), Http(reqwest::Error),
Io(std::io::Error), Io(std::io::Error),
Json(serde_json::Error), Json(serde_json::Error),
Other(String) Other(String)
} }
impl From<hyper::error::Error> for Error { impl From<reqwest::Error> for Error {
fn from (error: hyper::error::Error) -> Error { fn from (error: reqwest::Error) -> Error {
Error::Http(error) Error::Http(error)
} }
} }
@ -126,8 +121,8 @@ impl From<serde_json::Error> for Error {
} }
} }
impl From<retry::Error<hyper::Error>> for Error { impl From<retry::Error<reqwest::Error>> for Error {
fn from (err: retry::Error<hyper::Error>) -> Error { fn from (err: retry::Error<reqwest::Error>) -> Error {
match err { match err {
retry::Error::Operation { error, total_delay, tries } => { retry::Error::Operation { error, total_delay, tries } => {
Error::Http(error) Error::Http(error)