summaryrefslogtreecommitdiff
path: root/src/requests/device.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/requests/device.rs')
-rw-r--r--src/requests/device.rs44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/requests/device.rs b/src/requests/device.rs
index 525745a..cbc838e 100644
--- a/src/requests/device.rs
+++ b/src/requests/device.rs
@@ -1,55 +1,65 @@
1use crate::{error::CliError, default_headers, format_url}; 1use crate::{error::CliError, default_headers, format_url, Protocols};
2 2
3pub fn put(id: String, mac: String, broadcast_addr: String) -> Result<(), CliError> { 3pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> {
4 let res = reqwest::blocking::Client::new() 4 let url = format_url("device", Protocols::Http)?;
5 .put(format_url("device")?) 5 println!("{}", url);
6 let res = reqwest::Client::new()
7 .put(url)
6 .headers(default_headers()?) 8 .headers(default_headers()?)
7 .body( 9 .body(
8 format!( 10 format!(
9 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}"}}"#, 11 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#,
10 id, 12 id,
11 mac, 13 mac,
12 broadcast_addr 14 broadcast_addr,
15 ip
13 ) 16 )
14 ) 17 )
15 .send() 18 .send()
19 .await
16 .map_err(CliError::Reqwest)? 20 .map_err(CliError::Reqwest)?
17 .text(); 21 .text()
22 .await;
18 23
19 println!("{:?}", res); 24 println!("{:?}", res);
20 Ok(()) 25 Ok(())
21} 26}
22 27
23pub fn get(id: String) -> Result<(), CliError> { 28pub async fn get(id: String) -> Result<(), CliError> {
24 let res = reqwest::blocking::Client::new() 29 let res = reqwest::Client::new()
25 .get(format_url("device")?) 30 .get(format_url("device", Protocols::Http)?)
26 .headers(default_headers()?) 31 .headers(default_headers()?)
27 .body( 32 .body(
28 format!(r#"{{"id": "{}"}}"#, id) 33 format!(r#"{{"id": "{}"}}"#, id)
29 ) 34 )
30 .send() 35 .send()
36 .await
31 .map_err(CliError::Reqwest)? 37 .map_err(CliError::Reqwest)?
32 .text(); 38 .text()
39 .await;
33 40
34 println!("{:?}", res); 41 println!("{:?}", res);
35 Ok(()) 42 Ok(())
36} 43}
37 44
38pub fn post(id: String, mac: String, broadcast_addr: String) -> Result<(), CliError> { 45pub async fn post(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> {
39 let res = reqwest::blocking::Client::new() 46 let res = reqwest::Client::new()
40 .post(format_url("device")?) 47 .post(format_url("device", Protocols::Http)?)
41 .headers(default_headers()?) 48 .headers(default_headers()?)
42 .body( 49 .body(
43 format!( 50 format!(
44 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}"}}"#, 51 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#,
45 id, 52 id,
46 mac, 53 mac,
47 broadcast_addr 54 broadcast_addr,
55 ip
48 ) 56 )
49 ) 57 )
50 .send() 58 .send()
59 .await
51 .map_err(CliError::Reqwest)? 60 .map_err(CliError::Reqwest)?
52 .text(); 61 .text()
62 .await;
53 63
54 println!("{:?}", res); 64 println!("{:?}", res);
55 Ok(()) 65 Ok(())