use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddFavoriteError {
Status400(models::Error),
Status403(models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ClearFavoriteGroupError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFavoriteGroupError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFavoriteGroupsError {
Status401(models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFavoriteLimitsError {
Status401(models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFavoritesError {
Status401(models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RemoveFavoriteError {
Status401(models::Error),
Status404(models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateFavoriteGroupError {
UnknownValue(serde_json::Value),
}
pub async fn add_favorite(
configuration: &configuration::Configuration,
add_favorite_request: Option<models::AddFavoriteRequest>,
) -> Result<models::Favorite, Error<AddFavoriteError>> {
let p_body_add_favorite_request = add_favorite_request;
let uri_str = format!("{}/favorites", 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_body_add_favorite_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::Favorite`"))),
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::Favorite`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AddFavoriteError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn clear_favorite_group(
configuration: &configuration::Configuration,
favorite_group_type: models::FavoriteType,
favorite_group_name: &str,
user_id: &str,
) -> Result<models::Success, Error<ClearFavoriteGroupError>> {
let p_path_favorite_group_type = favorite_group_type;
let p_path_favorite_group_name = favorite_group_name;
let p_path_user_id = user_id;
let uri_str = format!(
"{}/favorite/group/{favoriteGroupType}/{favoriteGroupName}/{userId}",
configuration.base_path,
favoriteGroupType = p_path_favorite_group_type.to_string(),
favoriteGroupName = crate::apis::urlencode(p_path_favorite_group_name),
userId = crate::apis::urlencode(p_path_user_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();
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::Success`"))),
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::Success`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ClearFavoriteGroupError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_favorite_group(
configuration: &configuration::Configuration,
favorite_group_type: models::FavoriteType,
favorite_group_name: &str,
user_id: &str,
) -> Result<models::FavoriteGroup, Error<GetFavoriteGroupError>> {
let p_path_favorite_group_type = favorite_group_type;
let p_path_favorite_group_name = favorite_group_name;
let p_path_user_id = user_id;
let uri_str = format!(
"{}/favorite/group/{favoriteGroupType}/{favoriteGroupName}/{userId}",
configuration.base_path,
favoriteGroupType = p_path_favorite_group_type.to_string(),
favoriteGroupName = crate::apis::urlencode(p_path_favorite_group_name),
userId = crate::apis::urlencode(p_path_user_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());
}
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::FavoriteGroup`"))),
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::FavoriteGroup`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFavoriteGroupError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_favorite_groups(
configuration: &configuration::Configuration,
n: Option<i32>,
offset: Option<i32>,
user_id: Option<&str>,
owner_id: Option<&str>,
) -> Result<Vec<models::FavoriteGroup>, Error<GetFavoriteGroupsError>> {
let p_query_n = n;
let p_query_offset = offset;
let p_query_user_id = user_id;
let p_query_owner_id = owner_id;
let uri_str = format!("{}/favorite/groups", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_n {
req_builder = req_builder.query(&[("n", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_user_id {
req_builder = req_builder.query(&[("userId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_owner_id {
req_builder = req_builder.query(&[("ownerId", ¶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 `Vec<models::FavoriteGroup>`"))),
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::FavoriteGroup>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFavoriteGroupsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_favorite_limits(
configuration: &configuration::Configuration,
) -> Result<models::FavoriteLimits, Error<GetFavoriteLimitsError>> {
let uri_str = format!("{}/auth/user/favoritelimits", 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::FavoriteLimits`"))),
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::FavoriteLimits`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFavoriteLimitsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_favorites(
configuration: &configuration::Configuration,
n: Option<i32>,
offset: Option<i32>,
r#type: Option<&str>,
tag: Option<&str>,
) -> Result<Vec<models::Favorite>, Error<GetFavoritesError>> {
let p_query_n = n;
let p_query_offset = offset;
let p_query_type = r#type;
let p_query_tag = tag;
let uri_str = format!("{}/favorites", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_n {
req_builder = req_builder.query(&[("n", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_type {
req_builder = req_builder.query(&[("type", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_tag {
req_builder = req_builder.query(&[("tag", ¶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 `Vec<models::Favorite>`"))),
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::Favorite>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFavoritesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn remove_favorite(
configuration: &configuration::Configuration,
favorite_id: &str,
) -> Result<models::Success, Error<RemoveFavoriteError>> {
let p_path_favorite_id = favorite_id;
let uri_str = format!(
"{}/favorites/{favoriteId}",
configuration.base_path,
favoriteId = crate::apis::urlencode(p_path_favorite_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();
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::Success`"))),
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::Success`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<RemoveFavoriteError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn update_favorite_group(
configuration: &configuration::Configuration,
favorite_group_type: models::FavoriteType,
favorite_group_name: &str,
user_id: &str,
update_favorite_group_request: Option<models::UpdateFavoriteGroupRequest>,
) -> Result<(), Error<UpdateFavoriteGroupError>> {
let p_path_favorite_group_type = favorite_group_type;
let p_path_favorite_group_name = favorite_group_name;
let p_path_user_id = user_id;
let p_body_update_favorite_group_request = update_favorite_group_request;
let uri_str = format!(
"{}/favorite/group/{favoriteGroupType}/{favoriteGroupName}/{userId}",
configuration.base_path,
favoriteGroupType = p_path_favorite_group_type.to_string(),
favoriteGroupName = crate::apis::urlencode(p_path_favorite_group_name),
userId = crate::apis::urlencode(p_path_user_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());
}
req_builder = req_builder.json(&p_body_update_favorite_group_request);
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<UpdateFavoriteGroupError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}