use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
#[derive(Clone, Debug, Default)]
pub struct PointsControllerGetTotalPointsParams {
pub season: Option<f64>,
pub epoch: Option<f64>,
}
#[derive(Clone, Debug, Default)]
pub struct PointsControllerListPointsPeriodsParams {
pub address: String,
pub season: f64,
pub epoch: f64,
}
#[derive(Clone, Debug, Default)]
pub struct PointsControllerListPointsSeasonSummariesParams {
pub address: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PointsControllerGetTotalPointsError {
Status400(models::BadRequestDto),
Status401(models::UnauthorizedDto),
Status403(models::ForbiddenDto),
Status404(models::NotFoundDto),
Status422(models::UnprocessableEntityDto),
Status429(models::TooManyRequestsDto),
Status500(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PointsControllerListPointsPeriodsError {
Status400(models::BadRequestDto),
Status401(models::UnauthorizedDto),
Status403(models::ForbiddenDto),
Status404(models::NotFoundDto),
Status422(models::UnprocessableEntityDto),
Status429(models::TooManyRequestsDto),
Status500(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PointsControllerListPointsSeasonSummariesError {
Status400(models::BadRequestDto),
Status401(models::UnauthorizedDto),
Status403(models::ForbiddenDto),
Status404(models::NotFoundDto),
Status422(models::UnprocessableEntityDto),
Status429(models::TooManyRequestsDto),
Status500(),
UnknownValue(serde_json::Value),
}
pub async fn points_controller_get_total_points(
configuration: &configuration::Configuration,
params: PointsControllerGetTotalPointsParams,
) -> Result<models::TotalPointsDto, Error<PointsControllerGetTotalPointsError>> {
let uri_str = format!("{}/v1/points/total", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = params.season {
req_builder = req_builder.query(&[("season", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.epoch {
req_builder = req_builder.query(&[("epoch", ¶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());
}
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::TotalPointsDto`"))),
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::TotalPointsDto`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PointsControllerGetTotalPointsError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn points_controller_list_points_periods(
configuration: &configuration::Configuration,
params: PointsControllerListPointsPeriodsParams,
) -> Result<models::ListOfPointsPeriodDtos, Error<PointsControllerListPointsPeriodsError>> {
let uri_str = format!("{}/v1/points", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("address", ¶ms.address.to_string())]);
req_builder = req_builder.query(&[("season", ¶ms.season.to_string())]);
req_builder = req_builder.query(&[("epoch", ¶ms.epoch.to_string())]);
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::ListOfPointsPeriodDtos`"))),
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::ListOfPointsPeriodDtos`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PointsControllerListPointsPeriodsError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn points_controller_list_points_season_summaries(
configuration: &configuration::Configuration,
params: PointsControllerListPointsSeasonSummariesParams,
) -> Result<
models::ListOfPointsSeasonSummariesDtos,
Error<PointsControllerListPointsSeasonSummariesError>,
> {
let uri_str = format!("{}/v1/points/summary", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("address", ¶ms.address.to_string())]);
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::ListOfPointsSeasonSummariesDtos`"))),
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::ListOfPointsSeasonSummariesDtos`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PointsControllerListPointsSeasonSummariesError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}