From b4f59c226c6916a3e45f1a52dc6a9b15c800297a Mon Sep 17 00:00:00 2001 From: fx Date: Wed, 18 Oct 2023 15:11:44 +0200 Subject: basic cli, only start and get device --- src/requests/start.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/requests/start.rs (limited to 'src/requests/start.rs') diff --git a/src/requests/start.rs b/src/requests/start.rs new file mode 100644 index 0000000..1a8cb6c --- /dev/null +++ b/src/requests/start.rs @@ -0,0 +1,34 @@ +use serde::Deserialize; + +use crate::{config::SETTINGS, error::CliError, default_headers}; + +pub fn start(id: String) -> Result<(), CliError> { + let res = reqwest::blocking::Client::new() + .post( + format!( + "{}/start", + SETTINGS.get_string("server").map_err(CliError::Config)? + ) + ) + .headers(default_headers()?) + .body( + format!(r#"{{"id": "{}"}}"#, id) + ) + .send() + .map_err(CliError::Reqwest)? + .text(); + + let res = serde_json::from_str::(&res.map_err(CliError::Reqwest)?).map_err(CliError::Serde)?; + + if res.boot { + println!("successfully started {}", res.id); + } + + Ok(()) +} + +#[derive(Debug, Deserialize)] +struct StartResponse { + boot: bool, + id: String, +} -- cgit v1.2.3