From a192e9baca9a14beaa9f87c27a63cff96aa41c94 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Sun, 25 Feb 2024 20:00:38 +0100 Subject: Closes #4. Auth on Websocket. Small stuff --- src/requests/device.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/requests/device.rs') diff --git a/src/requests/device.rs b/src/requests/device.rs index a612978..7583406 100644 --- a/src/requests/device.rs +++ b/src/requests/device.rs @@ -1,4 +1,4 @@ -use crate::{config::Config, default_headers, error::Error, format_url, Protocols}; +use crate::{check_success, config::Config, default_headers, error::Error, format_url, Protocols}; pub async fn put( config: &Config, @@ -16,11 +16,10 @@ pub async fn put( r#"{{"id": "{id}", "mac": "{mac}", "broadcast_addr": "{broadcast_addr}", "ip": "{ip}"}}"#, )) .send() - .await? - .text() - .await; + .await?; - println!("{res:?}"); + let body = check_success(res).await?; + println!("{body}"); Ok(()) } @@ -30,11 +29,10 @@ pub async fn get(config: &Config, id: String) -> Result<(), Error> { .headers(default_headers(config)?) .body(format!(r#"{{"id": "{id}"}}"#)) .send() - .await? - .text() - .await; + .await?; - println!("{res:?}"); + let body = check_success(res).await?; + println!("{body}"); Ok(()) } @@ -52,10 +50,9 @@ pub async fn post( r#"{{"id": "{id}", "mac": "{mac}", "broadcast_addr": "{broadcast_addr}", "ip": "{ip}"}}"#, )) .send() - .await? - .text() - .await; + .await?; - println!("{res:?}"); + let body = check_success(res).await?; + println!("{body}"); Ok(()) } -- cgit v1.2.3