use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct PageShieldListConnections<'a> {
client: &'a crate::Client,
zone_id: Result<types::PageShieldId, String>,
direction: Result<types::PageShieldListConnectionsDirection, String>,
exclude_cdn_cgi: Result<bool, String>,
exclude_urls: Result<::std::string::String, String>,
export: Result<types::PageShieldListConnectionsExport, String>,
hosts: Result<::std::string::String, String>,
order_by: Result<types::PageShieldListConnectionsOrderBy, String>,
page: Result<::std::string::String, String>,
page_url: Result<::std::string::String, String>,
per_page: Result<f64, String>,
prioritize_malicious: Result<bool, String>,
status: Result<::std::string::String, String>,
urls: Result<::std::string::String, String>,
}
impl<'a> PageShieldListConnections<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
zone_id: Err("zone_id was not initialized".to_string()),
direction: Err("direction was not initialized".to_string()),
exclude_cdn_cgi: Err("exclude_cdn_cgi was not initialized".to_string()),
exclude_urls: Err("exclude_urls was not initialized".to_string()),
export: Err("export was not initialized".to_string()),
hosts: Err("hosts was not initialized".to_string()),
order_by: Err("order_by was not initialized".to_string()),
page: Err("page was not initialized".to_string()),
page_url: Err("page_url was not initialized".to_string()),
per_page: Err("per_page was not initialized".to_string()),
prioritize_malicious: Err("prioritize_malicious was not initialized".to_string()),
status: Err("status was not initialized".to_string()),
urls: Err("urls was not initialized".to_string()),
}
}
pub fn zone_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::PageShieldId>,
{
self.zone_id = value
.try_into()
.map_err(|_| "conversion to `PageShieldId` for zone_id failed".to_string());
self
}
pub fn direction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::PageShieldListConnectionsDirection>,
{
self.direction = value.try_into().map_err(|_| {
"conversion to `PageShieldListConnectionsDirection` for direction failed"
.to_string()
});
self
}
pub fn exclude_cdn_cgi<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.exclude_cdn_cgi = value
.try_into()
.map_err(|_| "conversion to `bool` for exclude_cdn_cgi failed".to_string());
self
}
pub fn exclude_urls<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.exclude_urls = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for exclude_urls failed".to_string()
});
self
}
pub fn export<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::PageShieldListConnectionsExport>,
{
self.export = value.try_into().map_err(|_| {
"conversion to `PageShieldListConnectionsExport` for export failed".to_string()
});
self
}
pub fn hosts<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.hosts = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for hosts failed".to_string()
});
self
}
pub fn order_by<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::PageShieldListConnectionsOrderBy>,
{
self.order_by = value.try_into().map_err(|_| {
"conversion to `PageShieldListConnectionsOrderBy` for order_by failed".to_string()
});
self
}
pub fn page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.page = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for page failed".to_string()
});
self
}
pub fn page_url<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.page_url = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for page_url failed".to_string()
});
self
}
pub fn per_page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<f64>,
{
self.per_page = value
.try_into()
.map_err(|_| "conversion to `f64` for per_page failed".to_string());
self
}
pub fn prioritize_malicious<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.prioritize_malicious = value
.try_into()
.map_err(|_| "conversion to `bool` for prioritize_malicious failed".to_string());
self
}
pub fn status<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.status = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for status failed".to_string()
});
self
}
pub fn urls<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.urls = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for urls 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,
direction,
exclude_cdn_cgi,
exclude_urls,
export,
hosts,
order_by,
page,
page_url,
per_page,
prioritize_malicious,
status,
urls,
} = self;
let zone_id = zone_id.map_err(Error::InvalidRequest)?;
let direction = direction.map_err(Error::InvalidRequest)?;
let exclude_cdn_cgi = exclude_cdn_cgi.map_err(Error::InvalidRequest)?;
let exclude_urls = exclude_urls.map_err(Error::InvalidRequest)?;
let export = export.map_err(Error::InvalidRequest)?;
let hosts = hosts.map_err(Error::InvalidRequest)?;
let order_by = order_by.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let page_url = page_url.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let prioritize_malicious = prioritize_malicious.map_err(Error::InvalidRequest)?;
let status = status.map_err(Error::InvalidRequest)?;
let urls = urls.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/zones/{}/page_shield/connections",
client.baseurl,
encode_path(&zone_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"),
)
.query(&progenitor_client::QueryParam::new("direction", &direction))
.query(&progenitor_client::QueryParam::new(
"exclude_cdn_cgi",
&exclude_cdn_cgi,
))
.query(&progenitor_client::QueryParam::new(
"exclude_urls",
&exclude_urls,
))
.query(&progenitor_client::QueryParam::new("export", &export))
.query(&progenitor_client::QueryParam::new("hosts", &hosts))
.query(&progenitor_client::QueryParam::new("order_by", &order_by))
.query(&progenitor_client::QueryParam::new("page", &page))
.query(&progenitor_client::QueryParam::new("page_url", &page_url))
.query(&progenitor_client::QueryParam::new("per_page", &per_page))
.query(&progenitor_client::QueryParam::new(
"prioritize_malicious",
&prioritize_malicious,
))
.query(&progenitor_client::QueryParam::new("status", &status))
.query(&progenitor_client::QueryParam::new("urls", &urls))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "page_shield_list_connections",
};
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)),
}
}
}