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