diff options
author | FxQnLr <[email protected]> | 2023-11-17 11:18:31 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2023-11-17 11:18:31 +0100 |
commit | 48190366ac94888811dd4b0b8e6532b35f1a9d10 (patch) | |
tree | 8689660d75d0e45af460ed3d144b5a010289c0be /src/requests/device.rs | |
parent | 8fab2e7c3a38a91c8f5549b639e7f2ac4ae1a420 (diff) | |
parent | 93de8742961287cb9cfd08e68c8afa2347585a73 (diff) | |
download | webol-cli-48190366ac94888811dd4b0b8e6532b35f1a9d10.tar webol-cli-48190366ac94888811dd4b0b8e6532b35f1a9d10.tar.gz webol-cli-48190366ac94888811dd4b0b8e6532b35f1a9d10.zip |
Merge pull request #1 from FxQnLr/eta
Eta
Diffstat (limited to 'src/requests/device.rs')
-rw-r--r-- | src/requests/device.rs | 44 |
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 @@ | |||
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 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 | ||
23 | pub fn get(id: String) -> Result<(), CliError> { | 28 | pub 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 | ||
38 | pub fn post(id: String, mac: String, broadcast_addr: String) -> Result<(), CliError> { | 45 | pub 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(()) |