/*
* Fox API
*
* Warning: Please add a custom user agent header to your requests. This would help us fighting against DDoS attacks in future, while keeping your application's access to the API. In future, this may be a mandatory requirement. To reduce the system load, the API endpoints are rate limited. The default limit is 30 requests per minute. Contact admin@orangefox.tech if you need a higher limit. The requests may be logged for analytics and development purposes.
*
* The version of the OpenAPI document: 6.0.2
* Contact: admin@orangefox.tech
* 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 [`download_release`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DownloadReleaseError {
Status400(models::ErrorResponse),
Status404(models::ErrorResponse),
Status429(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_release`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetReleaseError {
Status404(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_release_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetReleaseByIdError {
Status400(models::ErrorResponse),
Status404(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_updates_after`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetUpdatesAfterError {
Status400(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_releases`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListReleasesError {
Status404(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// The API hosts release binaries itself (acting as its own mirror). Each successful download is recorded in the `stats` collection.
pub async fn download_release(configuration: &configuration::Configuration, release_id: &str) -> Result<(), Error<DownloadReleaseError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_release_id = release_id;
let uri_str = format!("{}/release/{release_id}/dl", configuration.base_path, release_id=crate::apis::urlencode(p_path_release_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();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DownloadReleaseError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_release(configuration: &configuration::Configuration, id: Option<&str>, _id: Option<&str>, build_id: Option<&str>, filename: Option<&str>) -> Result<models::ReleaseResponse, Error<GetReleaseError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_id = id;
let p_query__id = _id;
let p_query_build_id = build_id;
let p_query_filename = filename;
let uri_str = format!("{}/releases/get", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_id {
req_builder = req_builder.query(&[("id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query__id {
req_builder = req_builder.query(&[("_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_build_id {
req_builder = req_builder.query(&[("build_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_filename {
req_builder = req_builder.query(&[("filename", ¶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::ReleaseResponse`"))),
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::ReleaseResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetReleaseError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_release_by_id(configuration: &configuration::Configuration, release_id: &str) -> Result<models::ReleaseResponse, Error<GetReleaseByIdError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_release_id = release_id;
let uri_str = format!("{}/releases/{release_id}", configuration.base_path, release_id=crate::apis::urlencode(p_path_release_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::ReleaseResponse`"))),
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::ReleaseResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetReleaseByIdError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns all non-archived releases that were created after the specified release's date.
pub async fn get_updates_after(configuration: &configuration::Configuration, last_known_id: &str) -> Result<models::ListResponseReleaseResponse, Error<GetUpdatesAfterError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_last_known_id = last_known_id;
let uri_str = format!("{}/updates/{last_known_id}", configuration.base_path, last_known_id=crate::apis::urlencode(p_path_last_known_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::ListResponseReleaseResponse`"))),
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::ListResponseReleaseResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetUpdatesAfterError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_releases(configuration: &configuration::Configuration, id: Option<&str>, _id: Option<&str>, build_id: Option<&str>, device_id: Option<&str>, maintainer_id: Option<&str>, codename: Option<&str>, version: Option<&str>, r#type: Option<&str>, archived: Option<bool>, freezed: Option<bool>, after_release_id: Option<&str>, after_date: Option<i64>, sort: Option<&str>, group: Option<bool>, skip: Option<i64>, limit: Option<i64>) -> Result<models::ListResponseReleaseResponse, Error<ListReleasesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_id = id;
let p_query__id = _id;
let p_query_build_id = build_id;
let p_query_device_id = device_id;
let p_query_maintainer_id = maintainer_id;
let p_query_codename = codename;
let p_query_version = version;
let p_query_type = r#type;
let p_query_archived = archived;
let p_query_freezed = freezed;
let p_query_after_release_id = after_release_id;
let p_query_after_date = after_date;
let p_query_sort = sort;
let p_query_group = group;
let p_query_skip = skip;
let p_query_limit = limit;
let uri_str = format!("{}/releases", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_id {
req_builder = req_builder.query(&[("id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query__id {
req_builder = req_builder.query(&[("_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_build_id {
req_builder = req_builder.query(&[("build_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_device_id {
req_builder = req_builder.query(&[("device_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_maintainer_id {
req_builder = req_builder.query(&[("maintainer_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_codename {
req_builder = req_builder.query(&[("codename", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_version {
req_builder = req_builder.query(&[("version", ¶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_archived {
req_builder = req_builder.query(&[("archived", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_freezed {
req_builder = req_builder.query(&[("freezed", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_after_release_id {
req_builder = req_builder.query(&[("after_release_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_after_date {
req_builder = req_builder.query(&[("after_date", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sort {
req_builder = req_builder.query(&[("sort", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_group {
req_builder = req_builder.query(&[("group", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_skip {
req_builder = req_builder.query(&[("skip", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶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::ListResponseReleaseResponse`"))),
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::ListResponseReleaseResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListReleasesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}