1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum UserSettingError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum UserSettingDeleteError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum UserSettingPostError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum UserSettingPutError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum UserSettingsError {
50 UnknownValue(serde_json::Value),
51}
52
53
54pub async fn user_setting(configuration: &configuration::Configuration, id: i64, app_key: &str) -> Result<models::UserSettingApiResponse, Error<UserSettingError>> {
56 let p_id = id;
58 let p_app_key = app_key;
59
60 let uri_str = format!("{}/UserSetting/{appKey}/{id}", configuration.base_path, id=p_id, appKey=crate::apis::urlencode(p_app_key));
61 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
62
63 if let Some(ref user_agent) = configuration.user_agent {
64 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
65 }
66 if let Some(ref token) = configuration.bearer_access_token {
67 req_builder = req_builder.bearer_auth(token.to_owned());
68 };
69
70 let req = req_builder.build()?;
71 let resp = configuration.client.execute(req).await?;
72
73 let status = resp.status();
74 let content_type = resp
75 .headers()
76 .get("content-type")
77 .and_then(|v| v.to_str().ok())
78 .unwrap_or("application/octet-stream");
79 let content_type = super::ContentType::from(content_type);
80
81 if !status.is_client_error() && !status.is_server_error() {
82 let content = resp.text().await?;
83 match content_type {
84 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
85 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserSettingApiResponse`"))),
86 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserSettingApiResponse`")))),
87 }
88 } else {
89 let content = resp.text().await?;
90 let entity: Option<UserSettingError> = serde_json::from_str(&content).ok();
91 Err(Error::ResponseError(ResponseContent { status, content, entity }))
92 }
93}
94
95pub async fn user_setting_delete(configuration: &configuration::Configuration, id: i64, app_key: &str) -> Result<models::BooleanApiResponse, Error<UserSettingDeleteError>> {
97 let p_id = id;
99 let p_app_key = app_key;
100
101 let uri_str = format!("{}/UserSetting/{appKey}/{id}", configuration.base_path, id=p_id, appKey=crate::apis::urlencode(p_app_key));
102 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
103
104 if let Some(ref user_agent) = configuration.user_agent {
105 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
106 }
107 if let Some(ref token) = configuration.bearer_access_token {
108 req_builder = req_builder.bearer_auth(token.to_owned());
109 };
110
111 let req = req_builder.build()?;
112 let resp = configuration.client.execute(req).await?;
113
114 let status = resp.status();
115 let content_type = resp
116 .headers()
117 .get("content-type")
118 .and_then(|v| v.to_str().ok())
119 .unwrap_or("application/octet-stream");
120 let content_type = super::ContentType::from(content_type);
121
122 if !status.is_client_error() && !status.is_server_error() {
123 let content = resp.text().await?;
124 match content_type {
125 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
126 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
127 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BooleanApiResponse`")))),
128 }
129 } else {
130 let content = resp.text().await?;
131 let entity: Option<UserSettingDeleteError> = serde_json::from_str(&content).ok();
132 Err(Error::ResponseError(ResponseContent { status, content, entity }))
133 }
134}
135
136pub async fn user_setting_post(configuration: &configuration::Configuration, app_key: &str, user_setting: Option<models::UserSetting>) -> Result<models::UserSettingPostResultApiResponse, Error<UserSettingPostError>> {
138 let p_app_key = app_key;
140 let p_user_setting = user_setting;
141
142 let uri_str = format!("{}/UserSetting/{appKey}", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
143 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
144
145 if let Some(ref user_agent) = configuration.user_agent {
146 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147 }
148 if let Some(ref token) = configuration.bearer_access_token {
149 req_builder = req_builder.bearer_auth(token.to_owned());
150 };
151 req_builder = req_builder.json(&p_user_setting);
152
153 let req = req_builder.build()?;
154 let resp = configuration.client.execute(req).await?;
155
156 let status = resp.status();
157 let content_type = resp
158 .headers()
159 .get("content-type")
160 .and_then(|v| v.to_str().ok())
161 .unwrap_or("application/octet-stream");
162 let content_type = super::ContentType::from(content_type);
163
164 if !status.is_client_error() && !status.is_server_error() {
165 let content = resp.text().await?;
166 match content_type {
167 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
168 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserSettingPostResultApiResponse`"))),
169 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserSettingPostResultApiResponse`")))),
170 }
171 } else {
172 let content = resp.text().await?;
173 let entity: Option<UserSettingPostError> = serde_json::from_str(&content).ok();
174 Err(Error::ResponseError(ResponseContent { status, content, entity }))
175 }
176}
177
178pub async fn user_setting_put(configuration: &configuration::Configuration, id: i64, app_key: &str, user_setting: Option<models::UserSetting>) -> Result<models::BooleanApiResponse, Error<UserSettingPutError>> {
180 let p_id = id;
182 let p_app_key = app_key;
183 let p_user_setting = user_setting;
184
185 let uri_str = format!("{}/UserSetting/{appKey}/{id}", configuration.base_path, id=p_id, appKey=crate::apis::urlencode(p_app_key));
186 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
187
188 if let Some(ref user_agent) = configuration.user_agent {
189 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
190 }
191 if let Some(ref token) = configuration.bearer_access_token {
192 req_builder = req_builder.bearer_auth(token.to_owned());
193 };
194 req_builder = req_builder.json(&p_user_setting);
195
196 let req = req_builder.build()?;
197 let resp = configuration.client.execute(req).await?;
198
199 let status = resp.status();
200 let content_type = resp
201 .headers()
202 .get("content-type")
203 .and_then(|v| v.to_str().ok())
204 .unwrap_or("application/octet-stream");
205 let content_type = super::ContentType::from(content_type);
206
207 if !status.is_client_error() && !status.is_server_error() {
208 let content = resp.text().await?;
209 match content_type {
210 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
211 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
212 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BooleanApiResponse`")))),
213 }
214 } else {
215 let content = resp.text().await?;
216 let entity: Option<UserSettingPutError> = serde_json::from_str(&content).ok();
217 Err(Error::ResponseError(ResponseContent { status, content, entity }))
218 }
219}
220
221pub async fn user_settings(configuration: &configuration::Configuration, app_key: &str, user_id: Option<i64>, code: Option<&str>, tag: Option<&str>) -> Result<models::UserSettingListApiResponse, Error<UserSettingsError>> {
223 let p_app_key = app_key;
225 let p_user_id = user_id;
226 let p_code = code;
227 let p_tag = tag;
228
229 let uri_str = format!("{}/UserSetting/{appKey}", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
230 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
231
232 if let Some(ref param_value) = p_user_id {
233 req_builder = req_builder.query(&[("userId", ¶m_value.to_string())]);
234 }
235 if let Some(ref param_value) = p_code {
236 req_builder = req_builder.query(&[("code", ¶m_value.to_string())]);
237 }
238 if let Some(ref param_value) = p_tag {
239 req_builder = req_builder.query(&[("tag", ¶m_value.to_string())]);
240 }
241 if let Some(ref user_agent) = configuration.user_agent {
242 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
243 }
244 if let Some(ref token) = configuration.bearer_access_token {
245 req_builder = req_builder.bearer_auth(token.to_owned());
246 };
247
248 let req = req_builder.build()?;
249 let resp = configuration.client.execute(req).await?;
250
251 let status = resp.status();
252 let content_type = resp
253 .headers()
254 .get("content-type")
255 .and_then(|v| v.to_str().ok())
256 .unwrap_or("application/octet-stream");
257 let content_type = super::ContentType::from(content_type);
258
259 if !status.is_client_error() && !status.is_server_error() {
260 let content = resp.text().await?;
261 match content_type {
262 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
263 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserSettingListApiResponse`"))),
264 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserSettingListApiResponse`")))),
265 }
266 } else {
267 let content = resp.text().await?;
268 let entity: Option<UserSettingsError> = serde_json::from_str(&content).ok();
269 Err(Error::ResponseError(ResponseContent { status, content, entity }))
270 }
271}
272