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:
Kiana Sheibani 2023-09-02 01:35:36 -04:00
parent fa96725968
commit badcec976a
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
4 changed files with 385 additions and 998 deletions

1355
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -8,12 +8,16 @@ name = "ggelo"
path = "src/main.rs"
[dependencies]
# GraphQL schema
schema.path = "../schema"
cynic = { version = "3.2", features = ["http-surf"] }
surf = "2"
dirs = "5.0"
futures = "0.3"
# API access
cynic = { version = "3.2", features = ["http-reqwest-blocking"] }
reqwest = "0.11"
serde = "1.0"
# Local file manipulation
dirs = "5.0"
sqlite = "0.31"
[build-dependencies]

View file

@ -1,7 +1,5 @@
#![feature(iterator_try_collect)]
use futures::executor::block_on;
use std::io::{self, Write};
use std::path::Path;
mod queries;
@ -36,7 +34,7 @@ fn main() {
config_dir.push("ggelo");
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 {
last_query: None,
game_id: VideogameId(1386),
@ -44,7 +42,7 @@ fn main() {
state: Some("GA"),
},
&auth_key,
)) {
) {
println!("Succeeded");
for tournament in response {
println!("Tournament: {}", tournament.name);

View file

@ -36,7 +36,7 @@ pub trait QueryUnwrap<Vars>: 'static + QueryBuilder<Vars> {
}
// Generic function for running start.gg queries
pub async fn run_query<Builder, Vars>(
pub fn run_query<Builder, Vars>(
vars: Builder::VarsUnwrapped,
auth: &str,
) -> Option<Builder::Unwrapped>
@ -45,14 +45,14 @@ where
Vars: Serialize,
for<'de> Builder: Deserialize<'de>,
{
use cynic::http::SurfExt;
use cynic::http::ReqwestBlockingExt;
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)
.run_graphql(query)
.await;
.run_graphql(query);
Builder::unwrap_response(response.unwrap())
}