From a2e1f25519515370890712b03b2fc4815bcd44eb Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Fri, 10 Feb 2023 10:11:13 +0200 Subject: [PATCH] feat(sdbclient): join game api --- sdbclient/src/api/game/join.rs | 34 ++++++++++++++++++++++++++++++++++ sdbclient/src/api/game/mod.rs | 3 +++ 2 files changed, 37 insertions(+) create mode 100644 sdbclient/src/api/game/join.rs diff --git a/sdbclient/src/api/game/join.rs b/sdbclient/src/api/game/join.rs new file mode 100644 index 0000000..37baae8 --- /dev/null +++ b/sdbclient/src/api/game/join.rs @@ -0,0 +1,34 @@ +/* + * This file is part of sdbclient + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use reqwest; +use serde::{Deserialize, Serialize}; + +use super::APIErrorWrapper; + +#[derive(Debug, Serialize, Deserialize)] +pub struct ResultJoinGame {} + +#[derive(Debug, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ResponseJoinGame { + Error(APIErrorWrapper), + Valid(ResultJoinGame), +} + +pub fn join(api_address: String, token: String, game_id: String) -> ResponseJoinGame { + let client = reqwest::blocking::Client::new(); + + let resp = client + .post(&format!("{}/game/{}/join", api_address, game_id)) + .header("Authorization", token) + .send() + .unwrap(); + + resp.json().unwrap() +} diff --git a/sdbclient/src/api/game/mod.rs b/sdbclient/src/api/game/mod.rs index 3ce0d04..a9b8d53 100644 --- a/sdbclient/src/api/game/mod.rs +++ b/sdbclient/src/api/game/mod.rs @@ -18,3 +18,6 @@ pub use all_forming::*; mod info; pub use info::*; + +mod join; +pub use join::*; -- 2.44.1