/*
* Stadar Esports Data API
*
* Read-only esports data across all major competitive titles. Flat-tier pricing (no per-game gates), monthly subscriptions, 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 [`players_get`]
#[derive(Clone, Debug)]
pub struct PlayersGetParams {
/// Either a public ID (`player_<ulid>`, case-insensitive) or a player slug. Slugs require the `?game=` query param to scope the lookup; passing a slug without `?game=` 400s.
pub id: String,
/// Required when `id` is a slug. Ignored when `id` is a `player_<ulid>`.
pub game: Option<String>
}
/// struct for passing parameters to the method [`players_list`]
#[derive(Clone, Debug)]
pub struct PlayersListParams {
/// Items per page. 1-200, default 50. (Pro+ on `/v1/matches` may request up to 10k via `?bulk=true`.)
pub limit: Option<i32>,
/// Opaque pagination cursor. Hand back the value from `meta.paging.cursor` to fetch the next page; stop when `meta.paging.has_more` is false. Cursors are valid for at least 24 hours and signed against a per-deployment secret — treat them as opaque strings. The wire format may change in a backwards-compatible way (a future cursor will still satisfy the regex above).
pub cursor: Option<String>,
pub game: Option<String>,
/// ISO-3166-1 alpha-2 (lowercase, e.g. `kr`).
pub nationality: Option<String>,
pub role: Option<String>,
/// Case-insensitive substring match on player name, real name, or slug. Minimum 2 characters. The fastest way to resolve a player by handle or legal name.
pub search: Option<String>
}
/// struct for typed errors of method [`players_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PlayersGetError {
Status400(models::ErrorEnvelope),
Status401(models::ErrorEnvelope),
Status404(models::ErrorEnvelope),
Status429(models::ErrorEnvelope),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`players_list`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PlayersListError {
Status400(models::ErrorEnvelope),
Status401(models::ErrorEnvelope),
Status429(models::ErrorEnvelope),
UnknownValue(serde_json::Value),
}
/// Single player detail.
pub async fn players_get(configuration: &configuration::Configuration, params: PlayersGetParams) -> Result<models::PlayerEnvelope, Error<PlayersGetError>> {
let uri_str = format!("{}/v1/players/{id}", configuration.base_path, id=crate::apis::urlencode(params.id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = params.game {
req_builder = req_builder.query(&[("game", ¶m_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::PlayerEnvelope`"))),
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::PlayerEnvelope`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PlayersGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Paginated list of esports players. Filter by `?game=<slug>`, `?nationality=<iso2>`, or `?role=<text>`. Role values are free-text per-game (e.g. `top`, `jungle` for LoL; `awp`, `igl` for CS2). Available on every tier; Liquipedia-derived rows are attributed automatically in `meta.sources`.
pub async fn players_list(configuration: &configuration::Configuration, params: PlayersListParams) -> Result<models::PlayersListResponse, Error<PlayersListError>> {
let uri_str = format!("{}/v1/players", 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", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.game {
req_builder = req_builder.query(&[("game", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.nationality {
req_builder = req_builder.query(&[("nationality", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.role {
req_builder = req_builder.query(&[("role", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.search {
req_builder = req_builder.query(&[("search", ¶m_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::PlayersListResponse`"))),
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::PlayersListResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PlayersListError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}