use super::{API_KEY_HEADER, ContentType, Error, configuration};
use crate::apis::ResponseContent;
use crate::models::{self, RadarQueueHost};
use reqwest;
use serde::de::Error as _;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RadarWindProfilerError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RadarDataQueueError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RadarServerError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RadarServersError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RadarStationError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RadarStationAlarmsError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RadarStationsError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Default)]
pub struct RadarDataQueueQueryParams<'a> {
pub limit: Option<i32>,
pub arrived: Option<&'a str>,
pub created: Option<&'a str>,
pub published: Option<&'a str>,
pub station: Option<&'a str>,
pub r#type: Option<&'a str>,
pub feed: Option<&'a str>,
pub resolution: Option<i32>,
}
pub async fn get_radar_wind_profiler(
configuration: &configuration::Configuration,
id: &str,
time: Option<&str>,
interval: Option<&str>,
) -> Result<serde_json::Value, Error<RadarWindProfilerError>> {
let uri_str = format!(
"{}/radar/profilers/{id}",
configuration.base_path,
id = crate::apis::urlencode(id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(param_value) = time {
req_builder = req_builder.query(&[("time", ¶m_value.to_owned())]);
}
if let Some(param_value) = interval {
req_builder = req_builder.query(&[("interval", ¶m_value.to_owned())]);
}
if let Some(user_agent) = &configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(api_key) = &configuration.api_key {
req_builder = req_builder.header(API_KEY_HEADER, api_key.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|header| header.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 => Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `serde_json::Value`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<RadarWindProfilerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_radar_data_queue(
configuration: &configuration::Configuration,
host: &RadarQueueHost,
params: RadarDataQueueQueryParams<'_>,
) -> Result<models::RadarQueuesResponse, Error<RadarDataQueueError>> {
let uri_str = format!(
"{}/radar/queues/{host}",
configuration.base_path,
host = host
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(param_value) = params.limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(param_value) = params.arrived {
req_builder = req_builder.query(&[("arrived", ¶m_value.to_owned())]);
}
if let Some(param_value) = params.created {
req_builder = req_builder.query(&[("created", ¶m_value.to_owned())]);
}
if let Some(param_value) = params.published {
req_builder = req_builder.query(&[("published", ¶m_value.to_owned())]);
}
if let Some(param_value) = params.station {
req_builder = req_builder.query(&[("station", ¶m_value.to_owned())]);
}
if let Some(param_value) = params.r#type {
req_builder = req_builder.query(&[("type", ¶m_value.to_owned())]);
}
if let Some(param_value) = params.feed {
req_builder = req_builder.query(&[("feed", ¶m_value.to_owned())]);
}
if let Some(param_value) = params.resolution {
req_builder = req_builder.query(&[("resolution", ¶m_value.to_owned())]);
}
if let Some(user_agent) = &configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(api_key) = &configuration.api_key {
req_builder = req_builder.header(API_KEY_HEADER, api_key.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|header| header.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 => Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `RadarQueuesResponse`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `RadarQueuesResponse`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `RadarQueuesResponse`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<RadarDataQueueError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_radar_server(
configuration: &configuration::Configuration,
id: &str,
reporting_host: Option<&str>,
) -> Result<models::RadarServer, Error<RadarServerError>> {
let uri_str = format!(
"{}/radar/servers/{id}",
configuration.base_path,
id = crate::apis::urlencode(id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(param_value) = reporting_host {
req_builder = req_builder.query(&[("reportingHost", ¶m_value.to_owned())]);
}
if let Some(user_agent) = &configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(api_key) = &configuration.api_key {
req_builder = req_builder.header(API_KEY_HEADER, api_key.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|header| header.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 => Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `RadarServer`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `RadarServer`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `RadarServer`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<RadarServerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_radar_servers(
configuration: &configuration::Configuration,
reporting_host: Option<&str>,
) -> Result<models::RadarServersResponse, Error<RadarServersError>> {
let uri_str = format!("{}/radar/servers", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(param_value) = reporting_host {
req_builder = req_builder.query(&[("reportingHost", ¶m_value.to_owned())]);
}
if let Some(user_agent) = &configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(api_key) = &configuration.api_key {
req_builder = req_builder.header(API_KEY_HEADER, api_key.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|header| header.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 => Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `RadarServersResponse`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `RadarServersResponse`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `RadarServersResponse"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<RadarServersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_radar_station(
configuration: &configuration::Configuration,
id: &str,
reporting_host: Option<&str>,
host: Option<&RadarQueueHost>,
) -> Result<models::RadarStationFeature, Error<RadarStationError>> {
let uri_str = format!(
"{}/radar/stations/{id}",
configuration.base_path,
id = crate::apis::urlencode(id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(param_value) = reporting_host {
req_builder = req_builder.query(&[("reportingHost", ¶m_value.to_owned())]);
}
if let Some(param_value) = host {
req_builder = req_builder.query(&[("host", ¶m_value.to_string())]);
}
if let Some(user_agent) = &configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(api_key) = &configuration.api_key {
req_builder = req_builder.header(API_KEY_HEADER, api_key.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|header| header.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 => Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `RadarStationFeature`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `RadarStationFeature`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `RadarStationFeature`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<RadarStationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_radar_station_alarms(
configuration: &configuration::Configuration,
station_id: &str,
) -> Result<models::RadarStationAlarmsResponse, Error<RadarStationAlarmsError>> {
let uri_str = format!(
"{}/radar/stations/{stationId}/alarms",
configuration.base_path,
stationId = crate::apis::urlencode(station_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(user_agent) = &configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(api_key) = &configuration.api_key {
req_builder = req_builder.header(API_KEY_HEADER, api_key.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|header| header.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 => Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `RadarStationAlarmsResponse`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `RadarStationAlarmsResponse`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `RadarStationAlarmsResponse`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<RadarStationAlarmsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_radar_stations(
configuration: &configuration::Configuration,
station_type: Option<Vec<String>>,
reporting_host: Option<&str>,
host: Option<&RadarQueueHost>,
) -> Result<models::RadarStationsResponse, Error<RadarStationsError>> {
let uri_str = format!("{}/radar/stations", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(param_value) = station_type {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("stationType".to_owned(), param.to_owned()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"stationType",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = reporting_host {
req_builder = req_builder.query(&[("reportingHost", ¶m_value.to_owned())]);
}
if let Some(param_value) = host {
req_builder = req_builder.query(&[("host", ¶m_value.to_string())]);
}
if let Some(user_agent) = &configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(api_key) = &configuration.api_key {
req_builder = req_builder.header(API_KEY_HEADER, api_key.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|header| header.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 => Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `RadarStationsResponse`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `RadarStationsResponse`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `RadarStationsResponse`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<RadarStationsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}