use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct TunnelRouteListTunnelRoutes<'a> {
client: &'a crate::Client,
account_id: Result<types::TunnelAccountId, String>,
comment: Result<types::TunnelRouteComment, String>,
existed_at: Result<types::TunnelExistedAt, String>,
is_deleted: Result<bool, String>,
network_subset: Result<types::TunnelIpNetwork, String>,
network_superset: Result<types::TunnelIpNetwork, String>,
page: Result<types::TunnelPageNumber, String>,
per_page: Result<types::TunnelPerPage, String>,
route_id: Result<types::TunnelRouteId, String>,
tun_types: Result<types::TunnelTunnelTypes, String>,
tunnel_id: Result<types::TunnelTunnelId, String>,
virtual_network_id: Result<types::TunnelVirtualNetworkId, String>,
}
impl<'a> TunnelRouteListTunnelRoutes<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
comment: Err("comment was not initialized".to_string()),
existed_at: Err("existed_at was not initialized".to_string()),
is_deleted: Err("is_deleted was not initialized".to_string()),
network_subset: Err("network_subset was not initialized".to_string()),
network_superset: Err("network_superset was not initialized".to_string()),
page: Err("page was not initialized".to_string()),
per_page: Err("per_page was not initialized".to_string()),
route_id: Err("route_id was not initialized".to_string()),
tun_types: Err("tun_types was not initialized".to_string()),
tunnel_id: Err("tunnel_id was not initialized".to_string()),
virtual_network_id: Err("virtual_network_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelAccountId>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `TunnelAccountId` for account_id failed".to_string());
self
}
pub fn comment<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelRouteComment>,
{
self.comment = value
.try_into()
.map_err(|_| "conversion to `TunnelRouteComment` for comment failed".to_string());
self
}
pub fn existed_at<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelExistedAt>,
{
self.existed_at = value
.try_into()
.map_err(|_| "conversion to `TunnelExistedAt` for existed_at failed".to_string());
self
}
pub fn is_deleted<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.is_deleted = value
.try_into()
.map_err(|_| "conversion to `bool` for is_deleted failed".to_string());
self
}
pub fn network_subset<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelIpNetwork>,
{
self.network_subset = value.try_into().map_err(|_| {
"conversion to `TunnelIpNetwork` for network_subset failed".to_string()
});
self
}
pub fn network_superset<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelIpNetwork>,
{
self.network_superset = value.try_into().map_err(|_| {
"conversion to `TunnelIpNetwork` for network_superset failed".to_string()
});
self
}
pub fn page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelPageNumber>,
{
self.page = value
.try_into()
.map_err(|_| "conversion to `TunnelPageNumber` for page failed".to_string());
self
}
pub fn per_page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelPerPage>,
{
self.per_page = value
.try_into()
.map_err(|_| "conversion to `TunnelPerPage` for per_page failed".to_string());
self
}
pub fn route_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelRouteId>,
{
self.route_id = value
.try_into()
.map_err(|_| "conversion to `TunnelRouteId` for route_id failed".to_string());
self
}
pub fn tun_types<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelTunnelTypes>,
{
self.tun_types = value
.try_into()
.map_err(|_| "conversion to `TunnelTunnelTypes` for tun_types failed".to_string());
self
}
pub fn tunnel_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelTunnelId>,
{
self.tunnel_id = value
.try_into()
.map_err(|_| "conversion to `TunnelTunnelId` for tunnel_id failed".to_string());
self
}
pub fn virtual_network_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelVirtualNetworkId>,
{
self.virtual_network_id = value.try_into().map_err(|_| {
"conversion to `TunnelVirtualNetworkId` for virtual_network_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,
account_id,
comment,
existed_at,
is_deleted,
network_subset,
network_superset,
page,
per_page,
route_id,
tun_types,
tunnel_id,
virtual_network_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let comment = comment.map_err(Error::InvalidRequest)?;
let existed_at = existed_at.map_err(Error::InvalidRequest)?;
let is_deleted = is_deleted.map_err(Error::InvalidRequest)?;
let network_subset = network_subset.map_err(Error::InvalidRequest)?;
let network_superset = network_superset.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let route_id = route_id.map_err(Error::InvalidRequest)?;
let tun_types = tun_types.map_err(Error::InvalidRequest)?;
let tunnel_id = tunnel_id.map_err(Error::InvalidRequest)?;
let virtual_network_id = virtual_network_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/teamnet/routes",
client.baseurl,
encode_path(&account_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("comment", &comment))
.query(&progenitor_client::QueryParam::new(
"existed_at",
&existed_at,
))
.query(&progenitor_client::QueryParam::new(
"is_deleted",
&is_deleted,
))
.query(&progenitor_client::QueryParam::new(
"network_subset",
&network_subset,
))
.query(&progenitor_client::QueryParam::new(
"network_superset",
&network_superset,
))
.query(&progenitor_client::QueryParam::new("page", &page))
.query(&progenitor_client::QueryParam::new("per_page", &per_page))
.query(&progenitor_client::QueryParam::new("route_id", &route_id))
.query(&progenitor_client::QueryParam::new("tun_types", &tun_types))
.query(&progenitor_client::QueryParam::new("tunnel_id", &tunnel_id))
.query(&progenitor_client::QueryParam::new(
"virtual_network_id",
&virtual_network_id,
))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "tunnel_route_list_tunnel_routes",
};
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 TunnelRouteCreateATunnelRoute<'a> {
client: &'a crate::Client,
account_id: Result<types::TunnelAccountId, String>,
body: Result<types::builder::TunnelRouteCreateATunnelRouteBody, String>,
}
impl<'a> TunnelRouteCreateATunnelRoute<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelAccountId>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `TunnelAccountId` for account_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TunnelRouteCreateATunnelRouteBody>,
<V as std::convert::TryInto<types::TunnelRouteCreateATunnelRouteBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `TunnelRouteCreateATunnelRouteBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::TunnelRouteCreateATunnelRouteBody,
) -> types::builder::TunnelRouteCreateATunnelRouteBody,
{
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,
account_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::TunnelRouteCreateATunnelRouteBody::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/teamnet/routes",
client.baseurl,
encode_path(&account_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
.post(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "tunnel_route_create_a_tunnel_route",
};
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)),
}
}
}