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 [`referral_points`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ReferralPointsError {
    Status400(models::ResultCode),
    UnknownValue(serde_json::Value),
}

/// Get referral points
pub async fn referral_points(
    configuration: &configuration::Configuration,
    account_index: i64,
    authorization: Option<&str>,
    auth: Option<&str>,
) -> Result<models::ReferralPoints, Error<ReferralPointsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_account_index = account_index;
    let p_header_authorization = authorization;
    let p_query_auth = auth;

    let uri_str = format!("{}/api/v1/referral/points", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_auth {
        req_builder = req_builder.query(&[("auth", &param_value.to_string())]);
    }
    req_builder = req_builder.query(&[("account_index", &p_query_account_index.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(param_value) = p_header_authorization {
        req_builder = req_builder.header("authorization", param_value.to_string());
    }

    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::ReferralPoints`"))),
            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::ReferralPoints`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<ReferralPointsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}