1use serde_json::json;
2
3use crate::error::HtbError;
4use crate::models::vpn::{Connection, ConnectionsResponse, VpnSwitchResponse};
5
6use super::HtbClient;
7
8pub struct VpnApi<'a>(pub(crate) &'a HtbClient);
9
10impl VpnApi<'_> {
11 pub async fn connections(&self) -> Result<Vec<Connection>, HtbError> {
12 let resp: ConnectionsResponse = self.0.get("/api/v5/connections").await?;
13 Ok(resp.data)
14 }
15
16 pub async fn status(&self) -> Result<Vec<serde_json::Value>, HtbError> {
17 self.0.get("/api/v4/connection/status").await
18 }
19
20 pub async fn switch(&self, server_id: u32) -> Result<VpnSwitchResponse, HtbError> {
21 self.0
22 .post(
23 &format!("/api/v4/connections/servers/switch/{server_id}"),
24 &json!({}),
25 )
26 .await
27 }
28
29 pub async fn download_ovpn(&self, server_id: u32) -> Result<Vec<u8>, HtbError> {
30 self.0
31 .get_bytes(&format!("/api/v4/access/ovpnfile/{server_id}/0"))
32 .await
33 }
34}