From 8fab2e7c3a38a91c8f5549b639e7f2ac4ae1a420 Mon Sep 17 00:00:00 2001 From: fx Date: Sat, 21 Oct 2023 17:43:31 +0200 Subject: added device add and update --- src/requests/device.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/requests/device.rs (limited to 'src/requests/device.rs') diff --git a/src/requests/device.rs b/src/requests/device.rs new file mode 100644 index 0000000..525745a --- /dev/null +++ b/src/requests/device.rs @@ -0,0 +1,56 @@ +use crate::{error::CliError, default_headers, format_url}; + +pub fn put(id: String, mac: String, broadcast_addr: String) -> Result<(), CliError> { + let res = reqwest::blocking::Client::new() + .put(format_url("device")?) + .headers(default_headers()?) + .body( + format!( + r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}"}}"#, + id, + mac, + broadcast_addr + ) + ) + .send() + .map_err(CliError::Reqwest)? + .text(); + + println!("{:?}", res); + Ok(()) +} + +pub fn get(id: String) -> Result<(), CliError> { + let res = reqwest::blocking::Client::new() + .get(format_url("device")?) + .headers(default_headers()?) + .body( + format!(r#"{{"id": "{}"}}"#, id) + ) + .send() + .map_err(CliError::Reqwest)? + .text(); + + println!("{:?}", res); + Ok(()) +} + +pub fn post(id: String, mac: String, broadcast_addr: String) -> Result<(), CliError> { + let res = reqwest::blocking::Client::new() + .post(format_url("device")?) + .headers(default_headers()?) + .body( + format!( + r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}"}}"#, + id, + mac, + broadcast_addr + ) + ) + .send() + .map_err(CliError::Reqwest)? + .text(); + + println!("{:?}", res); + Ok(()) +} -- cgit v1.2.3