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 LocationProductsError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ProductError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ProductLocationsError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ProductTypesError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ProductsQueryError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ProductsTypeError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ProductsTypeLocationError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ProductsTypeLocationsError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LatestProductTypeLocationError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Default)]
pub struct ProductsQueryParams {
pub location_ids: Option<Vec<models::NwsForecastOfficeId>>,
pub start_time: Option<String>,
pub end_time: Option<String>,
pub office_ids: Option<Vec<models::NwsForecastOfficeId>>,
pub wmo_ids: Option<Vec<String>>,
pub product_type_codes: Option<Vec<String>>,
pub limit: Option<i32>,
}
pub async fn get_products_by_location(
configuration: &configuration::Configuration,
location_id: &models::NwsForecastOfficeId,
) -> Result<models::TextProductTypeCollection, Error<LocationProductsError>> {
let uri_str = format!(
"{}/products/locations/{locationId}/types",
configuration.base_path,
locationId = location_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 `TextProductTypeCollection`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `TextProductTypeCollection`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `TextProductTypeCollection`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<LocationProductsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_product(
configuration: &configuration::Configuration,
product_id: &str,
) -> Result<models::TextProduct, Error<ProductError>> {
let uri_str = format!(
"{}/products/{productId}",
configuration.base_path,
productId = crate::apis::urlencode(product_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 `TextProduct`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `TextProduct`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `TextProduct`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ProductError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_product_locations(
configuration: &configuration::Configuration,
) -> Result<models::TextProductLocationCollection, Error<ProductLocationsError>> {
let uri_str = format!("{}/products/locations", configuration.base_path);
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 `TextProductLocationCollection`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `TextProductLocationCollection`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `TextProductLocationCollection`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ProductLocationsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_product_types(
configuration: &configuration::Configuration,
) -> Result<models::TextProductTypeCollection, Error<ProductTypesError>> {
let uri_str = format!("{}/products/types", configuration.base_path);
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 `TextProductTypeCollection`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `TextProductTypeCollection`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `TextProductTypeCollection`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ProductTypesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_products_query(
configuration: &configuration::Configuration,
params: ProductsQueryParams,
) -> Result<models::TextProductCollection, Error<ProductsQueryError>> {
let uri_str = format!("{}/products", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(param_value) = params.location_ids {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|p| ("location".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"location",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = params.start_time {
req_builder = req_builder.query(&[("start", ¶m_value)]);
}
if let Some(param_value) = params.end_time {
req_builder = req_builder.query(&[("end", ¶m_value)]);
}
if let Some(param_value) = params.office_ids {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|p| ("office".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"office",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = params.wmo_ids {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|p| ("wmoid".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"wmoid",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = params.product_type_codes {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|p| ("type".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"type",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = params.limit {
req_builder = req_builder.query(&[("limit", ¶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 `TextProductCollection`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `TextProductCollection`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `TextProductCollection`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ProductsQueryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_products_by_type(
configuration: &configuration::Configuration,
type_id: &str,
) -> Result<models::TextProductCollection, Error<ProductsTypeError>> {
let uri_str = format!(
"{}/products/types/{typeId}",
configuration.base_path,
typeId = crate::apis::urlencode(type_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 `TextProductCollection`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `TextProductCollection`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `TextProductCollection`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ProductsTypeError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_products_by_type_and_location(
configuration: &configuration::Configuration,
type_id: &str,
location_id: &models::NwsForecastOfficeId,
) -> Result<models::TextProductCollection, Error<ProductsTypeLocationError>> {
let uri_str = format!(
"{}/products/types/{typeId}/locations/{locationId}",
configuration.base_path,
typeId = type_id,
locationId = location_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 `TextProductCollection`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `TextProductCollection`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `TextProductCollection`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ProductsTypeLocationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_product_issuance_locations_by_type(
configuration: &configuration::Configuration,
type_id: &str,
) -> Result<models::TextProductLocationCollection, Error<ProductsTypeLocationsError>> {
let uri_str = format!(
"{}/products/types/{typeId}/locations",
configuration.base_path,
typeId = crate::apis::urlencode(type_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 `TextProductLocationCollection`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `TextProductLocationCollection`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `TextProductLocationCollection`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ProductsTypeLocationsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_latest_product_by_type_and_location(
configuration: &configuration::Configuration,
type_id: &str,
location_id: &str,
) -> Result<models::TextProduct, Error<LatestProductTypeLocationError>> {
let uri_str = format!(
"{}/products/types/{type_id}/locations/{location_id}/latest",
configuration.base_path,
type_id = crate::apis::urlencode(type_id),
location_id = crate::apis::urlencode(location_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 `TextProduct`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `TextProduct`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `TextProduct`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<LatestProductTypeLocationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}