stadar 0.1.6

Rust SDK for the stadar.net esports data API.
/*
 * Stadar Esports Data API
 *
 * Read-only, betting-friendly esports data across all major competitive titles. Flat-tier pricing (no per-game gates), Polar- billed subscriptions (Merchant of Record), sandbox keys for evaluation. See https://stadar.net for tier pricing. All endpoints under `/v1/...`. The version in `info.version` matches the URL prefix; non-breaking field additions ship in `/v1`, breaking changes get a `/v2`. We commit to 24 months of `/v1` support after `/v2` ships. Times are UTC end-to-end (RFC 3339). Localization is the client's problem. Cursors are opaque base64 strings; treat them as such. 
 *
 * The version of the OpenAPI document: v1
 * Contact: api@stadar.net
 * 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};

/// struct for passing parameters to the method [`series_get`]
#[derive(Clone, Debug)]
pub struct SeriesGetParams {
    pub idslug: String,
    /// Required when path is a slug (slugs are league-scoped).
    pub league_id: Option<i64>
}

/// struct for passing parameters to the method [`series_list`]
#[derive(Clone, Debug)]
pub struct SeriesListParams {
    /// Opaque pagination cursor. Hand back the value from `meta.next_cursor` to fetch the next page. Cursors are valid for at least 24 hours; treat them as opaque strings. 
    pub cursor: Option<String>,
    /// Items per page. 1-200, default 50. (Pro+ on `/v1/matches` may request up to 10k via `?bulk=true`.)
    pub limit: Option<i32>,
    pub game: Option<String>,
    pub league_id: Option<i64>,
    pub year: Option<i32>
}

/// struct for passing parameters to the method [`series_list_matches`]
#[derive(Clone, Debug)]
pub struct SeriesListMatchesParams {
    pub idslug: String,
    /// Opaque pagination cursor. Hand back the value from `meta.next_cursor` to fetch the next page. Cursors are valid for at least 24 hours; treat them as opaque strings. 
    pub cursor: Option<String>,
    /// Items per page. 1-200, default 50. (Pro+ on `/v1/matches` may request up to 10k via `?bulk=true`.)
    pub limit: Option<i32>,
    pub status: Option<String>
}

/// struct for passing parameters to the method [`series_list_tournaments`]
#[derive(Clone, Debug)]
pub struct SeriesListTournamentsParams {
    pub idslug: String,
    /// Opaque pagination cursor. Hand back the value from `meta.next_cursor` to fetch the next page. Cursors are valid for at least 24 hours; treat them as opaque strings. 
    pub cursor: Option<String>,
    /// Items per page. 1-200, default 50. (Pro+ on `/v1/matches` may request up to 10k via `?bulk=true`.)
    pub limit: Option<i32>
}


/// struct for typed errors of method [`series_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SeriesGetError {
    Status404(models::ErrorEnvelope),
    UnknownValue(serde_json::Value),
}

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

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

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


pub async fn series_get(configuration: &configuration::Configuration, params: SeriesGetParams) -> Result<models::SeriesEnvelope, Error<SeriesGetError>> {

    let uri_str = format!("{}/v1/series/{idslug}", configuration.base_path, idslug=crate::apis::urlencode(params.idslug));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = params.league_id {
        req_builder = req_builder.query(&[("league_id", &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::SeriesEnvelope`"))),
            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::SeriesEnvelope`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SeriesGetError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn series_list(configuration: &configuration::Configuration, params: SeriesListParams) -> Result<models::SeriesListResponse, Error<SeriesListError>> {

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

    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.limit {
        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.game {
        req_builder = req_builder.query(&[("game", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.league_id {
        req_builder = req_builder.query(&[("league_id", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.year {
        req_builder = req_builder.query(&[("year", &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::SeriesListResponse`"))),
            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::SeriesListResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SeriesListError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn series_list_matches(configuration: &configuration::Configuration, params: SeriesListMatchesParams) -> Result<models::MatchesListResponse, Error<SeriesListMatchesError>> {

    let uri_str = format!("{}/v1/series/{idslug}/matches", configuration.base_path, idslug=crate::apis::urlencode(params.idslug));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    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.limit {
        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.status {
        req_builder = req_builder.query(&[("status", &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::MatchesListResponse`"))),
            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::MatchesListResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SeriesListMatchesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn series_list_tournaments(configuration: &configuration::Configuration, params: SeriesListTournamentsParams) -> Result<models::TournamentsListResponse, Error<SeriesListTournamentsError>> {

    let uri_str = format!("{}/v1/series/{idslug}/tournaments", configuration.base_path, idslug=crate::apis::urlencode(params.idslug));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

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