use crate::internal::path_escape;
use crate::runtime::{self, Error};
#[derive(Clone, Debug, Default)]
pub struct ShieldInformationBarrierSegmentRestrictionsListOptions {
pub marker: Option<String>,
pub limit: Option<i64>,
}
pub struct ShieldInformationBarrierSegmentRestrictionsListPaginator {
manager: ShieldInformationBarrierSegmentRestrictionsManager,
shield_information_barrier_segment_id: String,
options: ShieldInformationBarrierSegmentRestrictionsListOptions,
buffer: std::vec::IntoIter<crate::models::schemas::ShieldInformationBarrierSegmentRestriction>,
done: bool,
}
impl ShieldInformationBarrierSegmentRestrictionsListPaginator {
pub async fn next(
&mut self,
) -> Option<Result<crate::models::schemas::ShieldInformationBarrierSegmentRestriction, Error>>
{
loop {
if let Some(item) = self.buffer.next() {
return Some(Ok(item));
}
if self.done {
return None;
}
let page = match self
.manager
.list_page(
self.shield_information_barrier_segment_id.clone(),
Some(self.options.clone()),
)
.await
{
Ok(page) => page,
Err(err) => {
self.done = true;
return Some(Err(err));
}
};
self.buffer = page.entries.unwrap_or_default().into_iter();
match page.next_marker.flatten() {
Some(cursor) if !cursor.is_empty() => self.options.marker = Some(cursor),
_ => self.done = true,
}
}
}
}
pub struct ShieldInformationBarrierSegmentRestrictionsManager {
session: std::sync::Arc<runtime::Client>,
}
impl ShieldInformationBarrierSegmentRestrictionsManager {
pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
Self { session }
}
pub async fn get(
&self,
shield_information_barrier_segment_restriction_id: String,
) -> Result<crate::models::schemas::ShieldInformationBarrierSegmentRestriction, Error> {
let mut url = self.session.base_url("api");
url.push_str("/shield_information_barrier_segment_restrictions");
url.push('/');
let seg = path_escape(&shield_information_barrier_segment_restriction_id);
url.push_str(&seg);
let req = self.session.new_request("GET", &url);
let resp = self.session.fetch(req).await?;
let data = runtime::response_bytes(&resp)?;
Ok(serde_json::from_slice(&data)?)
}
pub async fn delete(
&self,
shield_information_barrier_segment_restriction_id: String,
) -> Result<(), Error> {
let mut url = self.session.base_url("api");
url.push_str("/shield_information_barrier_segment_restrictions");
url.push('/');
let seg = path_escape(&shield_information_barrier_segment_restriction_id);
url.push_str(&seg);
let req = self.session.new_request("DELETE", &url);
let _ = self.session.fetch(req).await?;
Ok(())
}
async fn list_page(
&self,
shield_information_barrier_segment_id: String,
opts: Option<ShieldInformationBarrierSegmentRestrictionsListOptions>,
) -> Result<crate::models::schemas::ShieldInformationBarrierSegmentRestrictions, Error> {
let mut url = self.session.base_url("api");
url.push_str("/shield_information_barrier_segment_restrictions");
let mut req = self.session.new_request("GET", &url);
let arg = shield_information_barrier_segment_id;
req = runtime::with_query(req, "shield_information_barrier_segment_id", &arg);
let opts = opts.unwrap_or_default();
if let Some(value) = opts.marker {
req = runtime::with_query(req, "marker", &value);
}
if let Some(value) = opts.limit {
req = runtime::with_query(req, "limit", &value.to_string());
}
let resp = self.session.fetch(req).await?;
let data = runtime::response_bytes(&resp)?;
Ok(serde_json::from_slice(&data)?)
}
pub fn list(
&self,
shield_information_barrier_segment_id: String,
opts: Option<ShieldInformationBarrierSegmentRestrictionsListOptions>,
) -> ShieldInformationBarrierSegmentRestrictionsListPaginator {
ShieldInformationBarrierSegmentRestrictionsListPaginator {
manager: ShieldInformationBarrierSegmentRestrictionsManager::new(self.session.clone()),
shield_information_barrier_segment_id,
options: opts.unwrap_or_default(),
buffer: Vec::new().into_iter(),
done: false,
}
}
pub async fn create(
&self,
body: crate::models::schemas::ShieldInformationBarrierSegmentRestrictionCreateRequest,
) -> Result<crate::models::schemas::ShieldInformationBarrierSegmentRestriction, Error> {
let mut url = self.session.base_url("api");
url.push_str("/shield_information_barrier_segment_restrictions");
let mut req = self.session.new_request("POST", &url);
let payload = serde_json::to_vec(&body)?;
req = runtime::with_json_body(req, &payload);
let resp = self.session.fetch(req).await?;
let data = runtime::response_bytes(&resp)?;
Ok(serde_json::from_slice(&data)?)
}
}