use crate::apis::configuration::Configuration;
use crate::apis::{urlencode, Error, ResponseContent};
use crate::models::v2::community::{CategoryListResponse, ListResponse, PackageList};
use crate::models::v2::package;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CategoryListError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PackageDetailsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListPackagesError {
UnknownValue(serde_json::Value),
}
pub async fn list_categories(
configuration: &Configuration,
community: &str,
cursor: Option<&str>,
) -> Result<CategoryListResponse, Error<CategoryListError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/experimental/community/{community}/category/",
local_var_configuration.base_path,
community = urlencode(community)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(local_var_str) = cursor {
local_var_req_builder =
local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
local_var_req_builder = local_var_req_builder
.basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<CategoryListError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn list(
configuration: &Configuration,
cursor: Option<&str>,
) -> Result<ListResponse, Error<ListError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/experimental/community/",
local_var_configuration.base_path
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(local_var_str) = cursor {
local_var_req_builder =
local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
local_var_req_builder = local_var_req_builder
.basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ListError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn package_details(
configuration: &Configuration,
community_identifier: &str,
package_name: &str,
package_namespace: &str,
) -> Result<package::DetailView, Error<PackageDetailsError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/api/experimental/frontend/c/{community_identifier}/p/{package_namespace}/{package_name}/", local_var_configuration.base_path, community_identifier = urlencode(community_identifier), package_name = urlencode(package_name), package_namespace = urlencode(package_namespace));
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
local_var_req_builder = local_var_req_builder
.basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<PackageDetailsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn list_packages(
configuration: &Configuration,
community_identifier: &str,
) -> Result<PackageList, Error<ListPackagesError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/experimental/frontend/c/{community_identifier}/packages/",
local_var_configuration.base_path,
community_identifier = urlencode(community_identifier)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
local_var_req_builder = local_var_req_builder
.basic_auth(local_var_auth_conf.0.clone(), local_var_auth_conf.1.clone());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ListPackagesError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}