nodesty_api_library/services/
dedicated.rs1use crate::models::{
2 dedicated::{
3 DedicatedServerAction,
4 DedicatedServerDetails,
5 DedicatedServerHardwareComponent,
6 DedicatedServerOsTemplate,
7 DedicatedServerReinstallData,
8 DedicatedServerReinstallStatus,
9 DedicatedServerTask,
10 },
11 ApiResponse,
12};
13use crate::NodestyApiClient;
14use reqwest::{Error, Method};
15use std::sync::Arc;
16
17pub struct DedicatedServerApiService {
18 client: Arc<NodestyApiClient>,
19}
20
21impl DedicatedServerApiService {
22 pub fn new(client: Arc<NodestyApiClient>) -> Self {
23 Self {
24 client,
25 }
26 }
27
28 pub async fn perform_action(
29 &self,
30 id: &str,
31 action: DedicatedServerAction,
32 ) -> Result<ApiResponse<()>, Error> {
33 let body = serde_json::json!({ "action": action });
34 self.client.send_request(Method::POST, &format!("/services/{}/dedicated/action", id), Some(body)).await
35 }
36
37 pub async fn get_details(
38 &self,
39 id: &str,
40 ) -> Result<ApiResponse<DedicatedServerDetails>, Error> {
41 self.client.send_request(Method::GET, &format!("/services/{}/dedicated/info", id), None).await
42 }
43
44 pub async fn get_hardware_components(
45 &self,
46 id: &str,
47 ) -> Result<ApiResponse<Vec<DedicatedServerHardwareComponent>>, Error> {
48 self.client.send_request(Method::GET, &format!("/services/{}/dedicated/hardware", id), None).await
49 }
50
51 pub async fn get_os_templates(
52 &self,
53 id: &str,
54 ) -> Result<ApiResponse<Vec<DedicatedServerOsTemplate>>, Error> {
55 self.client.send_request(Method::GET, &format!("/services/{}/dedicated/os-templates", id), None).await
56 }
57
58 pub async fn get_reinstall_status(
59 &self,
60 id: &str,
61 ) -> Result<ApiResponse<DedicatedServerReinstallStatus>, Error> {
62 self.client.send_request(Method::GET, &format!("/services/{}/dedicated/reinstall-status", id), None).await
63 }
64
65 pub async fn reinstall(
66 &self,
67 id: &str,
68 data: DedicatedServerReinstallData,
69 ) -> Result<ApiResponse<()>, Error> {
70 let body = serde_json::to_value(&data).ok();
71 self.client.send_request(Method::POST, &format!("/services/{}/dedicated/reinstall", id), body).await
72 }
73
74 pub async fn get_tasks(
75 &self,
76 id: &str,
77 ) -> Result<ApiResponse<Vec<DedicatedServerTask>>, Error> {
78 self.client.send_request(Method::GET, &format!("/services/{}/dedicated/tasks", id), None).await
79 }
80}