use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct HealthChecksHealthCheckDetails<'a> {
client: &'a crate::Client,
zone_id: Result<types::HealthchecksIdentifier, String>,
healthcheck_id: Result<types::HealthchecksIdentifier, String>,
}
impl<'a> HealthChecksHealthCheckDetails<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
zone_id: Err("zone_id was not initialized".to_string()),
healthcheck_id: Err("healthcheck_id was not initialized".to_string()),
}
}
pub fn zone_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.zone_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for zone_id failed".to_string()
});
self
}
pub fn healthcheck_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.healthcheck_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for healthcheck_id failed".to_string()
});
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
zone_id,
healthcheck_id,
} = self;
let zone_id = zone_id.map_err(Error::InvalidRequest)?;
let healthcheck_id = healthcheck_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/zones/{}/healthchecks/{}",
client.baseurl,
encode_path(&zone_id.to_string()),
encode_path(&healthcheck_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.get(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "health_checks_health_check_details",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct HealthChecksUpdateHealthCheck<'a> {
client: &'a crate::Client,
zone_id: Result<types::HealthchecksIdentifier, String>,
healthcheck_id: Result<types::HealthchecksIdentifier, String>,
body: Result<types::builder::HealthchecksQueryHealthcheck, String>,
}
impl<'a> HealthChecksUpdateHealthCheck<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
zone_id: Err("zone_id was not initialized".to_string()),
healthcheck_id: Err("healthcheck_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn zone_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.zone_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for zone_id failed".to_string()
});
self
}
pub fn healthcheck_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.healthcheck_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for healthcheck_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksQueryHealthcheck>,
<V as std::convert::TryInto<types::HealthchecksQueryHealthcheck>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `HealthchecksQueryHealthcheck` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::HealthchecksQueryHealthcheck,
) -> types::builder::HealthchecksQueryHealthcheck,
{
self.body = self.body.map(f);
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
zone_id,
healthcheck_id,
body,
} = self;
let zone_id = zone_id.map_err(Error::InvalidRequest)?;
let healthcheck_id = healthcheck_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::HealthchecksQueryHealthcheck::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/zones/{}/healthchecks/{}",
client.baseurl,
encode_path(&zone_id.to_string()),
encode_path(&healthcheck_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "health_checks_update_health_check",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct HealthChecksDeleteHealthCheck<'a> {
client: &'a crate::Client,
zone_id: Result<types::HealthchecksIdentifier, String>,
healthcheck_id: Result<types::HealthchecksIdentifier, String>,
body: Result<::serde_json::Map<::std::string::String, ::serde_json::Value>, String>,
}
impl<'a> HealthChecksDeleteHealthCheck<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
zone_id: Err("zone_id was not initialized".to_string()),
healthcheck_id: Err("healthcheck_id was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn zone_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.zone_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for zone_id failed".to_string()
});
self
}
pub fn healthcheck_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.healthcheck_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for healthcheck_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
{
self . body = value . try_into () . map_err (| _ | "conversion to `:: serde_json :: Map < :: std :: string :: String , :: serde_json :: Value >` for body failed" . to_string ()) ;
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
zone_id,
healthcheck_id,
body,
} = self;
let zone_id = zone_id.map_err(Error::InvalidRequest)?;
let healthcheck_id = healthcheck_id.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/zones/{}/healthchecks/{}",
client.baseurl,
encode_path(&zone_id.to_string()),
encode_path(&healthcheck_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.delete(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "health_checks_delete_health_check",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct HealthChecksPatchHealthCheck<'a> {
client: &'a crate::Client,
zone_id: Result<types::HealthchecksIdentifier, String>,
healthcheck_id: Result<types::HealthchecksIdentifier, String>,
body: Result<types::builder::HealthchecksQueryHealthcheck, String>,
}
impl<'a> HealthChecksPatchHealthCheck<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
zone_id: Err("zone_id was not initialized".to_string()),
healthcheck_id: Err("healthcheck_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn zone_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.zone_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for zone_id failed".to_string()
});
self
}
pub fn healthcheck_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.healthcheck_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for healthcheck_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksQueryHealthcheck>,
<V as std::convert::TryInto<types::HealthchecksQueryHealthcheck>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `HealthchecksQueryHealthcheck` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::HealthchecksQueryHealthcheck,
) -> types::builder::HealthchecksQueryHealthcheck,
{
self.body = self.body.map(f);
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
zone_id,
healthcheck_id,
body,
} = self;
let zone_id = zone_id.map_err(Error::InvalidRequest)?;
let healthcheck_id = healthcheck_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::HealthchecksQueryHealthcheck::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/zones/{}/healthchecks/{}",
client.baseurl,
encode_path(&zone_id.to_string()),
encode_path(&healthcheck_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.patch(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "health_checks_patch_health_check",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct HealthChecksHealthCheckPreviewDetails<'a> {
client: &'a crate::Client,
zone_id: Result<types::HealthchecksIdentifier, String>,
healthcheck_id: Result<types::HealthchecksIdentifier, String>,
}
impl<'a> HealthChecksHealthCheckPreviewDetails<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
zone_id: Err("zone_id was not initialized".to_string()),
healthcheck_id: Err("healthcheck_id was not initialized".to_string()),
}
}
pub fn zone_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.zone_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for zone_id failed".to_string()
});
self
}
pub fn healthcheck_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.healthcheck_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for healthcheck_id failed".to_string()
});
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
zone_id,
healthcheck_id,
} = self;
let zone_id = zone_id.map_err(Error::InvalidRequest)?;
let healthcheck_id = healthcheck_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/zones/{}/healthchecks/preview/{}",
client.baseurl,
encode_path(&zone_id.to_string()),
encode_path(&healthcheck_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.get(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "health_checks_health_check_preview_details",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct HealthChecksDeletePreviewHealthCheck<'a> {
client: &'a crate::Client,
zone_id: Result<types::HealthchecksIdentifier, String>,
healthcheck_id: Result<types::HealthchecksIdentifier, String>,
body: Result<::serde_json::Map<::std::string::String, ::serde_json::Value>, String>,
}
impl<'a> HealthChecksDeletePreviewHealthCheck<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
zone_id: Err("zone_id was not initialized".to_string()),
healthcheck_id: Err("healthcheck_id was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn zone_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.zone_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for zone_id failed".to_string()
});
self
}
pub fn healthcheck_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::HealthchecksIdentifier>,
{
self.healthcheck_id = value.try_into().map_err(|_| {
"conversion to `HealthchecksIdentifier` for healthcheck_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
{
self . body = value . try_into () . map_err (| _ | "conversion to `:: serde_json :: Map < :: std :: string :: String , :: serde_json :: Value >` for body failed" . to_string ()) ;
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
zone_id,
healthcheck_id,
body,
} = self;
let zone_id = zone_id.map_err(Error::InvalidRequest)?;
let healthcheck_id = healthcheck_id.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/zones/{}/healthchecks/preview/{}",
client.baseurl,
encode_path(&zone_id.to_string()),
encode_path(&healthcheck_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.delete(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "health_checks_delete_preview_health_check",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}