1use super::Endpoint;
2use crate::error::ClientError;
3use crate::types;
4use async_trait::async_trait;
5use reqwest::{Method, StatusCode};
6use std::borrow::Cow;
7
8pub struct Version;
10
11#[async_trait]
12impl Endpoint for Version {
13 type Query = ();
14 type Form = ();
15 type Response = String;
16 fn relative_path(&self) -> Cow<str> {
17 "/api/v2/app/version".into()
18 }
19 fn method(&self) -> reqwest::Method {
20 Method::GET
21 }
22 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
23 match status {
24 StatusCode::OK => None,
25 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
26 _ => Some(ClientError::Unknown),
27 }
28 }
29 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
30 Ok(res.text().await?)
31 }
32}
33
34pub struct WebApiVersion;
36
37#[async_trait]
38impl Endpoint for WebApiVersion {
39 type Query = ();
40 type Form = ();
41 type Response = String;
42 fn relative_path(&self) -> Cow<str> {
43 "/api/v2/app/webapiVersion".into()
44 }
45 fn method(&self) -> reqwest::Method {
46 Method::GET
47 }
48 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
49 match status {
50 StatusCode::OK => None,
51 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
52 _ => Some(ClientError::Unknown),
53 }
54 }
55 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
56 Ok(res.text().await?)
57 }
58}
59
60pub struct BuildInfo;
62
63#[async_trait]
64impl Endpoint for BuildInfo {
65 type Query = ();
66 type Form = ();
67 type Response = types::app::BuildInfoResponse;
68 fn relative_path(&self) -> Cow<str> {
69 "/api/v2/app/buildInfo".into()
70 }
71 fn method(&self) -> reqwest::Method {
72 Method::GET
73 }
74 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
75 match status {
76 StatusCode::OK => None,
77 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
78 _ => Some(ClientError::Unknown),
79 }
80 }
81 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
82 Ok(res.json::<types::app::BuildInfoResponse>().await?)
83 }
84}
85
86pub struct Shutdown;
88
89#[async_trait]
90impl Endpoint for Shutdown {
91 type Query = ();
92 type Form = ();
93 type Response = String;
94 fn relative_path(&self) -> Cow<str> {
95 "/api/v2/app/shutdown".into()
96 }
97 fn method(&self) -> reqwest::Method {
98 Method::POST
99 }
100 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
101 match status {
102 StatusCode::OK => None,
103 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
104 _ => Some(ClientError::Unknown),
105 }
106 }
107 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
108 Ok(res.text().await?)
109 }
110}
111
112pub struct Preferences;
114
115#[async_trait]
116impl Endpoint for Preferences {
117 type Query = ();
118 type Form = ();
119 type Response = types::app::Preferences;
120 fn relative_path(&self) -> Cow<str> {
121 "/api/v2/app/preferences".into()
122 }
123 fn method(&self) -> reqwest::Method {
124 Method::GET
125 }
126 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
127 match status {
128 StatusCode::OK => None,
129 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
130 _ => Some(ClientError::Unknown),
131 }
132 }
133 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
134 Ok(res.json::<types::app::Preferences>().await?)
135 }
136}
137
138pub struct SetPreferences {
140 pub f: types::app::SetPreferencesForm,
141}
142
143#[async_trait]
144impl Endpoint for SetPreferences {
145 type Query = ();
146 type Form = types::app::SetPreferencesForm;
147 type Response = String;
148 fn relative_path(&self) -> Cow<str> {
149 "/api/v2/app/setPreferences".into()
150 }
151 fn method(&self) -> reqwest::Method {
152 Method::POST
153 }
154 fn form(&self) -> Option<&Self::Form> {
155 Some(&self.f)
156 }
157 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
158 match status {
159 StatusCode::OK => None,
160 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
161 _ => Some(ClientError::Unknown),
162 }
163 }
164 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
165 Ok(res.text().await?)
166 }
167}
168
169pub struct DefaultSavePath;
171
172#[async_trait]
173impl Endpoint for DefaultSavePath {
174 type Query = ();
175 type Form = ();
176 type Response = String;
177 fn relative_path(&self) -> Cow<str> {
178 "/api/v2/app/defaultSavePath".into()
179 }
180 fn method(&self) -> reqwest::Method {
181 Method::GET
182 }
183 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
184 match status {
185 StatusCode::OK => None,
186 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
187 _ => Some(ClientError::Unknown),
188 }
189 }
190 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
191 Ok(res.text().await?)
192 }
193}