summaryrefslogtreecommitdiff
path: root/src/requests/device.rs
blob: f7754a4fa609bfec5cbe21bff9281c474dedcbec (plain) (blame)
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
58
59
60
61
62
63
64
use crate::{error::CliError, default_headers, format_url, Protocols};

pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> {
    let res = reqwest::Client::new()
        .put(format_url("device", Protocols::Http)?)
        .headers(default_headers()?)
        .body(
            format!(
                r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#,
                id,
                mac,
                broadcast_addr,
                ip
            )
        )
        .send()
        .await
        .map_err(CliError::Reqwest)?
        .text()
        .await;

    println!("{:?}", res);
    Ok(())
}

pub async fn get(id: String) -> Result<(), CliError> {
    let res = reqwest::Client::new()
        .get(format_url("device", Protocols::Http)?)
        .headers(default_headers()?)
        .body(
            format!(r#"{{"id": "{}"}}"#, id)
        )
        .send()
        .await
        .map_err(CliError::Reqwest)?
        .text()
        .await;

    println!("{:?}", res);
    Ok(())
}

pub async fn post(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> {
    let res = reqwest::Client::new()
        .post(format_url("device", Protocols::Http)?)
        .headers(default_headers()?)
        .body(
            format!(
                r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#,
                id,
                mac,
                broadcast_addr,
                ip
            )
        )
        .send()
        .await
        .map_err(CliError::Reqwest)?
        .text()
        .await;

    println!("{:?}", res);
    Ok(())
}