foxclient 6.0.2

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.
Documentation
/*
 * 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 [`get_device`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDeviceError {
    Status404(models::ErrorResponse),
    Status500(models::ErrorResponse),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_device_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDeviceByIdError {
    Status400(models::ErrorResponse),
    Status404(models::ErrorResponse),
    Status500(models::ErrorResponse),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_oems`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetOemsError {
    Status500(models::ErrorResponse),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`list_devices`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListDevicesError {
    Status404(models::ErrorResponse),
    Status500(models::ErrorResponse),
    UnknownValue(serde_json::Value),
}


pub async fn get_device(configuration: &configuration::Configuration, device_id: Option<&str>, codename: Option<&str>, _id: Option<&str>) -> Result<models::DeviceResponse, Error<GetDeviceError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_device_id = device_id;
    let p_query_codename = codename;
    let p_query__id = _id;

    let uri_str = format!("{}/devices/get", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_device_id {
        req_builder = req_builder.query(&[("device_id", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_codename {
        req_builder = req_builder.query(&[("codename", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query__id {
        req_builder = req_builder.query(&[("_id", &param_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::DeviceResponse`"))),
            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::DeviceResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetDeviceError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn get_device_by_id(configuration: &configuration::Configuration, device_id: &str) -> Result<models::DeviceResponse, Error<GetDeviceByIdError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_device_id = device_id;

    let uri_str = format!("{}/devices/{device_id}", configuration.base_path, device_id=crate::apis::urlencode(p_path_device_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::DeviceResponse`"))),
            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::DeviceResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetDeviceByIdError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn get_oems(configuration: &configuration::Configuration, ) -> Result<models::ListResponseString, Error<GetOemsError>> {

    let uri_str = format!("{}/oems", 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::ListResponseString`"))),
            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::ListResponseString`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetOemsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

pub async fn list_devices(configuration: &configuration::Configuration, id: Option<&str>, _id: Option<&str>, oem_name: Option<&str>, codename: Option<&str>, model_name: Option<&str>, supported: Option<bool>, maintainer: Option<&str>, freezed: Option<bool>, has_releases: Option<bool>, skip: Option<i64>, limit: Option<i64>) -> Result<models::ListResponseShortDeviceResponse, Error<ListDevicesError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_id = id;
    let p_query__id = _id;
    let p_query_oem_name = oem_name;
    let p_query_codename = codename;
    let p_query_model_name = model_name;
    let p_query_supported = supported;
    let p_query_maintainer = maintainer;
    let p_query_freezed = freezed;
    let p_query_has_releases = has_releases;
    let p_query_skip = skip;
    let p_query_limit = limit;

    let uri_str = format!("{}/devices", 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", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query__id {
        req_builder = req_builder.query(&[("_id", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_oem_name {
        req_builder = req_builder.query(&[("oem_name", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_codename {
        req_builder = req_builder.query(&[("codename", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_model_name {
        req_builder = req_builder.query(&[("model_name", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_supported {
        req_builder = req_builder.query(&[("supported", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_maintainer {
        req_builder = req_builder.query(&[("maintainer", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_freezed {
        req_builder = req_builder.query(&[("freezed", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_has_releases {
        req_builder = req_builder.query(&[("has_releases", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_skip {
        req_builder = req_builder.query(&[("skip", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_limit {
        req_builder = req_builder.query(&[("limit", &param_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::ListResponseShortDeviceResponse`"))),
            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::ListResponseShortDeviceResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<ListDevicesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}