use super::{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 ZoneError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ZoneForecastError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ZoneListError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ZoneListTypeError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ZoneObsError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ZoneStationsError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Clone, Debug, Default)]
pub struct GetZonesParams<'a> {
pub id: Option<Vec<String>>,
pub area: Option<Vec<models::AreaCode>>,
pub region: Option<Vec<models::RegionCode>>,
pub r#type: Option<Vec<models::NwsZoneType>>,
pub point: Option<&'a str>,
pub include_geometry: Option<bool>,
pub limit: Option<i32>,
pub effective: Option<String>,
}
impl GetZonesParams<'_> {
pub fn new() -> Self {
Default::default()
}
}
#[derive(Clone, Debug, Default)]
pub struct GetZonesByTypeParams<'a> {
pub id: Option<Vec<String>>,
pub area: Option<Vec<models::AreaCode>>,
pub region: Option<Vec<models::RegionCode>>,
pub type_filter: Option<Vec<models::NwsZoneType>>,
pub point: Option<&'a str>,
pub include_geometry: Option<bool>,
pub limit: Option<i32>,
pub effective: Option<String>,
}
impl GetZonesByTypeParams<'_> {
pub fn new() -> Self {
Default::default()
}
}
pub async fn get_zone(
configuration: &configuration::Configuration,
r#type: models::NwsZoneType,
id: &str,
effective: Option<String>,
) -> Result<models::ZoneGeoJson, Error<ZoneError>> {
let uri_str = format!("{}/zones/{type}/{id}",
configuration.base_path,
type=r#type,
id=crate::apis::urlencode(id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = effective {
req_builder = req_builder.query(&[("effective", ¶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(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 `ZoneGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `ZoneGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `ZoneGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ZoneError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_current_zone_forecast(
configuration: &configuration::Configuration,
r#type: &str,
id: &str,
) -> Result<models::ZoneForecastGeoJson, Error<ZoneForecastError>> {
let uri_str = format!("{}/zones/{type}/{id}/forecast",
configuration.base_path,
type=crate::apis::urlencode(r#type),
id=crate::apis::urlencode(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(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 `ZoneForecastGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `ZoneForecastGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `ZoneForecastGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ZoneForecastError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_zones(
configuration: &configuration::Configuration,
params: GetZonesParams<'_>,
) -> Result<models::ZoneCollectionGeoJson, Error<ZoneListError>> {
let uri_str = format!("{}/zones", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = params.id {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("id".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"id",
¶m_value
.iter()
.map(|param| param.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = params.area {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("area".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"area",
¶m_value
.iter()
.map(|param| param.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = params.region {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("region".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"region",
¶m_value
.iter()
.map(|param| param.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = params.r#type {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("type".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"type",
¶m_value
.iter()
.map(|param| param.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = params.point {
req_builder = req_builder.query(&[("point", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.include_geometry {
req_builder = req_builder.query(&[("include_geometry", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.effective {
req_builder = req_builder.query(&[("effective", ¶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(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 `ZoneCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `ZoneCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `ZoneCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ZoneListError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_zones_by_type(
configuration: &configuration::Configuration,
r#type: models::NwsZoneType,
params: GetZonesByTypeParams<'_>,
) -> Result<models::ZoneCollectionGeoJson, Error<ZoneListTypeError>> {
let uri_str = format!("{}/zones/{type}", configuration.base_path, type = r#type);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = params.id {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("id".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"id",
¶m_value
.iter()
.map(|param| param.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = params.area {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("area".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"area",
¶m_value
.iter()
.map(|param| param.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = params.region {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("region".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"region",
¶m_value
.iter()
.map(|param| param.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = params.type_filter {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("type".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"type",
¶m_value
.iter()
.map(|param| param.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = params.point {
req_builder = req_builder.query(&[("point", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.include_geometry {
req_builder = req_builder.query(&[("include_geometry", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.effective {
req_builder = req_builder.query(&[("effective", ¶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(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 `ZoneCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `ZoneCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `ZoneCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ZoneListTypeError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_zone_observations(
configuration: &configuration::Configuration,
id: &str,
start: Option<String>,
end: Option<String>,
limit: Option<i32>,
) -> Result<models::ObservationCollectionGeoJson, Error<ZoneObsError>> {
let uri_str = format!(
"{}/zones/forecast/{id}/observations",
configuration.base_path,
id = crate::apis::urlencode(id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = start {
req_builder = req_builder.query(&[("start", ¶m_value.to_string())]);
}
if let Some(ref param_value) = end {
req_builder = req_builder.query(&[("end", ¶m_value.to_string())]);
}
if let Some(ref param_value) = 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(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 `ObservationCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `ObservationCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `ObservationCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ZoneObsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_stations_by_zone(
configuration: &configuration::Configuration,
id: &str,
limit: Option<i32>,
cursor: Option<&str>,
) -> Result<models::ObservationStationCollectionGeoJson, Error<ZoneStationsError>> {
let uri_str = format!(
"{}/zones/forecast/{id}/stations",
configuration.base_path,
id = crate::apis::urlencode(id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = cursor {
req_builder = req_builder.query(&[("cursor", ¶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(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 `ObservationStationCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `ObservationStationCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `ObservationStationCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ZoneStationsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}