summaryrefslogtreecommitdiff
path: root/src/requests
diff options
context:
space:
mode:
Diffstat (limited to 'src/requests')
-rw-r--r--src/requests/device.rs56
-rw-r--r--src/requests/get.rs21
-rw-r--r--src/requests/mod.rs2
3 files changed, 57 insertions, 22 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 @@
1use crate::{error::CliError, default_headers, format_url};
2
3pub 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
23pub 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
38pub 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}
diff --git a/src/requests/get.rs b/src/requests/get.rs
deleted file mode 100644
index 225562d..0000000
--- a/src/requests/get.rs
+++ /dev/null
@@ -1,21 +0,0 @@
1use crate::{error::CliError, config::SETTINGS, default_headers};
2
3pub fn get(id: String) -> Result<(), CliError> {
4 let res = reqwest::blocking::Client::new()
5 .get(
6 format!(
7 "{}/start",
8 SETTINGS.get_string("server").map_err(CliError::Config)?
9 )
10 )
11 .headers(default_headers()?)
12 .body(
13 format!(r#"{{"id": "{}"}}"#, id)
14 )
15 .send()
16 .map_err(CliError::Reqwest)?
17 .text();
18
19 println!("{:?}", res);
20 Ok(())
21}
diff --git a/src/requests/mod.rs b/src/requests/mod.rs
index ddf0ea9..6855db1 100644
--- a/src/requests/mod.rs
+++ b/src/requests/mod.rs
@@ -1,2 +1,2 @@
1pub mod start; 1pub mod start;
2pub mod get; 2pub mod device;