diff --git a/src/cgg_data_source.rs b/src/cgg_data_source.rs index 74dadb4..2ef853b 100644 --- a/src/cgg_data_source.rs +++ b/src/cgg_data_source.rs @@ -70,7 +70,7 @@ impl DataSource for CGGDataSource { (champions, patch) } - fn get_champ_data(id: &str, position: &str, client: &reqwest::Client) -> Option { + fn get_champ_data(&self, id: &str, position: &str, client: &reqwest::Client) -> Option { let mut req = client .get(&format!( "https://champion.gg/champion/{}/{}?league=", diff --git a/src/data_source.rs b/src/data_source.rs index 149c969..78a14d5 100644 --- a/src/data_source.rs +++ b/src/data_source.rs @@ -43,16 +43,22 @@ pub trait DataSource { &self, client: &reqwest::Client, ) -> (IndexMap>, String); - fn get_champ_data(id: &str, position: &str, client: &reqwest::Client) -> Option; + fn get_champ_data(&self, id: &str, position: &str, client: &reqwest::Client) -> Option; - fn make_item_set(data: &Value, label: &str) -> Value { + fn make_item_set(&self, data: &Value, label: &str) -> Value { json!({ "items": data["items"].as_array().unwrap().iter().map(|x| json!({"id": x["id"].as_str(), "count": 1})).collect::>(), "type": format!("{} ({:.2}% - {} games)", label, data["winPercent"].as_f64().unwrap() * 100., data["games"].as_u64().unwrap()) }) } - fn make_item_set_from_list(list: &Vec, label: &str, key: &str, data: &Value) -> Value { + fn make_item_set_from_list( + &self, + list: &Vec, + label: &str, + key: &str, + data: &Value, + ) -> Value { let mut key_order = String::new(); if !data["skills"].get("skillInfo").is_none() { key_order = data["skills"][key]["order"] @@ -83,7 +89,7 @@ pub trait DataSource { client: &reqwest::Client, ) { info!("Retrieving data for {} at {}", name, pos); - let data = Self::get_champ_data(id, pos, client); + let data = self.get_champ_data(id, pos, client); match data { Some(data) => { @@ -106,17 +112,17 @@ pub trait DataSource { if !data[&path[0]].get(&path[1]).is_none() { item_set .blocks - .push(Self::make_item_set(&data[&path[0]][&path[1]], label)); + .push(self.make_item_set(&data[&path[0]][&path[1]], label)); } } - item_set.blocks.push(Self::make_item_set_from_list( + item_set.blocks.push(self.make_item_set_from_list( &CONSUMABLES.to_vec(), "Consumables | Frequent:", "mostGames", &data, )); - item_set.blocks.push(Self::make_item_set_from_list( + item_set.blocks.push(self.make_item_set_from_list( &TRINKETS.to_vec(), "Trinkets | Wins:", "highestWinPercent", diff --git a/src/main.rs b/src/main.rs index 652b615..0ffc21b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,10 +16,12 @@ extern crate winreg; mod cgg_data_source; mod data_source; +mod pb_data_source; use cgg_data_source::CGGDataSource; use data_source::DataSource; use indexmap::IndexMap; +use pb_data_source::PBDataSource; use reqwest::header::{Headers, UserAgent}; use std::io::{Error, ErrorKind}; use std::path::PathBuf; @@ -85,7 +87,7 @@ fn main() { .unwrap(); info!("LoL numbers of champs: {}", champion.data.len()); - let data_sources = [CGGDataSource]; + let data_sources: [Box; 2] = [Box::new(PBDataSource), Box::new(CGGDataSource)]; for data_source in data_sources.iter() { let (champs, patch) = data_source.get_champs_with_positions_and_patch(&client); diff --git a/src/pb_data_source.rs b/src/pb_data_source.rs new file mode 100644 index 0000000..0b6a32c --- /dev/null +++ b/src/pb_data_source.rs @@ -0,0 +1,34 @@ +extern crate indexmap; +extern crate lazy_static; +extern crate log; +extern crate regex; +extern crate reqwest; +extern crate select; +extern crate serde; +extern crate serde_json; +extern crate simple_logger; +extern crate winreg; + +use indexmap::IndexMap; +use serde_json::Value; + +use data_source::DataSource; + +pub struct PBDataSource; +impl DataSource for PBDataSource { + fn get_champs_with_positions_and_patch( + &self, + _client: &reqwest::Client, + ) -> (IndexMap>, String) { + (IndexMap::new(), String::new()) + } + + fn get_champ_data( + &self, + _id: &str, + _position: &str, + _client: &reqwest::Client, + ) -> Option { + None + } +}