new version of STC. Finally update to reqwest and update all dependencies.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
extern crate hyper;
|
||||
extern crate reqwest;
|
||||
extern crate select;
|
||||
extern crate serde_json;
|
||||
extern crate retry;
|
||||
|
@@ -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<WikiPage, Error> {
|
||||
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<WikiPage> for MediawikiSearcher {
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Error {
|
||||
Http(hyper::error::Error),
|
||||
Http(reqwest::Error),
|
||||
Io(std::io::Error),
|
||||
Other(String)
|
||||
}
|
||||
|
||||
impl From<hyper::error::Error> for Error {
|
||||
fn from (error: hyper::error::Error) -> Error {
|
||||
impl From<reqwest::Error> for Error {
|
||||
fn from (error: reqwest::Error) -> Error {
|
||||
Error::Http(error)
|
||||
}
|
||||
}
|
||||
@@ -109,8 +106,8 @@ impl From<std::io::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<retry::Error<hyper::Error>> for Error {
|
||||
fn from (err: retry::Error<hyper::Error>) -> Error {
|
||||
impl From<retry::Error<reqwest::Error>> for Error {
|
||||
fn from (err: retry::Error<reqwest::Error>) -> Error {
|
||||
match err {
|
||||
retry::Error::Operation { error, total_delay, tries } => {
|
||||
Error::Http(error)
|
||||
|
@@ -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<String, Error> {
|
||||
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<YugiohCard> 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<hyper::error::Error> for Error {
|
||||
fn from (error: hyper::error::Error) -> Error {
|
||||
impl From<reqwest::Error> for Error {
|
||||
fn from (error: reqwest::Error) -> Error {
|
||||
Error::Http(error)
|
||||
}
|
||||
}
|
||||
@@ -126,8 +121,8 @@ impl From<serde_json::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<retry::Error<hyper::Error>> for Error {
|
||||
fn from (err: retry::Error<hyper::Error>) -> Error {
|
||||
impl From<retry::Error<reqwest::Error>> for Error {
|
||||
fn from (err: retry::Error<reqwest::Error>) -> Error {
|
||||
match err {
|
||||
retry::Error::Operation { error, total_delay, tries } => {
|
||||
Error::Http(error)
|
||||
|
Reference in New Issue
Block a user