summaryrefslogtreecommitdiff
path: root/src/requests/device.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-02-25 16:54:03 +0100
committerFxQnLr <[email protected]>2024-02-25 16:54:03 +0100
commit465a71b6780921fb7ec19682702cbe864decd212 (patch)
tree66d9a386045a98e95a50d7f84e7e3044b578a163 /src/requests/device.rs
parent03bea24f9de698375033af92a08762446d0e20cc (diff)
downloadwebol-cli-465a71b6780921fb7ec19682702cbe864decd212.tar
webol-cli-465a71b6780921fb7ec19682702cbe864decd212.tar.gz
webol-cli-465a71b6780921fb7ec19682702cbe864decd212.zip
Closes #3. Use thiserror. Fix clippy stuff
Diffstat (limited to 'src/requests/device.rs')
-rw-r--r--src/requests/device.rs39
1 files changed, 17 insertions, 22 deletions
diff --git a/src/requests/device.rs b/src/requests/device.rs
index 5003c4a..a612978 100644
--- a/src/requests/device.rs
+++ b/src/requests/device.rs
@@ -1,4 +1,4 @@
1use crate::{config::Config, default_headers, error::CliError, format_url, Protocols}; 1use crate::{config::Config, default_headers, error::Error, format_url, Protocols};
2 2
3pub async fn put( 3pub async fn put(
4 config: &Config, 4 config: &Config,
@@ -6,38 +6,35 @@ pub async fn put(
6 mac: String, 6 mac: String,
7 broadcast_addr: String, 7 broadcast_addr: String,
8 ip: String, 8 ip: String,
9) -> Result<(), CliError> { 9) -> Result<(), Error> {
10 let url = format_url(config, "device", Protocols::Http)?; 10 let url = format_url(config, "device", &Protocols::Http);
11 println!("{}", url); 11 println!("{url}");
12 let res = reqwest::Client::new() 12 let res = reqwest::Client::new()
13 .put(url) 13 .put(url)
14 .headers(default_headers(config)?) 14 .headers(default_headers(config)?)
15 .body(format!( 15 .body(format!(
16 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, 16 r#"{{"id": "{id}", "mac": "{mac}", "broadcast_addr": "{broadcast_addr}", "ip": "{ip}"}}"#,
17 id, mac, broadcast_addr, ip
18 )) 17 ))
19 .send() 18 .send()
20 .await 19 .await?
21 .map_err(CliError::Reqwest)?
22 .text() 20 .text()
23 .await; 21 .await;
24 22
25 println!("{:?}", res); 23 println!("{res:?}");
26 Ok(()) 24 Ok(())
27} 25}
28 26
29pub async fn get(config: &Config, id: String) -> Result<(), CliError> { 27pub async fn get(config: &Config, id: String) -> Result<(), Error> {
30 let res = reqwest::Client::new() 28 let res = reqwest::Client::new()
31 .get(format_url(config, "device", Protocols::Http)?) 29 .get(format_url(config, "device", &Protocols::Http))
32 .headers(default_headers(config)?) 30 .headers(default_headers(config)?)
33 .body(format!(r#"{{"id": "{}"}}"#, id)) 31 .body(format!(r#"{{"id": "{id}"}}"#))
34 .send() 32 .send()
35 .await 33 .await?
36 .map_err(CliError::Reqwest)?
37 .text() 34 .text()
38 .await; 35 .await;
39 36
40 println!("{:?}", res); 37 println!("{res:?}");
41 Ok(()) 38 Ok(())
42} 39}
43 40
@@ -47,20 +44,18 @@ pub async fn post(
47 mac: String, 44 mac: String,
48 broadcast_addr: String, 45 broadcast_addr: String,
49 ip: String, 46 ip: String,
50) -> Result<(), CliError> { 47) -> Result<(), Error> {
51 let res = reqwest::Client::new() 48 let res = reqwest::Client::new()
52 .post(format_url(config, "device", Protocols::Http)?) 49 .post(format_url(config, "device", &Protocols::Http))
53 .headers(default_headers(config)?) 50 .headers(default_headers(config)?)
54 .body(format!( 51 .body(format!(
55 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, 52 r#"{{"id": "{id}", "mac": "{mac}", "broadcast_addr": "{broadcast_addr}", "ip": "{ip}"}}"#,
56 id, mac, broadcast_addr, ip
57 )) 53 ))
58 .send() 54 .send()
59 .await 55 .await?
60 .map_err(CliError::Reqwest)?
61 .text() 56 .text()
62 .await; 57 .await;
63 58
64 println!("{:?}", res); 59 println!("{res:?}");
65 Ok(()) 60 Ok(())
66} 61}