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
57
|
use crate::{check_success, config::Config, default_headers, error::Error, format_url, Protocols};
pub async fn put(
config: &Config,
id: String,
mac: String,
broadcast_addr: String,
ip: String,
) -> Result<(), Error> {
let url = format_url(config, "device", &Protocols::Http, None);
println!("{url}");
let res = reqwest::Client::new()
.put(url)
.headers(default_headers(config)?)
.body(format!(
r#"{{"id": "{id}", "mac": "{mac}", "broadcast_addr": "{broadcast_addr}", "ip": "{ip}"}}"#,
))
.send()
.await?;
let body = check_success(res).await?;
println!("{body}");
Ok(())
}
pub async fn get(config: &Config, id: String) -> Result<(), Error> {
let res = reqwest::Client::new()
.get(format_url(config, "device", &Protocols::Http, Some(&id)))
.headers(default_headers(config)?)
.send()
.await?;
let body = check_success(res).await?;
println!("{body}");
Ok(())
}
pub async fn post(
config: &Config,
id: String,
mac: String,
broadcast_addr: String,
ip: String,
) -> Result<(), Error> {
let res = reqwest::Client::new()
.post(format_url(config, "device", &Protocols::Http, None))
.headers(default_headers(config)?)
.body(format!(
r#"{{"id": "{id}", "mac": "{mac}", "broadcast_addr": "{broadcast_addr}", "ip": "{ip}"}}"#,
))
.send()
.await?;
let body = check_success(res).await?;
println!("{body}");
Ok(())
}
|