use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct OriginCaListCertificates<'a> {
client: &'a crate::Client,
limit: Result<i64, String>,
offset: Result<i64, String>,
page: Result<f64, String>,
per_page: Result<f64, String>,
zone_id: Result<types::TlsCertificatesAndHostnamesIdentifier, String>,
}
impl<'a> OriginCaListCertificates<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
limit: Err("limit was not initialized".to_string()),
offset: Err("offset was not initialized".to_string()),
page: Err("page was not initialized".to_string()),
per_page: Err("per_page was not initialized".to_string()),
zone_id: Err("zone_id was not initialized".to_string()),
}
}
pub fn limit<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<i64>,
{
self.limit = value
.try_into()
.map_err(|_| "conversion to `i64` for limit failed".to_string());
self
}
pub fn offset<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<i64>,
{
self.offset = value
.try_into()
.map_err(|_| "conversion to `i64` for offset 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 fn zone_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::TlsCertificatesAndHostnamesIdentifier>,
{
self.zone_id = value.try_into().map_err(|_| {
"conversion to `TlsCertificatesAndHostnamesIdentifier` for zone_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,
limit,
offset,
page,
per_page,
zone_id,
} = self;
let limit = limit.map_err(Error::InvalidRequest)?;
let offset = offset.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let zone_id = zone_id.map_err(Error::InvalidRequest)?;
let url = format!("{}/certificates", 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("limit", &limit))
.query(&progenitor_client::QueryParam::new("offset", &offset))
.query(&progenitor_client::QueryParam::new("page", &page))
.query(&progenitor_client::QueryParam::new("per_page", &per_page))
.query(&progenitor_client::QueryParam::new("zone_id", &zone_id))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "origin_ca_list_certificates",
};
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 OriginCaCreateCertificate<'a> {
client: &'a crate::Client,
body: Result<types::builder::OriginCaCreateCertificateBody, String>,
}
impl<'a> OriginCaCreateCertificate<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
body: Ok(::std::default::Default::default()),
}
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::OriginCaCreateCertificateBody>,
<V as std::convert::TryInto<types::OriginCaCreateCertificateBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `OriginCaCreateCertificateBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::OriginCaCreateCertificateBody,
) -> types::builder::OriginCaCreateCertificateBody,
{
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, body } = self;
let body = body
.and_then(|v| {
types::OriginCaCreateCertificateBody::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!("{}/certificates", 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
.post(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "origin_ca_create_certificate",
};
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)),
}
}
}
mod by;
pub use by::*;