use super::{API_KEY_HEADER, ContentType, Error, configuration};
use crate::apis::ResponseContent;
use crate::models::{self, AreaCode};
use reqwest;
use serde::de::Error as _;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ActiveAlertsError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ActiveAlertsAreaError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ActiveAlertsCountError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ActiveRegionError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ActiveAlertsZoneError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAlertsError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAlertError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAlertTypesError {
DefaultResponse(models::ProblemDetail),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Default)]
pub struct ActiveAlertsParams<'a> {
pub status: Option<Vec<models::AlertStatus>>,
pub message_type: Option<Vec<models::AlertMessageType>>,
pub event: Option<Vec<String>>,
pub code: Option<Vec<String>>,
pub area: Option<Vec<models::AreaCode>>,
pub point: Option<&'a str>,
pub region: Option<Vec<models::MarineRegionCode>>,
pub region_type: Option<models::RegionType>,
pub zone: Option<Vec<String>>,
pub urgency: Option<Vec<models::AlertUrgency>>,
pub severity: Option<Vec<models::AlertSeverity>>,
pub certainty: Option<Vec<models::AlertCertainty>>,
}
#[derive(Debug, Clone, Default)]
pub struct GetAlertsParams<'a> {
pub active: Option<bool>,
pub start: Option<String>,
pub end: Option<String>,
pub status: Option<Vec<models::AlertStatus>>,
pub message_type: Option<Vec<models::AlertMessageType>>,
pub event: Option<Vec<String>>,
pub code: Option<Vec<String>>,
pub area: Option<Vec<models::AreaCode>>,
pub point: Option<&'a str>,
pub region: Option<Vec<models::MarineRegionCode>>,
pub region_type: Option<models::RegionType>,
pub zone: Option<Vec<String>>,
pub urgency: Option<Vec<models::AlertUrgency>>,
pub severity: Option<Vec<models::AlertSeverity>>,
pub certainty: Option<Vec<models::AlertCertainty>>,
pub limit: Option<i32>,
pub cursor: Option<&'a str>,
}
pub async fn get_active_alerts(
configuration: &configuration::Configuration,
params: ActiveAlertsParams<'_>,
) -> Result<models::AlertCollectionGeoJson, Error<ActiveAlertsError>> {
let uri_str = format!("{}/alerts/active", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(param_value) = ¶ms.status {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("status".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"status",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.message_type {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("message_type".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"message_type",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.event {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("event".to_owned(), param.clone()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"event",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.code {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("code".to_owned(), param.clone()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"code",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.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(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = params.point {
req_builder = req_builder.query(&[("point", ¶m_value.to_owned())]);
}
if let Some(param_value) = ¶ms.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(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.region_type {
req_builder = req_builder.query(&[("region_type", ¶m_value.to_string())]);
}
if let Some(param_value) = ¶ms.zone {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("zone".to_owned(), param.clone()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"zone",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.urgency {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("urgency".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"urgency",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.severity {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("severity".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"severity",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.certainty {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("certainty".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"certainty",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
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() {
match content_type {
ContentType::Json => resp.json().await.map_err(Error::from),
ContentType::Text => Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `AlertCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `AlertCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `AlertCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ActiveAlertsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_active_alerts_for_area(
configuration: &configuration::Configuration,
area: &AreaCode,
) -> Result<models::AlertCollectionGeoJson, Error<ActiveAlertsAreaError>> {
let uri_str = format!(
"{}/alerts/active/area/{area}",
configuration.base_path,
area = area
);
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 `AlertCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `AlertCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `AlertCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ActiveAlertsAreaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_active_alerts_count(
configuration: &configuration::Configuration,
) -> Result<models::ActiveAlertsCountResponse, Error<ActiveAlertsCountError>> {
let uri_str = format!("{}/alerts/active/count", 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 `AlertsActiveCount200Response`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `AlertsActiveCount200Response`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `AlertsActiveCount200Response`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ActiveAlertsCountError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_active_alerts_for_marine_region(
configuration: &configuration::Configuration,
region: models::MarineRegionCode,
) -> Result<models::AlertCollectionGeoJson, Error<ActiveRegionError>> {
let uri_str = format!(
"{}/alerts/active/region/{region}",
configuration.base_path,
region = region
);
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 `AlertCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `AlertCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `AlertCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ActiveRegionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_active_alerts_for_zone(
configuration: &configuration::Configuration,
zone_id: &str,
) -> Result<models::AlertCollectionGeoJson, Error<ActiveAlertsZoneError>> {
let uri_str = format!(
"{}/alerts/active/zone/{zoneId}",
configuration.base_path,
zoneId = crate::apis::urlencode(zone_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 `AlertCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `AlertCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `AlertCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<ActiveAlertsZoneError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_alerts(
configuration: &configuration::Configuration,
params: GetAlertsParams<'_>,
) -> Result<models::AlertCollectionGeoJson, Error<GetAlertsError>> {
let uri_str = format!("{}/alerts", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(param_value) = ¶ms.active {
req_builder = req_builder.query(&[("active", ¶m_value.clone())]);
}
if let Some(param_value) = ¶ms.start {
req_builder = req_builder.query(&[("start", ¶m_value.clone())]);
}
if let Some(param_value) = ¶ms.end {
req_builder = req_builder.query(&[("end", ¶m_value.clone())]);
}
if let Some(param_value) = ¶ms.status {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("status".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"status",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.message_type {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("message_type".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"message_type",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.event {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("event".to_owned(), param.clone()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"event",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.code {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|p| ("code".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"code",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.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(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.point {
req_builder = req_builder.query(&[("point", &(*param_value).to_owned())]);
}
if let Some(param_value) = ¶ms.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(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.region_type {
req_builder = req_builder.query(&[("region_type", ¶m_value.to_string())]);
}
if let Some(param_value) = ¶ms.zone {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("zone".to_owned(), param.clone()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"zone",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.urgency {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("urgency".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"urgency",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.severity {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("severity".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"severity",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.certainty {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.iter()
.map(|param| ("certainty".to_owned(), param.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"certainty",
¶m_value
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(","),
)]),
};
}
if let Some(param_value) = ¶ms.limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(param_value) = ¶ms.cursor {
req_builder = req_builder.query(&[("cursor", &(*param_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 `AlertCollectionGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `AlertCollectionGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `AlertCollectionGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetAlertsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_alert(
configuration: &configuration::Configuration,
id: &str,
) -> Result<models::AlertGeoJson, Error<GetAlertError>> {
let uri_str = format!(
"{}/alerts/{id}",
configuration.base_path,
id = crate::apis::urlencode(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 `AlertGeoJson`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `AlertGeoJson`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `AlertGeoJson`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetAlertError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}
pub async fn get_alert_types(
configuration: &configuration::Configuration,
) -> Result<models::AlertTypesResponse, Error<GetAlertTypesError>> {
let uri_str = format!("{}/alerts/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 `AlertsTypes200Response`",
))),
ContentType::Xml => Err(Error::from(serde_json::Error::custom(
"Received `application/xml` content type response that cannot be converted to `AlertsTypes200Response`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `AlertsTypes200Response`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetAlertTypesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
content,
entity,
status,
})))
}
}