/*
* 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 [`account_create_key`]
#[derive(Clone, Debug)]
pub struct AccountCreateKeyParams {
pub account_create_key_request: models::AccountCreateKeyRequest,
/// `live` (default) returns a production `esp_live_<22>` key. `sandbox` returns an `esp_test_<22>` key. Sandbox keys hit the fixture-only schema and never burn production quota.
pub mode: Option<String>
}
/// struct for passing parameters to the method [`account_delete_key`]
#[derive(Clone, Debug)]
pub struct AccountDeleteKeyParams {
pub id: i64
}
/// struct for typed errors of method [`account_create_key`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccountCreateKeyError {
Status400(models::ErrorEnvelope),
Status401(models::ErrorEnvelope),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`account_delete_key`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccountDeleteKeyError {
Status404(models::ErrorEnvelope),
Status401(models::ErrorEnvelope),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`account_list_keys`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccountListKeysError {
Status401(models::ErrorEnvelope),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`account_me_capabilities`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccountMeCapabilitiesError {
Status401(models::ErrorEnvelope),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`account_usage_recent`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccountUsageRecentError {
Status401(models::ErrorEnvelope),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`account_usage_today`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccountUsageTodayError {
Status401(models::ErrorEnvelope),
UnknownValue(serde_json::Value),
}
/// Generates a new key. The raw key is returned in the response EXACTLY ONCE — save it; subsequent calls only return the non-secret summary. Sandbox keys (`?mode=sandbox`) mint with prefix `esp_test_` and route to the curated fixture set (`esports_sandbox` schema, separate quota counter).
pub async fn account_create_key(configuration: &configuration::Configuration, params: AccountCreateKeyParams) -> Result<models::AccountCreateKey201Response, Error<AccountCreateKeyError>> {
let uri_str = format!("{}/v1/account/keys", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = params.mode {
req_builder = req_builder.query(&[("mode", ¶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());
}
req_builder = req_builder.json(¶ms.account_create_key_request);
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::AccountCreateKey201Response`"))),
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::AccountCreateKey201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccountCreateKeyError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn account_delete_key(configuration: &configuration::Configuration, params: AccountDeleteKeyParams) -> Result<(), Error<AccountDeleteKeyError>> {
let uri_str = format!("{}/v1/account/keys/{id}", configuration.base_path, id=params.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());
}
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<AccountDeleteKeyError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the non-secret summary of every active key (id, name, prefix, created_at, last_used_at). Revoked keys are excluded.
pub async fn account_list_keys(configuration: &configuration::Configuration) -> Result<models::AccountListKeys200Response, Error<AccountListKeysError>> {
let uri_str = format!("{}/v1/account/keys", configuration.base_path);
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());
}
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::AccountListKeys200Response`"))),
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::AccountListKeys200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccountListKeysError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the calling user's current tier and the list of capability tokens unlocked. SDK consumers call this to surface \"why am I getting a 402\" without guessing — the envelope's `data.capabilities` is authoritative.
pub async fn account_me_capabilities(configuration: &configuration::Configuration) -> Result<models::AccountMeCapabilities200Response, Error<AccountMeCapabilitiesError>> {
let uri_str = format!("{}/v1/account/me/capabilities", configuration.base_path);
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());
}
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::AccountMeCapabilities200Response`"))),
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::AccountMeCapabilities200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccountMeCapabilitiesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the last 50 logged requests for the calling user's API keys. Content-negotiates: `Accept: text/event-stream` upgrades to SSE; default JSON.
pub async fn account_usage_recent(configuration: &configuration::Configuration) -> Result<models::AccountUsageRecent200Response, Error<AccountUsageRecentError>> {
let uri_str = format!("{}/v1/account/usage/recent", configuration.base_path);
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());
}
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::AccountUsageRecent200Response`"))),
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::AccountUsageRecent200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccountUsageRecentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns `{count, quota, pct, tier, resets_at_utc}` for the current UTC day. Reads the Redis counter the Quota middleware writes — same source of truth as the rate limiter.
pub async fn account_usage_today(configuration: &configuration::Configuration) -> Result<models::UsageToday, Error<AccountUsageTodayError>> {
let uri_str = format!("{}/v1/account/usage/today", configuration.base_path);
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());
}
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::UsageToday`"))),
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::UsageToday`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccountUsageTodayError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}