use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Clone, Debug)]
pub struct AcceptPlayerFriendRequestParams {
pub player_id: String,
pub sender_id: String
}
#[derive(Clone, Debug)]
pub struct AddPlayerFriendParams {
pub player_id: String,
pub friend_id: String
}
#[derive(Clone, Debug)]
pub struct AddPlayerFriendRequestParams {
pub player_id: String,
pub sender_id: String
}
#[derive(Clone, Debug)]
pub struct GetPlayerByIdParams {
pub player_id: String
}
#[derive(Clone, Debug)]
pub struct ListPlayerFriendRequestsParams {
pub player_id: String,
pub limit: Option<u8>,
pub cursor: Option<String>,
pub sender_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct ListPlayerFriendsParams {
pub player_id: String,
pub limit: Option<u8>,
pub cursor: Option<String>,
pub friend_id: Option<String>
}
#[derive(Clone, Debug)]
pub struct ListPlayersParams {
pub limit: Option<u8>,
pub cursor: Option<String>,
pub username: Option<String>,
pub discord_id: Option<String>,
pub status: Option<String>
}
#[derive(Clone, Debug)]
pub struct RejectPlayerFriendRequestParams {
pub player_id: String,
pub sender_id: String
}
#[derive(Clone, Debug)]
pub struct RemovePlayerFriendParams {
pub player_id: String,
pub friend_id: String
}
#[derive(Clone, Debug)]
pub struct RemovePlayerFriendRequestParams {
pub player_id: String,
pub sender_id: String
}
#[derive(Clone, Debug)]
pub struct UpdatePlayerByIdParams {
pub player_id: String,
pub update_player_by_id_request: models::UpdatePlayerByIdRequest
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AcceptPlayerFriendRequestError {
Status401(),
Status403(),
Status404(),
Status409(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddPlayerFriendError {
Status400(),
Status401(),
Status403(),
Status404(),
Status409(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddPlayerFriendRequestError {
Status401(),
Status403(),
Status404(),
Status409(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPlayerByIdError {
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListPlayerFriendRequestsError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListPlayerFriendsError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListPlayersError {
Status400(),
Status401(),
Status403(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RejectPlayerFriendRequestError {
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RemovePlayerFriendError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RemovePlayerFriendRequestError {
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdatePlayerByIdError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
pub async fn accept_player_friend_request(configuration: &configuration::Configuration, params: AcceptPlayerFriendRequestParams) -> Result<(), Error<AcceptPlayerFriendRequestError>> {
let uri_str = format!("{}/players/{playerId}/friend-requests/{senderId}/accept", configuration.base_path, playerId=crate::apis::urlencode(params.player_id), senderId=crate::apis::urlencode(params.sender_id));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<AcceptPlayerFriendRequestError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn add_player_friend(configuration: &configuration::Configuration, params: AddPlayerFriendParams) -> Result<models::Player, Error<AddPlayerFriendError>> {
let uri_str = format!("{}/players/{playerId}/friends/{friendId}", configuration.base_path, playerId=crate::apis::urlencode(params.player_id), friendId=crate::apis::urlencode(params.friend_id));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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 `models::Player`"))),
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::Player`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AddPlayerFriendError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn add_player_friend_request(configuration: &configuration::Configuration, params: AddPlayerFriendRequestParams) -> Result<(), Error<AddPlayerFriendRequestError>> {
let uri_str = format!("{}/players/{playerId}/friend-requests/{senderId}", configuration.base_path, playerId=crate::apis::urlencode(params.player_id), senderId=crate::apis::urlencode(params.sender_id));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<AddPlayerFriendRequestError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_player_by_id(configuration: &configuration::Configuration, params: GetPlayerByIdParams) -> Result<models::Player, Error<GetPlayerByIdError>> {
let uri_str = format!("{}/players/{playerId}", configuration.base_path, playerId=crate::apis::urlencode(params.player_id));
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 `models::Player`"))),
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::Player`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetPlayerByIdError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_player_friend_requests(configuration: &configuration::Configuration, params: ListPlayerFriendRequestsParams) -> Result<models::ListPlayers200Response, Error<ListPlayerFriendRequestsError>> {
let uri_str = format!("{}/players/{playerId}/friend-requests", configuration.base_path, playerId=crate::apis::urlencode(params.player_id));
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.sender_id {
req_builder = req_builder.query(&[("senderId", ¶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::ListPlayers200Response`"))),
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::ListPlayers200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListPlayerFriendRequestsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_player_friends(configuration: &configuration::Configuration, params: ListPlayerFriendsParams) -> Result<models::ListPlayers200Response, Error<ListPlayerFriendsError>> {
let uri_str = format!("{}/players/{playerId}/friends", configuration.base_path, playerId=crate::apis::urlencode(params.player_id));
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.friend_id {
req_builder = req_builder.query(&[("friendId", ¶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::ListPlayers200Response`"))),
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::ListPlayers200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListPlayerFriendsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_players(configuration: &configuration::Configuration, params: ListPlayersParams) -> Result<models::ListPlayers200Response, Error<ListPlayersError>> {
let uri_str = format!("{}/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.username {
req_builder = req_builder.query(&[("username", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.discord_id {
req_builder = req_builder.query(&[("discordId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.status {
req_builder = req_builder.query(&[("status", ¶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::ListPlayers200Response`"))),
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::ListPlayers200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListPlayersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn reject_player_friend_request(configuration: &configuration::Configuration, params: RejectPlayerFriendRequestParams) -> Result<(), Error<RejectPlayerFriendRequestError>> {
let uri_str = format!("{}/players/{playerId}/friend-requests/{senderId}/reject", configuration.base_path, playerId=crate::apis::urlencode(params.player_id), senderId=crate::apis::urlencode(params.sender_id));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<RejectPlayerFriendRequestError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn remove_player_friend(configuration: &configuration::Configuration, params: RemovePlayerFriendParams) -> Result<(), Error<RemovePlayerFriendError>> {
let uri_str = format!("{}/players/{playerId}/friends/{friendId}", configuration.base_path, playerId=crate::apis::urlencode(params.player_id), friendId=crate::apis::urlencode(params.friend_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());
}
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();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<RemovePlayerFriendError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn remove_player_friend_request(configuration: &configuration::Configuration, params: RemovePlayerFriendRequestParams) -> Result<(), Error<RemovePlayerFriendRequestError>> {
let uri_str = format!("{}/players/{playerId}/friend-requests/{senderId}", configuration.base_path, playerId=crate::apis::urlencode(params.player_id), senderId=crate::apis::urlencode(params.sender_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());
}
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();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<RemovePlayerFriendRequestError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn update_player_by_id(configuration: &configuration::Configuration, params: UpdatePlayerByIdParams) -> Result<models::Player, Error<UpdatePlayerByIdError>> {
let uri_str = format!("{}/players/{playerId}", configuration.base_path, playerId=crate::apis::urlencode(params.player_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &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(¶ms.update_player_by_id_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::Player`"))),
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::Player`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdatePlayerByIdError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}