summaryrefslogtreecommitdiff
path: root/src/requests/start.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-10-18 15:11:44 +0200
committerfx <[email protected]>2023-10-18 15:11:44 +0200
commitb4f59c226c6916a3e45f1a52dc6a9b15c800297a (patch)
tree07016e2ac7278da6b63aa839065c5ad572215e50 /src/requests/start.rs
downloadwebol-cli-b4f59c226c6916a3e45f1a52dc6a9b15c800297a.tar
webol-cli-b4f59c226c6916a3e45f1a52dc6a9b15c800297a.tar.gz
webol-cli-b4f59c226c6916a3e45f1a52dc6a9b15c800297a.zip
basic cli, only start and get device
Diffstat (limited to 'src/requests/start.rs')
-rw-r--r--src/requests/start.rs34
1 files changed, 34 insertions, 0 deletions
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 @@
1use serde::Deserialize;
2
3use crate::{config::SETTINGS, error::CliError, default_headers};
4
5pub fn start(id: String) -> Result<(), CliError> {
6 let res = reqwest::blocking::Client::new()
7 .post(
8 format!(
9 "{}/start",
10 SETTINGS.get_string("server").map_err(CliError::Config)?
11 )
12 )
13 .headers(default_headers()?)
14 .body(
15 format!(r#"{{"id": "{}"}}"#, id)
16 )
17 .send()
18 .map_err(CliError::Reqwest)?
19 .text();
20
21 let res = serde_json::from_str::<StartResponse>(&res.map_err(CliError::Reqwest)?).map_err(CliError::Serde)?;
22
23 if res.boot {
24 println!("successfully started {}", res.id);
25 }
26
27 Ok(())
28}
29
30#[derive(Debug, Deserialize)]
31struct StartResponse {
32 boot: bool,
33 id: String,
34}