use super::{API_KEY_HEADER, ContentType, Error, configuration};
use crate::apis::ResponseContent;
use crate::models;
use reqwest;
use serde::de::Error as _;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CenterWeatherAdvisoryError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CenterWeatherAdvisoryCollectionError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CenterWeatherServiceUnitError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SigmetError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SigmetQueryError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SigmetsByAtsuError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SigmetsByAtsuAndDateError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
pub async fn get_center_weather_advisories_by_date_and_sequence(
configuration: &configuration::Configuration,
center_weather_service_unit_id: models::NwsCenterWeatherServiceUnitId,
date: String,
sequence: i32,
) -> Result<models::CenterWeatherAdvisoryGeoJson, Error<CenterWeatherAdvisoryError>> {
let uri_str = format!(
"{}/aviation/cwsus/{center_weather_service_unit_id}/cwas/{date}/{sequence}",
configuration.base_path,
center_weather_service_unit_id = center_weather_service_unit_id,
date = date,
sequence = sequence
);
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 `CenterWeatherAdvisoryGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `CenterWeatherAdvisoryGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `CenterWeatherAdvisoryGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<CenterWeatherAdvisoryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_center_weather_advisories(
configuration: &configuration::Configuration,
center_weather_service_unit_id: models::NwsCenterWeatherServiceUnitId,
) -> Result<
models::CenterWeatherAdvisoryCollectionGeoJson,
Error<CenterWeatherAdvisoryCollectionError>,
> {
let uri_str = format!(
"{}/aviation/cwsus/{center_weather_service_unit_id}/cwas",
configuration.base_path,
center_weather_service_unit_id = center_weather_service_unit_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 `CenterWeatherAdvisoryCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `CenterWeatherAdvisoryCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `CenterWeatherAdvisoryCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<CenterWeatherAdvisoryCollectionError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_center_weather_service_unit(
configuration: &configuration::Configuration,
center_weather_service_unit_id: models::NwsCenterWeatherServiceUnitId,
) -> Result<models::CwsuOffice, Error<CenterWeatherServiceUnitError>> {
let uri_str = format!(
"{}/aviation/cwsus/{center_weather_service_unit_id}",
configuration.base_path,
center_weather_service_unit_id = center_weather_service_unit_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 `Office`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `Office`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `Office`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<CenterWeatherServiceUnitError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_sigmet(
configuration: &configuration::Configuration,
air_traffic_service_unit: &str,
date: String,
time: &str,
) -> Result<models::SigmetGeoJson, Error<SigmetError>> {
let uri_str = format!(
"{}/aviation/sigmets/{air_traffic_service_unit}/{date}/{time}",
configuration.base_path,
air_traffic_service_unit = crate::apis::urlencode(air_traffic_service_unit),
date = date,
time = crate::apis::urlencode(time)
);
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 `SigmetGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `SigmetGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `SigmetGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<SigmetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_sigmets(
configuration: &configuration::Configuration,
start: Option<String>,
end: Option<String>,
date: Option<String>,
air_traffic_service_unit: Option<&str>,
sequence: Option<&str>,
) -> Result<models::SigmetCollectionGeoJson, Error<SigmetQueryError>> {
let uri_str = format!("{}/aviation/sigmets", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(param_value) = start {
req_builder = req_builder.query(&[("start", ¶m_value)]);
}
if let Some(param_value) = end {
req_builder = req_builder.query(&[("end", ¶m_value)]);
}
if let Some(param_value) = date {
req_builder = req_builder.query(&[("date", ¶m_value)]);
}
if let Some(param_value) = air_traffic_service_unit {
req_builder = req_builder.query(&[("atsu", ¶m_value)]);
}
if let Some(param_value) = sequence {
req_builder = req_builder.query(&[("sequence", ¶m_value)]);
}
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 `SigmetCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `SigmetCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `SigmetCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<SigmetQueryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_sigmets_by_air_traffic_service_unit(
configuration: &configuration::Configuration,
air_traffic_service_unit: &str,
) -> Result<models::SigmetCollectionGeoJson, Error<SigmetsByAtsuError>> {
let uri_str = format!(
"{}/aviation/sigmets/{air_traffic_service_unit}",
configuration.base_path,
air_traffic_service_unit = crate::apis::urlencode(air_traffic_service_unit)
);
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 `SigmetCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `SigmetCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `SigmetCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<SigmetsByAtsuError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_sigmets_by_air_traffic_service_unit_and_date(
configuration: &configuration::Configuration,
air_traffic_service_unit: &str,
date: String,
) -> Result<models::SigmetCollectionGeoJson, Error<SigmetsByAtsuAndDateError>> {
let uri_str = format!(
"{}/aviation/sigmets/{air_traffic_service_unit}/{date}",
configuration.base_path,
air_traffic_service_unit = crate::apis::urlencode(air_traffic_service_unit),
date = date
);
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 `SigmetCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `SigmetCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `SigmetCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<SigmetsByAtsuAndDateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}