azisaba-graph 0.1.0-rc.3

An API for connecting and sharing data across Azisaba Network.
Documentation
/*
 * Azisaba Graph API
 *
 * An API for connecting and sharing data across Azisaba Network.
 *
 * The version of the OpenAPI document: 0.0.1
 * 
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
use tokio::fs::File as TokioFile;
use tokio_util::codec::{BytesCodec, FramedRead};

/// struct for passing parameters to the method [`create_patch_note`]
#[derive(Clone, Debug)]
pub struct CreatePatchNoteParams {
    /// The target of the patch note.
    pub target: String,
    /// The category of the patch note.
    pub category: String,
    /// The title of the patch note.
    pub title: String,
    /// The body text of the patch note.
    pub body: String,
    /// The unique identifier of the player.
    pub author_id: Option<String>,
    /// The image files attached to the patch note.
    pub images: Option<Vec<std::path::PathBuf>>
}

/// struct for passing parameters to the method [`delete_patch_note_by_id`]
#[derive(Clone, Debug)]
pub struct DeletePatchNoteByIdParams {
    /// The unique identifier of the patch note.
    pub patch_note_id: String
}

/// struct for passing parameters to the method [`get_patch_note_by_id`]
#[derive(Clone, Debug)]
pub struct GetPatchNoteByIdParams {
    /// The unique identifier of the patch note.
    pub patch_note_id: String
}

/// struct for passing parameters to the method [`list_patch_notes`]
#[derive(Clone, Debug)]
pub struct ListPatchNotesParams {
    /// The maximum number of patch notes to return.
    pub limit: Option<u8>,
    /// The cursor returned by the previous request.
    pub cursor: Option<String>,
    /// The target used to filter patch notes.
    pub target: Option<String>,
    /// The category used to filter patch notes.
    pub category: Option<String>
}


/// struct for typed errors of method [`create_patch_note`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreatePatchNoteError {
    Status400(),
    Status401(),
    Status403(),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_patch_note_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeletePatchNoteByIdError {
    Status401(),
    Status403(),
    Status404(),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_patch_note_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPatchNoteByIdError {
    Status401(),
    Status403(),
    Status404(),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`list_patch_notes`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListPatchNotesError {
    Status400(),
    Status401(),
    Status403(),
    UnknownValue(serde_json::Value),
}


pub async fn create_patch_note(configuration: &configuration::Configuration, params: CreatePatchNoteParams) -> Result<models::ListPatchNotes200ResponseItemsInner, Error<CreatePatchNoteError>> {

    let uri_str = format!("{}/patch-notes", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };
    let mut multipart_form = reqwest::multipart::Form::new();
    multipart_form = multipart_form.text("target", params.target.to_string());
    multipart_form = multipart_form.text("category", params.category.to_string());
    multipart_form = multipart_form.text("title", params.title.to_string());
    multipart_form = multipart_form.text("body", params.body.to_string());
    if let Some(param_value) = params.author_id {
        multipart_form = multipart_form.text("authorId", param_value.to_string());
    }
    if let Some(ref param_value) = params.images {
                for value in param_value {
                let file = TokioFile::open(value).await?;
                let stream = FramedRead::new(file, BytesCodec::new());
                let file_name = value.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
                let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
                multipart_form = multipart_form.part("images", file_part);
                }
    }
    req_builder = req_builder.multipart(multipart_form);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListPatchNotes200ResponseItemsInner`"))),
            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::ListPatchNotes200ResponseItemsInner`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CreatePatchNoteError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn delete_patch_note_by_id(configuration: &configuration::Configuration, params: DeletePatchNoteByIdParams) -> Result<(), Error<DeletePatchNoteByIdError>> {

    let uri_str = format!("{}/patch-notes/{patchNoteId}", configuration.base_path, patchNoteId=crate::apis::urlencode(params.patch_note_id));
    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();

    if !status.is_client_error() && !status.is_server_error() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<DeletePatchNoteByIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn get_patch_note_by_id(configuration: &configuration::Configuration, params: GetPatchNoteByIdParams) -> Result<models::ListPatchNotes200ResponseItemsInner, Error<GetPatchNoteByIdError>> {

    let uri_str = format!("{}/patch-notes/{patchNoteId}", configuration.base_path, patchNoteId=crate::apis::urlencode(params.patch_note_id));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListPatchNotes200ResponseItemsInner`"))),
            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::ListPatchNotes200ResponseItemsInner`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetPatchNoteByIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn list_patch_notes(configuration: &configuration::Configuration, params: ListPatchNotesParams) -> Result<models::ListPatchNotes200Response, Error<ListPatchNotesError>> {

    let uri_str = format!("{}/patch-notes", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = params.limit {
        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.cursor {
        req_builder = req_builder.query(&[("cursor", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.target {
        req_builder = req_builder.query(&[("target", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.category {
        req_builder = req_builder.query(&[("category", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListPatchNotes200Response`"))),
            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`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<ListPatchNotesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}