1use super::{configuration, ContentType, Error};
10use crate::{apis::ResponseContent, models};
11use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(untagged)]
17pub enum BoopError {
18 Status400(models::Error),
19 Status401(models::Error),
20 Status404(models::Error),
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum DeleteFriendRequestError {
28 Status401(models::Error),
29 Status404(models::Error),
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum FriendError {
37 Status400(models::Error),
38 Status401(models::Error),
39 Status404(models::Error),
40 UnknownValue(serde_json::Value),
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum GetFriendStatusError {
47 Status401(models::Error),
48 UnknownValue(serde_json::Value),
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum GetFriendsError {
55 Status401(models::Error),
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum UnfriendError {
63 Status400(models::Error),
64 Status401(models::Error),
65 UnknownValue(serde_json::Value),
66}
67
68pub async fn boop(
70 configuration: &configuration::Configuration,
71 user_id: &str,
72 boop_request: models::BoopRequest,
73) -> Result<models::Success, Error<BoopError>> {
74 let p_path_user_id = user_id;
76 let p_body_boop_request = boop_request;
77
78 let uri_str = format!(
79 "{}/users/{userId}/boop",
80 configuration.base_path,
81 userId = crate::apis::urlencode(p_path_user_id)
82 );
83 let mut req_builder = configuration
84 .client
85 .request(reqwest::Method::POST, &uri_str);
86
87 if let Some(ref user_agent) = configuration.user_agent {
88 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
89 }
90 req_builder = req_builder.json(&p_body_boop_request);
91
92 let req = req_builder.build()?;
93 let resp = configuration.client.execute(req).await?;
94
95 let status = resp.status();
96 let content_type = resp
97 .headers()
98 .get("content-type")
99 .and_then(|v| v.to_str().ok())
100 .unwrap_or("application/octet-stream");
101 let content_type = super::ContentType::from(content_type);
102
103 if !status.is_client_error() && !status.is_server_error() {
104 let content = resp.text().await?;
105 match content_type {
106 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
107 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Success`"))),
108 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::Success`")))),
109 }
110 } else {
111 let content = resp.text().await?;
112 let entity: Option<BoopError> = serde_json::from_str(&content).ok();
113 Err(Error::ResponseError(ResponseContent {
114 status,
115 content,
116 entity,
117 }))
118 }
119}
120
121pub async fn delete_friend_request(
123 configuration: &configuration::Configuration,
124 user_id: &str,
125) -> Result<models::Success, Error<DeleteFriendRequestError>> {
126 let p_path_user_id = user_id;
128
129 let uri_str = format!(
130 "{}/user/{userId}/friendRequest",
131 configuration.base_path,
132 userId = crate::apis::urlencode(p_path_user_id)
133 );
134 let mut req_builder = configuration
135 .client
136 .request(reqwest::Method::DELETE, &uri_str);
137
138 if let Some(ref user_agent) = configuration.user_agent {
139 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
140 }
141
142 let req = req_builder.build()?;
143 let resp = configuration.client.execute(req).await?;
144
145 let status = resp.status();
146 let content_type = resp
147 .headers()
148 .get("content-type")
149 .and_then(|v| v.to_str().ok())
150 .unwrap_or("application/octet-stream");
151 let content_type = super::ContentType::from(content_type);
152
153 if !status.is_client_error() && !status.is_server_error() {
154 let content = resp.text().await?;
155 match content_type {
156 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
157 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Success`"))),
158 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::Success`")))),
159 }
160 } else {
161 let content = resp.text().await?;
162 let entity: Option<DeleteFriendRequestError> = serde_json::from_str(&content).ok();
163 Err(Error::ResponseError(ResponseContent {
164 status,
165 content,
166 entity,
167 }))
168 }
169}
170
171pub async fn friend(
173 configuration: &configuration::Configuration,
174 user_id: &str,
175) -> Result<models::Notification, Error<FriendError>> {
176 let p_path_user_id = user_id;
178
179 let uri_str = format!(
180 "{}/user/{userId}/friendRequest",
181 configuration.base_path,
182 userId = crate::apis::urlencode(p_path_user_id)
183 );
184 let mut req_builder = configuration
185 .client
186 .request(reqwest::Method::POST, &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
192 let req = req_builder.build()?;
193 let resp = configuration.client.execute(req).await?;
194
195 let status = resp.status();
196 let content_type = resp
197 .headers()
198 .get("content-type")
199 .and_then(|v| v.to_str().ok())
200 .unwrap_or("application/octet-stream");
201 let content_type = super::ContentType::from(content_type);
202
203 if !status.is_client_error() && !status.is_server_error() {
204 let content = resp.text().await?;
205 match content_type {
206 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
207 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Notification`"))),
208 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::Notification`")))),
209 }
210 } else {
211 let content = resp.text().await?;
212 let entity: Option<FriendError> = serde_json::from_str(&content).ok();
213 Err(Error::ResponseError(ResponseContent {
214 status,
215 content,
216 entity,
217 }))
218 }
219}
220
221pub async fn get_friend_status(
223 configuration: &configuration::Configuration,
224 user_id: &str,
225) -> Result<models::FriendStatus, Error<GetFriendStatusError>> {
226 let p_path_user_id = user_id;
228
229 let uri_str = format!(
230 "{}/user/{userId}/friendStatus",
231 configuration.base_path,
232 userId = crate::apis::urlencode(p_path_user_id)
233 );
234 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
235
236 if let Some(ref user_agent) = configuration.user_agent {
237 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
238 }
239
240 let req = req_builder.build()?;
241 let resp = configuration.client.execute(req).await?;
242
243 let status = resp.status();
244 let content_type = resp
245 .headers()
246 .get("content-type")
247 .and_then(|v| v.to_str().ok())
248 .unwrap_or("application/octet-stream");
249 let content_type = super::ContentType::from(content_type);
250
251 if !status.is_client_error() && !status.is_server_error() {
252 let content = resp.text().await?;
253 match content_type {
254 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
255 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FriendStatus`"))),
256 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::FriendStatus`")))),
257 }
258 } else {
259 let content = resp.text().await?;
260 let entity: Option<GetFriendStatusError> = serde_json::from_str(&content).ok();
261 Err(Error::ResponseError(ResponseContent {
262 status,
263 content,
264 entity,
265 }))
266 }
267}
268
269pub async fn get_friends(
271 configuration: &configuration::Configuration,
272 offset: Option<i32>,
273 n: Option<i32>,
274 offline: Option<bool>,
275) -> Result<Vec<models::LimitedUserFriend>, Error<GetFriendsError>> {
276 let p_query_offset = offset;
278 let p_query_n = n;
279 let p_query_offline = offline;
280
281 let uri_str = format!("{}/auth/user/friends", configuration.base_path);
282 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
283
284 if let Some(ref param_value) = p_query_offset {
285 req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
286 }
287 if let Some(ref param_value) = p_query_n {
288 req_builder = req_builder.query(&[("n", ¶m_value.to_string())]);
289 }
290 if let Some(ref param_value) = p_query_offline {
291 req_builder = req_builder.query(&[("offline", ¶m_value.to_string())]);
292 }
293 if let Some(ref user_agent) = configuration.user_agent {
294 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
295 }
296
297 let req = req_builder.build()?;
298 let resp = configuration.client.execute(req).await?;
299
300 let status = resp.status();
301 let content_type = resp
302 .headers()
303 .get("content-type")
304 .and_then(|v| v.to_str().ok())
305 .unwrap_or("application/octet-stream");
306 let content_type = super::ContentType::from(content_type);
307
308 if !status.is_client_error() && !status.is_server_error() {
309 let content = resp.text().await?;
310 match content_type {
311 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
312 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::LimitedUserFriend>`"))),
313 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::LimitedUserFriend>`")))),
314 }
315 } else {
316 let content = resp.text().await?;
317 let entity: Option<GetFriendsError> = serde_json::from_str(&content).ok();
318 Err(Error::ResponseError(ResponseContent {
319 status,
320 content,
321 entity,
322 }))
323 }
324}
325
326pub async fn unfriend(
328 configuration: &configuration::Configuration,
329 user_id: &str,
330) -> Result<models::Success, Error<UnfriendError>> {
331 let p_path_user_id = user_id;
333
334 let uri_str = format!(
335 "{}/auth/user/friends/{userId}",
336 configuration.base_path,
337 userId = crate::apis::urlencode(p_path_user_id)
338 );
339 let mut req_builder = configuration
340 .client
341 .request(reqwest::Method::DELETE, &uri_str);
342
343 if let Some(ref user_agent) = configuration.user_agent {
344 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
345 }
346
347 let req = req_builder.build()?;
348 let resp = configuration.client.execute(req).await?;
349
350 let status = resp.status();
351 let content_type = resp
352 .headers()
353 .get("content-type")
354 .and_then(|v| v.to_str().ok())
355 .unwrap_or("application/octet-stream");
356 let content_type = super::ContentType::from(content_type);
357
358 if !status.is_client_error() && !status.is_server_error() {
359 let content = resp.text().await?;
360 match content_type {
361 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
362 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Success`"))),
363 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::Success`")))),
364 }
365 } else {
366 let content = resp.text().await?;
367 let entity: Option<UnfriendError> = serde_json::from_str(&content).ok();
368 Err(Error::ResponseError(ResponseContent {
369 status,
370 content,
371 entity,
372 }))
373 }
374}