From f4d3d921460b606a9ff6686c9bb9a79bf546f264 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Thu, 2 Nov 2023 21:01:16 +0100 Subject: baseline ping --- src/requests/device.rs | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'src/requests/device.rs') diff --git a/src/requests/device.rs b/src/requests/device.rs index 525745a..f7754a4 100644 --- a/src/requests/device.rs +++ b/src/requests/device.rs @@ -1,55 +1,63 @@ -use crate::{error::CliError, default_headers, format_url}; +use crate::{error::CliError, default_headers, format_url, Protocols}; -pub fn put(id: String, mac: String, broadcast_addr: String) -> Result<(), CliError> { - let res = reqwest::blocking::Client::new() - .put(format_url("device")?) +pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { + let res = reqwest::Client::new() + .put(format_url("device", Protocols::Http)?) .headers(default_headers()?) .body( format!( - r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}"}}"#, + r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, id, mac, - broadcast_addr + broadcast_addr, + ip ) ) .send() + .await .map_err(CliError::Reqwest)? - .text(); + .text() + .await; println!("{:?}", res); Ok(()) } -pub fn get(id: String) -> Result<(), CliError> { - let res = reqwest::blocking::Client::new() - .get(format_url("device")?) +pub async fn get(id: String) -> Result<(), CliError> { + let res = reqwest::Client::new() + .get(format_url("device", Protocols::Http)?) .headers(default_headers()?) .body( format!(r#"{{"id": "{}"}}"#, id) ) .send() + .await .map_err(CliError::Reqwest)? - .text(); + .text() + .await; 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")?) +pub async fn post(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { + let res = reqwest::Client::new() + .post(format_url("device", Protocols::Http)?) .headers(default_headers()?) .body( format!( - r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}"}}"#, + r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, id, mac, - broadcast_addr + broadcast_addr, + ip ) ) .send() + .await .map_err(CliError::Reqwest)? - .text(); + .text() + .await; println!("{:?}", res); Ok(()) -- cgit v1.2.3