1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
use crate::{error::CliError, default_headers, format_url};
pub fn put(id: String, mac: String, broadcast_addr: String) -> Result<(), CliError> {
let res = reqwest::blocking::Client::new()
.put(format_url("device")?)
.headers(default_headers()?)
.body(
format!(
r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}"}}"#,
id,
mac,
broadcast_addr
)
)
.send()
.map_err(CliError::Reqwest)?
.text();
println!("{:?}", res);
Ok(())
}
pub fn get(id: String) -> Result<(), CliError> {
let res = reqwest::blocking::Client::new()
.get(format_url("device")?)
.headers(default_headers()?)
.body(
format!(r#"{{"id": "{}"}}"#, id)
)
.send()
.map_err(CliError::Reqwest)?
.text();
println!("{:?}", res);
Ok(())
}
pub fn post(id: String, mac: String, broadcast_addr: String) -> Result<(), CliError> {
let res = reqwest::blocking::Client::new()
.post(format_url("device")?)
.headers(default_headers()?)
.body(
format!(
r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}"}}"#,
id,
mac,
broadcast_addr
)
)
.send()
.map_err(CliError::Reqwest)?
.text();
println!("{:?}", res);
Ok(())
}
|