Skip to main content

azisaba_graph/apis/
patch_notes_api.rs

1/*
2 * Azisaba Graph API
3 *
4 * An API for connecting and sharing data across the Azisaba Network.
5 *
6 * The version of the OpenAPI document: 0.0.1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use 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/// struct for passing parameters to the method [`create_patch_note`]
20#[derive(Clone, Debug)]
21pub struct CreatePatchNoteParams {
22    /// The target of the patch note.
23    pub target: String,
24    /// The category of the patch note.
25    pub category: String,
26    /// The title of the patch note.
27    pub title: String,
28    /// The body text of the patch note.
29    pub body: String,
30    /// The unique identifier of the player.
31    pub author_id: Option<String>,
32    /// JPEG, PNG, GIF, or WebP image files to attach to the patch note.
33    pub images: Option<Vec<std::path::PathBuf>>
34}
35
36/// struct for passing parameters to the method [`delete_patch_note_by_id`]
37#[derive(Clone, Debug)]
38pub struct DeletePatchNoteByIdParams {
39    /// The unique identifier of the patch note.
40    pub patch_note_id: String
41}
42
43/// struct for passing parameters to the method [`get_patch_note_by_id`]
44#[derive(Clone, Debug)]
45pub struct GetPatchNoteByIdParams {
46    /// The unique identifier of the patch note.
47    pub patch_note_id: String
48}
49
50/// struct for passing parameters to the method [`list_patch_notes`]
51#[derive(Clone, Debug)]
52pub struct ListPatchNotesParams {
53    /// The maximum number of patch notes to return.
54    pub limit: Option<u8>,
55    /// The cursor returned by the previous request.
56    pub cursor: Option<String>,
57    /// The target used to filter patch notes.
58    pub target: Option<String>,
59    /// The category used to filter patch notes.
60    pub category: Option<String>
61}
62
63
64/// struct for typed errors of method [`create_patch_note`]
65#[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/// struct for typed errors of method [`delete_patch_note_by_id`]
75#[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/// struct for typed errors of method [`get_patch_note_by_id`]
85#[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/// struct for typed errors of method [`list_patch_notes`]
95#[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
105/// Creates a new patch note.
106pub 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
161/// Deletes the patch note with the specified ID.
162pub 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
188/// Returns the patch note with the specified ID.
189pub 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
226/// Returns a list of patch notes.
227pub 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", &param_value.to_string())]);
234    }
235    if let Some(ref param_value) = params.cursor {
236        req_builder = req_builder.query(&[("cursor", &param_value.to_string())]);
237    }
238    if let Some(ref param_value) = params.target {
239        req_builder = req_builder.query(&[("target", &param_value.to_string())]);
240    }
241    if let Some(ref param_value) = params.category {
242        req_builder = req_builder.query(&[("category", &param_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