Write TournamentSets query test code
This commit is contained in:
parent
53cde72ede
commit
fa96725968
|
@ -6,7 +6,6 @@ use std::path::Path;
|
||||||
|
|
||||||
mod queries;
|
mod queries;
|
||||||
use queries::*;
|
use queries::*;
|
||||||
use search_games::{VideogameSearch, VideogameSearchVars};
|
|
||||||
|
|
||||||
mod datasets;
|
mod datasets;
|
||||||
|
|
||||||
|
@ -20,9 +19,14 @@ fn get_auth_key(config_dir: &Path) -> Option<String> {
|
||||||
Err(VarError::NotPresent) => {
|
Err(VarError::NotPresent) => {
|
||||||
let mut auth_file = config_dir.to_owned();
|
let mut auth_file = config_dir.to_owned();
|
||||||
auth_file.push("auth.txt");
|
auth_file.push("auth.txt");
|
||||||
read_to_string(auth_file)
|
read_to_string(auth_file).ok().and_then(|s| {
|
||||||
.ok()
|
let trimmed = s.trim();
|
||||||
.and_then(|s| s.split_whitespace().next().map(String::from))
|
if trimmed.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(trimmed.to_owned())
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,22 +36,30 @@ fn main() {
|
||||||
config_dir.push("ggelo");
|
config_dir.push("ggelo");
|
||||||
let auth_key = get_auth_key(&config_dir).expect("Could not find authorization key");
|
let auth_key = get_auth_key(&config_dir).expect("Could not find authorization key");
|
||||||
|
|
||||||
// Get search prompt
|
if let Some(response) = block_on(run_query::<TournamentSets, _>(
|
||||||
let mut search = String::new();
|
TournamentSetsVars {
|
||||||
print!("Search for game: ");
|
last_query: None,
|
||||||
let _ = io::stdout().flush();
|
game_id: VideogameId(1386),
|
||||||
io::stdin()
|
country: None,
|
||||||
.read_line(&mut search)
|
state: Some("GA"),
|
||||||
.expect("Error reading from stdin");
|
},
|
||||||
|
|
||||||
if let Some(response) = block_on(run_query::<VideogameSearch, _>(
|
|
||||||
VideogameSearchVars { name: &search },
|
|
||||||
&auth_key,
|
&auth_key,
|
||||||
)) {
|
)) {
|
||||||
for game in response.into_iter() {
|
println!("Succeeded");
|
||||||
println!("{} - {}", game.id.0, game.name);
|
for tournament in response {
|
||||||
|
println!("Tournament: {}", tournament.name);
|
||||||
|
for set in tournament.sets {
|
||||||
|
println!(
|
||||||
|
"Winner: {}",
|
||||||
|
if set.winner {
|
||||||
|
set.player2.0
|
||||||
|
} else {
|
||||||
|
set.player1.0
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("No response");
|
println!("Invalid GraphQL response");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ use cynic::{GraphQlResponse, QueryBuilder};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod search_games;
|
pub mod search_games;
|
||||||
|
pub use search_games::*;
|
||||||
pub mod tournament_sets;
|
pub mod tournament_sets;
|
||||||
|
pub use tournament_sets::*;
|
||||||
|
|
||||||
use schema::schema;
|
use schema::schema;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue