new version of STC. Finally update to reqwest and update all dependencies.
This commit is contained in:
parent
450cec8b48
commit
c7235acdef
20
Cargo.toml
20
Cargo.toml
@ -1,21 +1,15 @@
|
||||
[package]
|
||||
name="stc"
|
||||
version="0.0.1"
|
||||
version="0.0.2"
|
||||
authors=["Adrian Malacoda <adrian.malacoda@monarch-pass.net>"]
|
||||
|
||||
[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"
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user