Switch from surf to reqwest-blocking
Reqwest seems to be more popular, and a non-async API would simplify the code without losing too much.
This commit is contained in:
parent
fa96725968
commit
badcec976a
1355
Cargo.lock
generated
1355
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -8,12 +8,16 @@ name = "ggelo"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
# GraphQL schema
|
||||||
schema.path = "../schema"
|
schema.path = "../schema"
|
||||||
cynic = { version = "3.2", features = ["http-surf"] }
|
|
||||||
surf = "2"
|
# API access
|
||||||
dirs = "5.0"
|
cynic = { version = "3.2", features = ["http-reqwest-blocking"] }
|
||||||
futures = "0.3"
|
reqwest = "0.11"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
|
|
||||||
|
# Local file manipulation
|
||||||
|
dirs = "5.0"
|
||||||
sqlite = "0.31"
|
sqlite = "0.31"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#![feature(iterator_try_collect)]
|
#![feature(iterator_try_collect)]
|
||||||
|
|
||||||
use futures::executor::block_on;
|
|
||||||
use std::io::{self, Write};
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
mod queries;
|
mod queries;
|
||||||
|
@ -36,7 +34,7 @@ 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");
|
||||||
|
|
||||||
if let Some(response) = block_on(run_query::<TournamentSets, _>(
|
if let Some(response) = run_query::<TournamentSets, _>(
|
||||||
TournamentSetsVars {
|
TournamentSetsVars {
|
||||||
last_query: None,
|
last_query: None,
|
||||||
game_id: VideogameId(1386),
|
game_id: VideogameId(1386),
|
||||||
|
@ -44,7 +42,7 @@ fn main() {
|
||||||
state: Some("GA"),
|
state: Some("GA"),
|
||||||
},
|
},
|
||||||
&auth_key,
|
&auth_key,
|
||||||
)) {
|
) {
|
||||||
println!("Succeeded");
|
println!("Succeeded");
|
||||||
for tournament in response {
|
for tournament in response {
|
||||||
println!("Tournament: {}", tournament.name);
|
println!("Tournament: {}", tournament.name);
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub trait QueryUnwrap<Vars>: 'static + QueryBuilder<Vars> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic function for running start.gg queries
|
// Generic function for running start.gg queries
|
||||||
pub async fn run_query<Builder, Vars>(
|
pub fn run_query<Builder, Vars>(
|
||||||
vars: Builder::VarsUnwrapped,
|
vars: Builder::VarsUnwrapped,
|
||||||
auth: &str,
|
auth: &str,
|
||||||
) -> Option<Builder::Unwrapped>
|
) -> Option<Builder::Unwrapped>
|
||||||
|
@ -45,14 +45,14 @@ where
|
||||||
Vars: Serialize,
|
Vars: Serialize,
|
||||||
for<'de> Builder: Deserialize<'de>,
|
for<'de> Builder: Deserialize<'de>,
|
||||||
{
|
{
|
||||||
use cynic::http::SurfExt;
|
use cynic::http::ReqwestBlockingExt;
|
||||||
|
|
||||||
let query = Builder::build(Builder::wrap_vars(vars));
|
let query = Builder::build(Builder::wrap_vars(vars));
|
||||||
|
|
||||||
let response = surf::post("https://api.start.gg/gql/alpha")
|
let response = reqwest::blocking::Client::new()
|
||||||
|
.post("https://api.start.gg/gql/alpha")
|
||||||
.header("Authorization", String::from("Bearer ") + auth)
|
.header("Authorization", String::from("Bearer ") + auth)
|
||||||
.run_graphql(query)
|
.run_graphql(query);
|
||||||
.await;
|
|
||||||
|
|
||||||
Builder::unwrap_response(response.unwrap())
|
Builder::unwrap_response(response.unwrap())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue