/* * This file is part of laurelin/shared * Copyright (C) 2023 Jonni Liljamo * * Licensed under GPL-3.0-only. * See LICENSE for licensing information. */ use reqwest; use serde::{Deserialize, Serialize}; use super::{ types::{Game, GameState}, APIErrorWrapper, }; #[derive(Serialize)] pub struct PostState { pub state: GameState, } #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum ResponsePatchGameState { Error(APIErrorWrapper), Valid(Game), } pub fn patch_state( api_address: String, token: String, game_id: String, state: GameState, ) -> ResponsePatchGameState { let client = reqwest::blocking::Client::new(); let resp = client .patch(&format!("{}/game/{}/state", api_address, game_id)) .header("Authorization", token) .json(&PostState { state }) .send() .unwrap(); resp.json().unwrap() }