stadar 0.1.25

Rust SDK for the stadar.net esports data API.
/*
 * 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 [`stripe_webhook_receive`]
#[derive(Clone, Debug)]
pub struct StripeWebhookReceiveParams {
    pub body: serde_json::Value
}

/// struct for passing parameters to the method [`webhooks_create`]
#[derive(Clone, Debug)]
pub struct WebhooksCreateParams {
    pub webhook_subscription_request: models::WebhookSubscriptionRequest
}

/// struct for passing parameters to the method [`webhooks_delete`]
#[derive(Clone, Debug)]
pub struct WebhooksDeleteParams {
    pub id: i64
}

/// struct for passing parameters to the method [`webhooks_test`]
#[derive(Clone, Debug)]
pub struct WebhooksTestParams {
    pub id: i64
}


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

/// struct for typed errors of method [`webhooks_create`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WebhooksCreateError {
    Status400(models::ErrorEnvelope),
    Status402(models::ErrorEnvelope),
    Status401(models::ErrorEnvelope),
    UnknownValue(serde_json::Value),
}

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

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

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


/// Stripe subscription + invoice event ingress. Signed with the `Stripe-Signature` header; idempotent on the Stripe event id. Customers should never call this directly — it is documented here for completeness. 
pub async fn stripe_webhook_receive(configuration: &configuration::Configuration, params: StripeWebhookReceiveParams) -> Result<(), Error<StripeWebhookReceiveError>> {

    let uri_str = format!("{}/v1/webhooks/stripe", 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());
    }
    req_builder = req_builder.json(&params.body);

    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<StripeWebhookReceiveError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Registers a new webhook URL. The signing secret is generated and returned EXACTLY ONCE. Optional filters narrow the events delivered (game, league, tournament). Pro tier or higher. 
pub async fn webhooks_create(configuration: &configuration::Configuration, params: WebhooksCreateParams) -> Result<models::WebhooksCreate201Response, Error<WebhooksCreateError>> {

    let uri_str = format!("{}/v1/account/webhooks", 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());
    }
    req_builder = req_builder.json(&params.webhook_subscription_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::WebhooksCreate201Response`"))),
            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::WebhooksCreate201Response`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<WebhooksCreateError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn webhooks_delete(configuration: &configuration::Configuration, params: WebhooksDeleteParams) -> Result<(), Error<WebhooksDeleteError>> {

    let uri_str = format!("{}/v1/account/webhooks/{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<WebhooksDeleteError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Returns the calling API key's webhook subscriptions. Signing secrets are NEVER echoed; only the metadata. 
pub async fn webhooks_list(configuration: &configuration::Configuration) -> Result<models::WebhooksList200Response, Error<WebhooksListError>> {

    let uri_str = format!("{}/v1/account/webhooks", 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::WebhooksList200Response`"))),
            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::WebhooksList200Response`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<WebhooksListError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Sends a signed sample event (event type `webhook.test`) to a subscription's URL so the customer can verify their receiver is reachable + their HMAC verifier accepts the signature before wiring up production events. The endpoint always returns HTTP 200 with a `delivered` boolean — the test answers \"did your endpoint respond\", not \"did the delivery succeed\". Customer-side 4xx / 5xx / timeout / DNS failures surface as `delivered: false` in the response body. Rate-limited to one fire per webhook per 60 seconds. Test fires do not count against the customer's daily quota, do not write to the dead-letter queue, and do not appear in the subscription's `last_delivered_at` / `last_status` columns. The payload carries `\"test\": true` at the top level AND uses the `webhook.test` event type. The request also sets `X-Stadar-Test-Event: true` so receivers can route on the header before parsing the body. 
pub async fn webhooks_test(configuration: &configuration::Configuration, params: WebhooksTestParams) -> Result<models::WebhooksTest200Response, Error<WebhooksTestError>> {

    let uri_str = format!("{}/v1/webhooks/{id}/test", configuration.base_path, id=params.id);
    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());
    }

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