use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct ConnectivityServicesList<'a> {
client: &'a crate::Client,
account_id: Result<types::InfraAccountTag, String>,
page: Result<::std::num::NonZeroU32, String>,
per_page: Result<::std::num::NonZeroU32, String>,
kind: Result<Option<types::InfraServiceType>, String>,
}
impl<'a> ConnectivityServicesList<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
page: Err("page was not initialized".to_string()),
per_page: Err("per_page was not initialized".to_string()),
kind: Ok(None),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraAccountTag>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `InfraAccountTag` for account_id failed".to_string());
self
}
pub fn page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::num::NonZeroU32>,
{
self.page = value.try_into().map_err(|_| {
"conversion to `:: std :: num :: NonZeroU32` for page failed".to_string()
});
self
}
pub fn per_page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::num::NonZeroU32>,
{
self.per_page = value.try_into().map_err(|_| {
"conversion to `:: std :: num :: NonZeroU32` for per_page failed".to_string()
});
self
}
pub fn kind<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraServiceType>,
{
self.kind = value
.try_into()
.map(Some)
.map_err(|_| "conversion to `InfraServiceType` for kind 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,
page,
per_page,
kind,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let kind = kind.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/connectivity/directory/services",
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("page", &page))
.query(&progenitor_client::QueryParam::new("per_page", &per_page))
.query(&progenitor_client::QueryParam::new("type", &kind))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "connectivity_services_list",
};
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 ConnectivityServicesPost<'a> {
client: &'a crate::Client,
account_id: Result<types::InfraAccountTag, String>,
body: Result<types::InfraServiceConfig, String>,
}
impl<'a> ConnectivityServicesPost<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraAccountTag>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `InfraAccountTag` for account_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraServiceConfig>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `InfraServiceConfig` 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,
account_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/connectivity/directory/services",
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: "connectivity_services_post",
};
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 ConnectivityServicesGet<'a> {
client: &'a crate::Client,
account_id: Result<::std::string::String, String>,
service_id: Result<::uuid::Uuid, String>,
}
impl<'a> ConnectivityServicesGet<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
service_id: Err("service_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for account_id failed".to_string()
});
self
}
pub fn service_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::uuid::Uuid>,
{
self.service_id = value
.try_into()
.map_err(|_| "conversion to `:: uuid :: Uuid` for service_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,
service_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let service_id = service_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/connectivity/directory/services/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&service_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: "connectivity_services_get",
};
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 ConnectivityServicesPut<'a> {
client: &'a crate::Client,
account_id: Result<::std::string::String, String>,
service_id: Result<::uuid::Uuid, String>,
body: Result<types::InfraServiceConfig, String>,
}
impl<'a> ConnectivityServicesPut<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
service_id: Err("service_id was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for account_id failed".to_string()
});
self
}
pub fn service_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::uuid::Uuid>,
{
self.service_id = value
.try_into()
.map_err(|_| "conversion to `:: uuid :: Uuid` for service_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraServiceConfig>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `InfraServiceConfig` 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,
account_id,
service_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let service_id = service_id.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/connectivity/directory/services/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&service_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: "connectivity_services_put",
};
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 ConnectivityServicesDelete<'a> {
client: &'a crate::Client,
account_id: Result<::std::string::String, String>,
service_id: Result<::uuid::Uuid, String>,
}
impl<'a> ConnectivityServicesDelete<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
service_id: Err("service_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for account_id failed".to_string()
});
self
}
pub fn service_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::uuid::Uuid>,
{
self.service_id = value
.try_into()
.map_err(|_| "conversion to `:: uuid :: Uuid` for service_id failed".to_string());
self
}
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self {
client,
account_id,
service_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let service_id = service_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/connectivity/directory/services/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&service_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).headers(header_map).build()?;
let info = OperationInfo {
operation_id: "connectivity_services_delete",
};
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 => Ok(ResponseValue::empty(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}