lighter-rust 0.2.0

A comprehensive Rust SDK for the Lighter trading platform with async/await, WebSocket support, and Ethereum wallet integration
/*
 *
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document:
 *
 * Generated by: https://openapi-generator.tech
 */

use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};

/// struct for typed errors of method [`notification_ack`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum NotificationAckError {
    Status400(models::ResultCode),
    UnknownValue(serde_json::Value),
}

/// Ack notification
pub async fn notification_ack(
    configuration: &configuration::Configuration,
    notif_id: &str,
    account_index: i64,
    authorization: Option<&str>,
    auth: Option<&str>,
) -> Result<models::ResultCode, Error<NotificationAckError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_form_notif_id = notif_id;
    let p_form_account_index = account_index;
    let p_header_authorization = authorization;
    let p_form_auth = auth;

    let uri_str = format!("{}/api/v1/notification/ack", 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(param_value) = p_header_authorization {
        req_builder = req_builder.header("authorization", param_value.to_string());
    }
    let mut multipart_form = reqwest::multipart::Form::new();
    multipart_form = multipart_form.text("notif_id", p_form_notif_id.to_string());
    if let Some(param_value) = p_form_auth {
        multipart_form = multipart_form.text("auth", param_value.to_string());
    }
    multipart_form = multipart_form.text("account_index", p_form_account_index.to_string());
    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::ResultCode`"))),
            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::ResultCode`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<NotificationAckError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}