use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct IpAccessRulesForAUserListIpAccessRules<'a> {
client: &'a crate::Client,
configuration_target:
Result<types::IpAccessRulesForAUserListIpAccessRulesConfigurationTarget, String>,
configuration_value: Result<::std::string::String, String>,
direction: Result<types::IpAccessRulesForAUserListIpAccessRulesDirection, String>,
pattern: Result<types::IpAccessRulesForAUserListIpAccessRulesMatch, String>,
mode: Result<types::FirewallSchemasMode, String>,
notes: Result<::std::string::String, String>,
order: Result<types::IpAccessRulesForAUserListIpAccessRulesOrder, String>,
page: Result<f64, String>,
per_page: Result<f64, String>,
}
impl<'a> IpAccessRulesForAUserListIpAccessRules<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
configuration_target: Err("configuration_target was not initialized".to_string()),
configuration_value: Err("configuration_value was not initialized".to_string()),
direction: Err("direction was not initialized".to_string()),
pattern: Err("pattern was not initialized".to_string()),
mode: Err("mode was not initialized".to_string()),
notes: Err("notes was not initialized".to_string()),
order: Err("order was not initialized".to_string()),
page: Err("page was not initialized".to_string()),
per_page: Err("per_page was not initialized".to_string()),
}
}
pub fn configuration_target<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<
types::IpAccessRulesForAUserListIpAccessRulesConfigurationTarget,
>,
{
self . configuration_target = value . try_into () . map_err (| _ | "conversion to `IpAccessRulesForAUserListIpAccessRulesConfigurationTarget` for configuration_target failed" . to_string ()) ;
self
}
pub fn configuration_value<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.configuration_value = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for configuration_value failed"
.to_string()
});
self
}
pub fn direction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::IpAccessRulesForAUserListIpAccessRulesDirection>,
{
self . direction = value . try_into () . map_err (| _ | "conversion to `IpAccessRulesForAUserListIpAccessRulesDirection` for direction failed" . to_string ()) ;
self
}
pub fn pattern<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::IpAccessRulesForAUserListIpAccessRulesMatch>,
{
self.pattern = value.try_into().map_err(|_| {
"conversion to `IpAccessRulesForAUserListIpAccessRulesMatch` for pattern failed"
.to_string()
});
self
}
pub fn mode<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::FirewallSchemasMode>,
{
self.mode = value
.try_into()
.map_err(|_| "conversion to `FirewallSchemasMode` for mode failed".to_string());
self
}
pub fn notes<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.notes = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for notes failed".to_string()
});
self
}
pub fn order<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::IpAccessRulesForAUserListIpAccessRulesOrder>,
{
self.order = value.try_into().map_err(|_| {
"conversion to `IpAccessRulesForAUserListIpAccessRulesOrder` for order failed"
.to_string()
});
self
}
pub fn page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<f64>,
{
self.page = value
.try_into()
.map_err(|_| "conversion to `f64` for page 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 async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
configuration_target,
configuration_value,
direction,
pattern,
mode,
notes,
order,
page,
per_page,
} = self;
let configuration_target = configuration_target.map_err(Error::InvalidRequest)?;
let configuration_value = configuration_value.map_err(Error::InvalidRequest)?;
let direction = direction.map_err(Error::InvalidRequest)?;
let pattern = pattern.map_err(Error::InvalidRequest)?;
let mode = mode.map_err(Error::InvalidRequest)?;
let notes = notes.map_err(Error::InvalidRequest)?;
let order = order.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let url = format!("{}/user/firewall/access_rules/rules", client.baseurl,);
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(
"configuration.target",
&configuration_target,
))
.query(&progenitor_client::QueryParam::new(
"configuration.value",
&configuration_value,
))
.query(&progenitor_client::QueryParam::new("direction", &direction))
.query(&progenitor_client::QueryParam::new("match", &pattern))
.query(&progenitor_client::QueryParam::new("mode", &mode))
.query(&progenitor_client::QueryParam::new("notes", ¬es))
.query(&progenitor_client::QueryParam::new("order", &order))
.query(&progenitor_client::QueryParam::new("page", &page))
.query(&progenitor_client::QueryParam::new("per_page", &per_page))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "ip_access_rules_for_a_user_list_ip_access_rules",
};
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)),
}
}
}