From 03bea24f9de698375033af92a08762446d0e20cc Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Sun, 25 Feb 2024 16:14:56 +0100 Subject: Closes #2. Config and setup stuff --- src/requests/device.rs | 62 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'src/requests/device.rs') diff --git a/src/requests/device.rs b/src/requests/device.rs index cbc838e..5003c4a 100644 --- a/src/requests/device.rs +++ b/src/requests/device.rs @@ -1,20 +1,21 @@ -use crate::{error::CliError, default_headers, format_url, Protocols}; +use crate::{config::Config, default_headers, error::CliError, format_url, Protocols}; -pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { - let url = format_url("device", Protocols::Http)?; +pub async fn put( + config: &Config, + id: String, + mac: String, + broadcast_addr: String, + ip: String, +) -> Result<(), CliError> { + let url = format_url(config, "device", Protocols::Http)?; println!("{}", url); let res = reqwest::Client::new() .put(url) - .headers(default_headers()?) - .body( - format!( - r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, - id, - mac, - broadcast_addr, - ip - ) - ) + .headers(default_headers(config)?) + .body(format!( + r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, + id, mac, broadcast_addr, ip + )) .send() .await .map_err(CliError::Reqwest)? @@ -25,13 +26,11 @@ pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) -> Ok(()) } -pub async fn get(id: String) -> Result<(), CliError> { +pub async fn get(config: &Config, id: String) -> Result<(), CliError> { let res = reqwest::Client::new() - .get(format_url("device", Protocols::Http)?) - .headers(default_headers()?) - .body( - format!(r#"{{"id": "{}"}}"#, id) - ) + .get(format_url(config, "device", Protocols::Http)?) + .headers(default_headers(config)?) + .body(format!(r#"{{"id": "{}"}}"#, id)) .send() .await .map_err(CliError::Reqwest)? @@ -42,19 +41,20 @@ pub async fn get(id: String) -> Result<(), CliError> { Ok(()) } -pub async fn post(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { +pub async fn post( + config: &Config, + 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": "{}", "ip": "{}"}}"#, - id, - mac, - broadcast_addr, - ip - ) - ) + .post(format_url(config, "device", Protocols::Http)?) + .headers(default_headers(config)?) + .body(format!( + r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, + id, mac, broadcast_addr, ip + )) .send() .await .map_err(CliError::Reqwest)? -- cgit v1.2.3