use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDeviceError {
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDeviceByIdError {
Status400(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetOemsError {
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[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>> {
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", ¶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__id {
req_builder = req_builder.query(&[("_id", ¶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::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>> {
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>> {
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", ¶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_oem_name {
req_builder = req_builder.query(&[("oem_name", ¶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_model_name {
req_builder = req_builder.query(&[("model_name", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_supported {
req_builder = req_builder.query(&[("supported", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_maintainer {
req_builder = req_builder.query(&[("maintainer", ¶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_has_releases {
req_builder = req_builder.query(&[("has_releases", ¶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::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 }))
}
}