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