fix build
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nyyu 2020-06-28 18:34:31 +02:00
parent 8c6016acc8
commit 8f9f68d2f1
7 changed files with 62 additions and 24 deletions

30
Cargo.lock generated
View File

@ -205,6 +205,11 @@ name = "futures-core"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "futures-io"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "futures-sink"
version = "0.3.5"
@ -214,6 +219,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "futures-task"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "futures-util"
@ -221,9 +229,12 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures-io 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"pin-project 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)",
"pin-utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -546,6 +557,20 @@ dependencies = [
"autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "once_cell"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "openssl"
version = "0.10.30"
@ -883,6 +908,7 @@ dependencies = [
"percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pin-project-lite 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-tls 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1141,6 +1167,7 @@ dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pin-project-lite 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1396,6 +1423,7 @@ dependencies = [
"checksum futf 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7c9c1ce3fa9336301af935ab852c437817d14cd33690446569392e65170aac3b"
"checksum futures-channel 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5"
"checksum futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399"
"checksum futures-io 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789"
"checksum futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc"
"checksum futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626"
"checksum futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6"
@ -1432,6 +1460,8 @@ dependencies = [
"checksum new_debug_unreachable 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
"checksum num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
"checksum num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
"checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
"checksum once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
"checksum openssl 0.10.30 (registry+https://github.com/rust-lang/crates.io-index)" = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4"
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
"checksum openssl-sys 0.9.58 (registry+https://github.com/rust-lang/crates.io-index)" = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de"

View File

@ -10,9 +10,11 @@ simple_logger = "1.6"
serde = "1.0"
serde_derive = "1.0"
serde_json = { version = "1.0", features = ["preserve_order"] }
reqwest = "0.10"
reqwest = { version = "0.10", features = ["blocking", "json"] }
select = "0.4"
regex = "1.3"
lazy_static = "1.4"
winreg = "0.7"
indexmap = { version = "1.4", features = ["serde-1"] }
[target.'cfg(windows)'.dependencies]
winreg = "0.7"

View File

@ -65,7 +65,7 @@ impl DataSource for CGGDataSource {
fn get_champs_with_positions_and_patch(
&self,
client: &reqwest::Client,
client: &reqwest::blocking::Client,
) -> (IndexMap<String, Vec<String>>, String) {
let page = client
.get("https://champion.gg")
@ -118,9 +118,9 @@ impl DataSource for CGGDataSource {
&self,
id: &str,
position: &str,
client: &reqwest::Client,
client: &reqwest::blocking::Client,
) -> Option<(Vec<Value>, f64)> {
let mut req = client
let req = client
.get(&format!(
"https://champion.gg/champion/{}/{}?league=",
id, position

View File

@ -35,14 +35,14 @@ pub trait DataSource {
fn get_champs_with_positions_and_patch(
&self,
client: &reqwest::Client,
client: &reqwest::blocking::Client,
) -> (IndexMap<String, Vec<String>>, String);
fn get_champ_data_with_win_pourcentage(
&self,
id: &str,
position: &str,
client: &reqwest::Client,
client: &reqwest::blocking::Client,
) -> Option<(Vec<Value>, f64)>;
fn write_item_set(
@ -52,7 +52,7 @@ pub trait DataSource {
pos: &str,
ver: &str,
path: &PathBuf,
client: &reqwest::Client,
client: &reqwest::blocking::Client,
) {
info!("Retrieving data for {} at {}", name, pos);
let data = self.get_champ_data_with_win_pourcentage(id, pos, client);

View File

@ -3,7 +3,6 @@ use indexmap::IndexMap;
use regex::Regex;
use serde_derive::Deserialize;
use serde_json::{json, Value};
use std::time::Duration;
pub struct KBDataSource {
token: Option<String>,
@ -89,7 +88,7 @@ struct Summoner {
}
impl KBDataSource {
pub fn new(client: &reqwest::Client) -> KBDataSource {
pub fn new(client: &reqwest::blocking::Client) -> KBDataSource {
let mut datasource = KBDataSource {
token: None,
internal_classname_mapping: IndexMap::new(),
@ -100,9 +99,9 @@ impl KBDataSource {
}
// It will be better to use Result...
fn get_auth_token(&self, client: &reqwest::Client) -> Option<String> {
fn get_auth_token(&self, client: &reqwest::blocking::Client) -> Option<String> {
let bundle = match client.get("https://koreanbuilds.net/bundle.js").send() {
Ok(mut resp) => match resp.text() {
Ok(resp) => match resp.text() {
Ok(val) => val,
Err(_) => return None,
},
@ -122,7 +121,7 @@ impl KBDataSource {
};
}
fn get_classname_mapping(&self, client: &reqwest::Client) -> IndexMap<String, String> {
fn get_classname_mapping(&self, client: &reqwest::blocking::Client) -> IndexMap<String, String> {
let mut mapping = IndexMap::new();
match self.get_champion_response(client) {
Some(data) => {
@ -135,7 +134,7 @@ impl KBDataSource {
mapping
}
fn get_champion_response(&self, client: &reqwest::Client) -> Option<ChampionResponse> {
fn get_champion_response(&self, client: &reqwest::blocking::Client) -> Option<ChampionResponse> {
let token = match self.token.clone() {
Some(t) => t,
None => return None,
@ -146,7 +145,7 @@ impl KBDataSource {
.header("Authorization", token)
.send()
{
Ok(mut resp) => match resp.json() {
Ok(resp) => match resp.json() {
Ok(val) => return val,
Err(_) => return None,
},
@ -187,7 +186,7 @@ impl DataSource for KBDataSource {
fn get_champs_with_positions_and_patch(
&self,
client: &reqwest::Client,
client: &reqwest::blocking::Client,
) -> (IndexMap<String, Vec<String>>, String) {
let mut champions = IndexMap::new();
let data: ChampionResponse = match self.get_champion_response(client) {
@ -210,7 +209,7 @@ impl DataSource for KBDataSource {
&self,
id: &str,
position: &str,
client: &reqwest::Client,
client: &reqwest::blocking::Client,
) -> Option<(Vec<Value>, f64)> {
let token = match self.token.clone() {
Some(t) => t,
@ -229,7 +228,7 @@ impl DataSource for KBDataSource {
.header("Authorization", token)
.send()
{
Ok(mut resp) => match resp.json() {
Ok(resp) => match resp.json() {
Ok(val) => val,
Err(_) => {
return None;
@ -350,7 +349,7 @@ mod tests {
token: None,
internal_classname_mapping: IndexMap::new(),
};
let client = reqwest::Client::builder()
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(10))
.build()
.unwrap();
@ -362,7 +361,7 @@ mod tests {
#[test]
fn test_get_champs_with_positions_and_patch() {
let client = reqwest::Client::builder()
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(10))
.build()
.unwrap();
@ -374,7 +373,7 @@ mod tests {
#[test]
fn test_get_champ_data_with_win_pourcentage() {
let client = reqwest::Client::builder()
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(10))
.build()
.unwrap();

View File

@ -7,6 +7,7 @@ use std::io::{Error, ErrorKind};
use std::path::PathBuf;
use std::{fs, thread, time};
use time::Duration;
#[cfg(target_os = "windows")]
use winreg::RegKey;
mod cgg_data_source;
@ -55,7 +56,7 @@ fn main() {
header::HeaderValue::from_static(USER_AGENT),
);
let client = reqwest::Client::builder()
let client = reqwest::blocking::Client::builder()
.default_headers(headers)
.timeout(Duration::from_secs(10))
.build()
@ -118,6 +119,7 @@ fn main() {
}
}
#[cfg(target_os = "windows")]
fn lol_champ_dir() -> Result<PathBuf, Error> {
let hklm = RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE);
let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games\RADS");
@ -150,3 +152,8 @@ fn lol_champ_dir() -> Result<PathBuf, Error> {
}
Ok(path.join("Config").join("Champions"))
}
#[cfg(not(target_os = "windows"))]
fn lol_champ_dir() -> Result<PathBuf, Error> {
Ok(PathBuf::from("./champs"))
}

View File

@ -11,7 +11,7 @@ impl DataSource for PBDataSource {
fn get_champs_with_positions_and_patch(
&self,
_client: &reqwest::Client,
_client: &reqwest::blocking::Client,
) -> (IndexMap<String, Vec<String>>, String) {
(IndexMap::new(), String::new())
}
@ -20,7 +20,7 @@ impl DataSource for PBDataSource {
&self,
_id: &str,
_position: &str,
_client: &reqwest::Client,
_client: &reqwest::blocking::Client,
) -> Option<(Vec<Value>, f64)> {
None
}