235 lines
9.8 KiB
Rust
235 lines
9.8 KiB
Rust
/*
|
|
* Gamenight
|
|
*
|
|
* Api specifaction for a Gamenight server
|
|
*
|
|
* The version of the OpenAPI document: 1.0
|
|
* Contact: dennis@brentj.es
|
|
* 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 typed errors of method [`get_gamenight`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum GetGamenightError {
|
|
Status401(models::Failure),
|
|
Status422(models::Failure),
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed errors of method [`get_gamenights`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum GetGamenightsError {
|
|
Status400(models::Failure),
|
|
Status401(models::Failure),
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed errors of method [`get_token`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum GetTokenError {
|
|
Status401(models::Failure),
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed errors of method [`post_gamenight`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum PostGamenightError {
|
|
Status401(models::Failure),
|
|
Status422(models::Failure),
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed errors of method [`post_register`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum PostRegisterError {
|
|
Status422(models::Failure),
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
|
|
pub async fn get_gamenight(configuration: &configuration::Configuration, get_gamenight_request: Option<models::GetGamenightRequest>) -> Result<models::Gamenight, Error<GetGamenightError>> {
|
|
// add a prefix to parameters to efficiently prevent name collisions
|
|
let p_get_gamenight_request = get_gamenight_request;
|
|
|
|
let uri_str = format!("{}/gamenight", 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());
|
|
}
|
|
if let Some(ref token) = configuration.bearer_access_token {
|
|
req_builder = req_builder.bearer_auth(token.to_owned());
|
|
};
|
|
req_builder = req_builder.json(&p_get_gamenight_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::Gamenight`"))),
|
|
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::Gamenight`")))),
|
|
}
|
|
} else {
|
|
let content = resp.text().await?;
|
|
let entity: Option<GetGamenightError> = serde_json::from_str(&content).ok();
|
|
Err(Error::ResponseError(ResponseContent { status, content, entity }))
|
|
}
|
|
}
|
|
|
|
/// Retrieve the list of gamenights on this gamenight server. Requires authorization.
|
|
pub async fn get_gamenights(configuration: &configuration::Configuration, ) -> Result<Vec<models::Gamenight>, Error<GetGamenightsError>> {
|
|
|
|
let uri_str = format!("{}/gamenights", 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());
|
|
}
|
|
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 `Vec<models::Gamenight>`"))),
|
|
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Gamenight>`")))),
|
|
}
|
|
} else {
|
|
let content = resp.text().await?;
|
|
let entity: Option<GetGamenightsError> = serde_json::from_str(&content).ok();
|
|
Err(Error::ResponseError(ResponseContent { status, content, entity }))
|
|
}
|
|
}
|
|
|
|
/// Submit your credentials to get a JWT-token to use with the rest of the api.
|
|
pub async fn get_token(configuration: &configuration::Configuration, login: Option<models::Login>) -> Result<models::Token, Error<GetTokenError>> {
|
|
// add a prefix to parameters to efficiently prevent name collisions
|
|
let p_login = login;
|
|
|
|
let uri_str = format!("{}/token", 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());
|
|
}
|
|
req_builder = req_builder.json(&p_login);
|
|
|
|
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::Token`"))),
|
|
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::Token`")))),
|
|
}
|
|
} else {
|
|
let content = resp.text().await?;
|
|
let entity: Option<GetTokenError> = serde_json::from_str(&content).ok();
|
|
Err(Error::ResponseError(ResponseContent { status, content, entity }))
|
|
}
|
|
}
|
|
|
|
/// Add a gamenight by providing a name and a date, only available when providing an JWT token.
|
|
pub async fn post_gamenight(configuration: &configuration::Configuration, add_gamenight_request_body: Option<models::AddGamenightRequestBody>) -> Result<(), Error<PostGamenightError>> {
|
|
// add a prefix to parameters to efficiently prevent name collisions
|
|
let p_add_gamenight_request_body = add_gamenight_request_body;
|
|
|
|
let uri_str = format!("{}/gamenight", 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());
|
|
}
|
|
if let Some(ref token) = configuration.bearer_access_token {
|
|
req_builder = req_builder.bearer_auth(token.to_owned());
|
|
};
|
|
req_builder = req_builder.json(&p_add_gamenight_request_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<PostGamenightError> = serde_json::from_str(&content).ok();
|
|
Err(Error::ResponseError(ResponseContent { status, content, entity }))
|
|
}
|
|
}
|
|
|
|
/// Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match.
|
|
pub async fn post_register(configuration: &configuration::Configuration, registration: Option<models::Registration>) -> Result<(), Error<PostRegisterError>> {
|
|
// add a prefix to parameters to efficiently prevent name collisions
|
|
let p_registration = registration;
|
|
|
|
let uri_str = format!("{}/user", 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(&p_registration);
|
|
|
|
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<PostRegisterError> = serde_json::from_str(&content).ok();
|
|
Err(Error::ResponseError(ResponseContent { status, content, entity }))
|
|
}
|
|
}
|
|
|