summaryrefslogtreecommitdiff
path: root/src/requests
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-06-17 11:19:13 +0200
committerGitHub <[email protected]>2024-06-17 11:19:13 +0200
commitb375657e660b199127a76683980a5d210a572ab7 (patch)
treefbed775283917537c1d2d11bdbf38a0fa7c05a02 /src/requests
parent31a57425a76cae121c5d8ef5b0f2442ca6a9ee61 (diff)
parent0877850a63791772dd19a0af9a0c7c87940aead2 (diff)
downloadwebol-cli-main.tar
webol-cli-main.tar.gz
webol-cli-main.zip
Merge pull request #9 from FxQnLr/0.3.0HEAD0.3.0main
0.3.0
Diffstat (limited to 'src/requests')
-rw-r--r--src/requests/device.rs7
-rw-r--r--src/requests/start.rs8
2 files changed, 7 insertions, 8 deletions
diff --git a/src/requests/device.rs b/src/requests/device.rs
index 7583406..2606579 100644
--- a/src/requests/device.rs
+++ b/src/requests/device.rs
@@ -7,7 +7,7 @@ pub async fn put(
7 broadcast_addr: String, 7 broadcast_addr: String,
8 ip: String, 8 ip: String,
9) -> Result<(), Error> { 9) -> Result<(), Error> {
10 let url = format_url(config, "device", &Protocols::Http); 10 let url = format_url(config, "device", &Protocols::Http, None);
11 println!("{url}"); 11 println!("{url}");
12 let res = reqwest::Client::new() 12 let res = reqwest::Client::new()
13 .put(url) 13 .put(url)
@@ -25,9 +25,8 @@ pub async fn put(
25 25
26pub async fn get(config: &Config, id: String) -> Result<(), Error> { 26pub async fn get(config: &Config, id: String) -> Result<(), Error> {
27 let res = reqwest::Client::new() 27 let res = reqwest::Client::new()
28 .get(format_url(config, "device", &Protocols::Http)) 28 .get(format_url(config, "device", &Protocols::Http, Some(&id)))
29 .headers(default_headers(config)?) 29 .headers(default_headers(config)?)
30 .body(format!(r#"{{"id": "{id}"}}"#))
31 .send() 30 .send()
32 .await?; 31 .await?;
33 32
@@ -44,7 +43,7 @@ pub async fn post(
44 ip: String, 43 ip: String,
45) -> Result<(), Error> { 44) -> Result<(), Error> {
46 let res = reqwest::Client::new() 45 let res = reqwest::Client::new()
47 .post(format_url(config, "device", &Protocols::Http)) 46 .post(format_url(config, "device", &Protocols::Http, None))
48 .headers(default_headers(config)?) 47 .headers(default_headers(config)?)
49 .body(format!( 48 .body(format!(
50 r#"{{"id": "{id}", "mac": "{mac}", "broadcast_addr": "{broadcast_addr}", "ip": "{ip}"}}"#, 49 r#"{{"id": "{id}", "mac": "{mac}", "broadcast_addr": "{broadcast_addr}", "ip": "{ip}"}}"#,
diff --git a/src/requests/start.rs b/src/requests/start.rs
index 3afbe3a..1ec3ce8 100644
--- a/src/requests/start.rs
+++ b/src/requests/start.rs
@@ -17,12 +17,12 @@ pub async fn start(config: &Config, id: String, ping: bool) -> Result<(), Error>
17 let send_start = MultiProgress::new(); 17 let send_start = MultiProgress::new();
18 let overview = add_pb(&send_start, OVERVIEW_STYLE, format!(") start {id}")); 18 let overview = add_pb(&send_start, OVERVIEW_STYLE, format!(") start {id}"));
19 19
20 let url = format_url(config, "start", &Protocols::Http); 20 let url = format_url(config, "start", &Protocols::Http, Some(&id));
21 let connect = add_pb(&send_start, DEFAULT_STYLE, format!("connect to {url}")); 21 let connect = add_pb(&send_start, DEFAULT_STYLE, format!("connect to {url}"));
22 let res = reqwest::Client::new() 22 let res = reqwest::Client::new()
23 .post(url) 23 .post(url)
24 .headers(default_headers(config)?) 24 .headers(default_headers(config)?)
25 .body(format!(r#"{{"id": "{id}", "ping": {ping}}}"#)) 25 .body(format!(r#"{{"ping": {ping}}}"#))
26 .send() 26 .send()
27 .await?; 27 .await?;
28 finish_pb(&connect, "connected, got response".to_string(), DONE_STYLE); 28 finish_pb(&connect, "connected, got response".to_string(), DONE_STYLE);
@@ -71,8 +71,8 @@ async fn status_socket(
71 let ws_pb = add_pb(pb, DEFAULT_STYLE, "connect to websocket".to_string()); 71 let ws_pb = add_pb(pb, DEFAULT_STYLE, "connect to websocket".to_string());
72 72
73 let request = Request::builder() 73 let request = Request::builder()
74 .uri(format_url(config, "status", &Protocols::Websocket)) 74 .uri(format_url(config, "status", &Protocols::Websocket, None))
75 .header("Authorization", &config.apikey) 75 .header("Authorization", &config.auth.secret)
76 .header("sec-websocket-key", "") 76 .header("sec-websocket-key", "")
77 .header("host", &config.server) 77 .header("host", &config.server)
78 .header("upgrade", "websocket") 78 .header("upgrade", "websocket")