komga_sdk/apis/
current_user_api.rs1use 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 GetAuthenticationActivityForCurrentUserError {
22 Status400(models::ValidationErrorResponse),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetCurrentUserError {
30 Status400(models::ValidationErrorResponse),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum UpdatePasswordForCurrentUserError {
38 Status400(models::ValidationErrorResponse),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn get_authentication_activity_for_current_user(configuration: &configuration::Configuration, unpaged: Option<bool>, page: Option<i32>, size: Option<i32>, sort: Option<Vec<String>>) -> Result<models::PageAuthenticationActivityDto, Error<GetAuthenticationActivityForCurrentUserError>> {
44 let p_query_unpaged = unpaged;
46 let p_query_page = page;
47 let p_query_size = size;
48 let p_query_sort = sort;
49
50 let uri_str = format!("{}/api/v2/users/me/authentication-activity", configuration.base_path);
51 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
52
53 if let Some(ref param_value) = p_query_unpaged {
54 req_builder = req_builder.query(&[("unpaged", ¶m_value.to_string())]);
55 }
56 if let Some(ref param_value) = p_query_page {
57 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
58 }
59 if let Some(ref param_value) = p_query_size {
60 req_builder = req_builder.query(&[("size", ¶m_value.to_string())]);
61 }
62 if let Some(ref param_value) = p_query_sort {
63 req_builder = match "multi" {
64 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("sort".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
65 _ => req_builder.query(&[("sort", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
66 };
67 }
68 if let Some(ref user_agent) = configuration.user_agent {
69 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
70 }
71 if let Some(ref apikey) = configuration.api_key {
72 let key = apikey.key.clone();
73 let value = match apikey.prefix {
74 Some(ref prefix) => format!("{} {}", prefix, key),
75 None => key,
76 };
77 req_builder = req_builder.header("X-API-Key", value);
78 };
79 if let Some(ref auth_conf) = configuration.basic_auth {
80 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
81 };
82
83 let req = req_builder.build()?;
84 let resp = configuration.client.execute(req).await?;
85
86 let status = resp.status();
87 let content_type = resp
88 .headers()
89 .get("content-type")
90 .and_then(|v| v.to_str().ok())
91 .unwrap_or("application/octet-stream");
92 let content_type = super::ContentType::from(content_type);
93
94 if !status.is_client_error() && !status.is_server_error() {
95 let content = resp.text().await?;
96 match content_type {
97 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
98 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PageAuthenticationActivityDto`"))),
99 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::PageAuthenticationActivityDto`")))),
100 }
101 } else {
102 let content = resp.text().await?;
103 let entity: Option<GetAuthenticationActivityForCurrentUserError> = serde_json::from_str(&content).ok();
104 Err(Error::ResponseError(ResponseContent { status, content, entity }))
105 }
106}
107
108pub async fn get_current_user(configuration: &configuration::Configuration, remember_me: Option<bool>) -> Result<models::UserDto, Error<GetCurrentUserError>> {
109 let p_query_remember_me = remember_me;
111
112 let uri_str = format!("{}/api/v2/users/me", configuration.base_path);
113 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
114
115 if let Some(ref param_value) = p_query_remember_me {
116 req_builder = req_builder.query(&[("remember-me", ¶m_value.to_string())]);
117 }
118 if let Some(ref user_agent) = configuration.user_agent {
119 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
120 }
121 if let Some(ref apikey) = configuration.api_key {
122 let key = apikey.key.clone();
123 let value = match apikey.prefix {
124 Some(ref prefix) => format!("{} {}", prefix, key),
125 None => key,
126 };
127 req_builder = req_builder.header("X-API-Key", value);
128 };
129 if let Some(ref auth_conf) = configuration.basic_auth {
130 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
131 };
132
133 let req = req_builder.build()?;
134 let resp = configuration.client.execute(req).await?;
135
136 let status = resp.status();
137 let content_type = resp
138 .headers()
139 .get("content-type")
140 .and_then(|v| v.to_str().ok())
141 .unwrap_or("application/octet-stream");
142 let content_type = super::ContentType::from(content_type);
143
144 if !status.is_client_error() && !status.is_server_error() {
145 let content = resp.text().await?;
146 match content_type {
147 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
148 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserDto`"))),
149 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::UserDto`")))),
150 }
151 } else {
152 let content = resp.text().await?;
153 let entity: Option<GetCurrentUserError> = serde_json::from_str(&content).ok();
154 Err(Error::ResponseError(ResponseContent { status, content, entity }))
155 }
156}
157
158pub async fn update_password_for_current_user(configuration: &configuration::Configuration, password_update_dto: models::PasswordUpdateDto) -> Result<(), Error<UpdatePasswordForCurrentUserError>> {
159 let p_body_password_update_dto = password_update_dto;
161
162 let uri_str = format!("{}/api/v2/users/me/password", configuration.base_path);
163 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
164
165 if let Some(ref user_agent) = configuration.user_agent {
166 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
167 }
168 if let Some(ref apikey) = configuration.api_key {
169 let key = apikey.key.clone();
170 let value = match apikey.prefix {
171 Some(ref prefix) => format!("{} {}", prefix, key),
172 None => key,
173 };
174 req_builder = req_builder.header("X-API-Key", value);
175 };
176 if let Some(ref auth_conf) = configuration.basic_auth {
177 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
178 };
179 req_builder = req_builder.json(&p_body_password_update_dto);
180
181 let req = req_builder.build()?;
182 let resp = configuration.client.execute(req).await?;
183
184 let status = resp.status();
185
186 if !status.is_client_error() && !status.is_server_error() {
187 Ok(())
188 } else {
189 let content = resp.text().await?;
190 let entity: Option<UpdatePasswordForCurrentUserError> = serde_json::from_str(&content).ok();
191 Err(Error::ResponseError(ResponseContent { status, content, entity }))
192 }
193}
194