summaryrefslogtreecommitdiff
path: root/src/requests/device.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-02-25 16:14:56 +0100
committerFxQnLr <[email protected]>2024-02-25 16:14:56 +0100
commit03bea24f9de698375033af92a08762446d0e20cc (patch)
tree71b696ddcdc14f36115155be7f287fc0cb43e16d /src/requests/device.rs
parentcd73d51fba4a7d24b5ef12cb7d23054ab922cb67 (diff)
downloadwebol-cli-03bea24f9de698375033af92a08762446d0e20cc.tar
webol-cli-03bea24f9de698375033af92a08762446d0e20cc.tar.gz
webol-cli-03bea24f9de698375033af92a08762446d0e20cc.zip
Closes #2. Config and setup stuff
Diffstat (limited to 'src/requests/device.rs')
-rw-r--r--src/requests/device.rs62
1 files changed, 31 insertions, 31 deletions
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 @@
1use crate::{error::CliError, default_headers, format_url, Protocols}; 1use crate::{config::Config, default_headers, error::CliError, format_url, Protocols};
2 2
3pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { 3pub async fn put(
4 let url = format_url("device", Protocols::Http)?; 4 config: &Config,
5 id: String,
6 mac: String,
7 broadcast_addr: String,
8 ip: String,
9) -> Result<(), CliError> {
10 let url = format_url(config, "device", Protocols::Http)?;
5 println!("{}", url); 11 println!("{}", url);
6 let res = reqwest::Client::new() 12 let res = reqwest::Client::new()
7 .put(url) 13 .put(url)
8 .headers(default_headers()?) 14 .headers(default_headers(config)?)
9 .body( 15 .body(format!(
10 format!( 16 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#,
11 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, 17 id, mac, broadcast_addr, ip
12 id, 18 ))
13 mac,
14 broadcast_addr,
15 ip
16 )
17 )
18 .send() 19 .send()
19 .await 20 .await
20 .map_err(CliError::Reqwest)? 21 .map_err(CliError::Reqwest)?
@@ -25,13 +26,11 @@ pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) ->
25 Ok(()) 26 Ok(())
26} 27}
27 28
28pub async fn get(id: String) -> Result<(), CliError> { 29pub async fn get(config: &Config, id: String) -> Result<(), CliError> {
29 let res = reqwest::Client::new() 30 let res = reqwest::Client::new()
30 .get(format_url("device", Protocols::Http)?) 31 .get(format_url(config, "device", Protocols::Http)?)
31 .headers(default_headers()?) 32 .headers(default_headers(config)?)
32 .body( 33 .body(format!(r#"{{"id": "{}"}}"#, id))
33 format!(r#"{{"id": "{}"}}"#, id)
34 )
35 .send() 34 .send()
36 .await 35 .await
37 .map_err(CliError::Reqwest)? 36 .map_err(CliError::Reqwest)?
@@ -42,19 +41,20 @@ pub async fn get(id: String) -> Result<(), CliError> {
42 Ok(()) 41 Ok(())
43} 42}
44 43
45pub async fn post(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { 44pub async fn post(
45 config: &Config,
46 id: String,
47 mac: String,
48 broadcast_addr: String,
49 ip: String,
50) -> Result<(), CliError> {
46 let res = reqwest::Client::new() 51 let res = reqwest::Client::new()
47 .post(format_url("device", Protocols::Http)?) 52 .post(format_url(config, "device", Protocols::Http)?)
48 .headers(default_headers()?) 53 .headers(default_headers(config)?)
49 .body( 54 .body(format!(
50 format!( 55 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#,
51 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, 56 id, mac, broadcast_addr, ip
52 id, 57 ))
53 mac,
54 broadcast_addr,
55 ip
56 )
57 )
58 .send() 58 .send()
59 .await 59 .await
60 .map_err(CliError::Reqwest)? 60 .map_err(CliError::Reqwest)?