1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16use tokio::fs::File as TokioFile;
17use tokio_util::codec::{BytesCodec, FramedRead};
18
19#[derive(Clone, Debug)]
21pub struct CreatePatchNoteParams {
22 pub target: String,
24 pub category: String,
26 pub title: String,
28 pub body: String,
30 pub author_id: Option<String>,
32 pub images: Option<Vec<std::path::PathBuf>>
34}
35
36#[derive(Clone, Debug)]
38pub struct DeletePatchNoteByIdParams {
39 pub patch_note_id: String
41}
42
43#[derive(Clone, Debug)]
45pub struct GetPatchNoteByIdParams {
46 pub patch_note_id: String
48}
49
50#[derive(Clone, Debug)]
52pub struct ListPatchNotesParams {
53 pub limit: Option<u8>,
55 pub cursor: Option<String>,
57 pub target: Option<String>,
59 pub category: Option<String>
61}
62
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum CreatePatchNoteError {
68 Status400(),
69 Status401(),
70 Status403(),
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum DeletePatchNoteByIdError {
78 Status401(),
79 Status403(),
80 Status404(),
81 UnknownValue(serde_json::Value),
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum GetPatchNoteByIdError {
88 Status401(),
89 Status403(),
90 Status404(),
91 UnknownValue(serde_json::Value),
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum ListPatchNotesError {
98 Status400(),
99 Status401(),
100 Status403(),
101 UnknownValue(serde_json::Value),
102}
103
104
105pub async fn create_patch_note(configuration: &configuration::Configuration, params: CreatePatchNoteParams) -> Result<models::PatchNote, Error<CreatePatchNoteError>> {
107
108 let uri_str = format!("{}/patch-notes", configuration.base_path);
109 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
110
111 if let Some(ref user_agent) = configuration.user_agent {
112 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
113 }
114 if let Some(ref token) = configuration.bearer_access_token {
115 req_builder = req_builder.bearer_auth(token.to_owned());
116 };
117 let mut multipart_form = reqwest::multipart::Form::new();
118 multipart_form = multipart_form.text("target", params.target.to_string());
119 multipart_form = multipart_form.text("category", params.category.to_string());
120 multipart_form = multipart_form.text("title", params.title.to_string());
121 multipart_form = multipart_form.text("body", params.body.to_string());
122 if let Some(param_value) = params.author_id {
123 multipart_form = multipart_form.text("authorId", param_value.to_string());
124 }
125 if let Some(ref param_value) = params.images {
126 for value in param_value {
127 let file = TokioFile::open(value).await?;
128 let stream = FramedRead::new(file, BytesCodec::new());
129 let file_name = value.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
130 let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
131 multipart_form = multipart_form.part("images", file_part);
132 }
133 }
134 req_builder = req_builder.multipart(multipart_form);
135
136 let req = req_builder.build()?;
137 let resp = configuration.client.execute(req).await?;
138
139 let status = resp.status();
140 let content_type = resp
141 .headers()
142 .get("content-type")
143 .and_then(|v| v.to_str().ok())
144 .unwrap_or("application/octet-stream");
145 let content_type = super::ContentType::from(content_type);
146
147 if !status.is_client_error() && !status.is_server_error() {
148 let content = resp.text().await?;
149 match content_type {
150 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
151 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PatchNote`"))),
152 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::PatchNote`")))),
153 }
154 } else {
155 let content = resp.text().await?;
156 let entity: Option<CreatePatchNoteError> = serde_json::from_str(&content).ok();
157 Err(Error::ResponseError(ResponseContent { status, content, entity }))
158 }
159}
160
161pub async fn delete_patch_note_by_id(configuration: &configuration::Configuration, params: DeletePatchNoteByIdParams) -> Result<(), Error<DeletePatchNoteByIdError>> {
163
164 let uri_str = format!("{}/patch-notes/{patchNoteId}", configuration.base_path, patchNoteId=crate::apis::urlencode(params.patch_note_id));
165 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
166
167 if let Some(ref user_agent) = configuration.user_agent {
168 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
169 }
170 if let Some(ref token) = configuration.bearer_access_token {
171 req_builder = req_builder.bearer_auth(token.to_owned());
172 };
173
174 let req = req_builder.build()?;
175 let resp = configuration.client.execute(req).await?;
176
177 let status = resp.status();
178
179 if !status.is_client_error() && !status.is_server_error() {
180 Ok(())
181 } else {
182 let content = resp.text().await?;
183 let entity: Option<DeletePatchNoteByIdError> = serde_json::from_str(&content).ok();
184 Err(Error::ResponseError(ResponseContent { status, content, entity }))
185 }
186}
187
188pub async fn get_patch_note_by_id(configuration: &configuration::Configuration, params: GetPatchNoteByIdParams) -> Result<models::PatchNote, Error<GetPatchNoteByIdError>> {
190
191 let uri_str = format!("{}/patch-notes/{patchNoteId}", configuration.base_path, patchNoteId=crate::apis::urlencode(params.patch_note_id));
192 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
193
194 if let Some(ref user_agent) = configuration.user_agent {
195 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
196 }
197 if let Some(ref token) = configuration.bearer_access_token {
198 req_builder = req_builder.bearer_auth(token.to_owned());
199 };
200
201 let req = req_builder.build()?;
202 let resp = configuration.client.execute(req).await?;
203
204 let status = resp.status();
205 let content_type = resp
206 .headers()
207 .get("content-type")
208 .and_then(|v| v.to_str().ok())
209 .unwrap_or("application/octet-stream");
210 let content_type = super::ContentType::from(content_type);
211
212 if !status.is_client_error() && !status.is_server_error() {
213 let content = resp.text().await?;
214 match content_type {
215 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
216 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PatchNote`"))),
217 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::PatchNote`")))),
218 }
219 } else {
220 let content = resp.text().await?;
221 let entity: Option<GetPatchNoteByIdError> = serde_json::from_str(&content).ok();
222 Err(Error::ResponseError(ResponseContent { status, content, entity }))
223 }
224}
225
226pub async fn list_patch_notes(configuration: &configuration::Configuration, params: ListPatchNotesParams) -> Result<models::ListPatchNotes200Response, Error<ListPatchNotesError>> {
228
229 let uri_str = format!("{}/patch-notes", configuration.base_path);
230 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
231
232 if let Some(ref param_value) = params.limit {
233 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
234 }
235 if let Some(ref param_value) = params.cursor {
236 req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
237 }
238 if let Some(ref param_value) = params.target {
239 req_builder = req_builder.query(&[("target", ¶m_value.to_string())]);
240 }
241 if let Some(ref param_value) = params.category {
242 req_builder = req_builder.query(&[("category", ¶m_value.to_string())]);
243 }
244 if let Some(ref user_agent) = configuration.user_agent {
245 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
246 }
247 if let Some(ref token) = configuration.bearer_access_token {
248 req_builder = req_builder.bearer_auth(token.to_owned());
249 };
250
251 let req = req_builder.build()?;
252 let resp = configuration.client.execute(req).await?;
253
254 let status = resp.status();
255 let content_type = resp
256 .headers()
257 .get("content-type")
258 .and_then(|v| v.to_str().ok())
259 .unwrap_or("application/octet-stream");
260 let content_type = super::ContentType::from(content_type);
261
262 if !status.is_client_error() && !status.is_server_error() {
263 let content = resp.text().await?;
264 match content_type {
265 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
266 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListPatchNotes200Response`"))),
267 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::ListPatchNotes200Response`")))),
268 }
269 } else {
270 let content = resp.text().await?;
271 let entity: Option<ListPatchNotesError> = serde_json::from_str(&content).ok();
272 Err(Error::ResponseError(ResponseContent { status, content, entity }))
273 }
274}
275