pub mod types;
#[allow(unused_imports)]
use types::*;
#[derive(Clone)]
pub struct AllocationsClient {
client: crate::client::Client,
}
impl AllocationsClient {
pub fn new(client: crate::client::Client) -> Self {
AllocationsClient { client }
}
pub async fn list_allocations(
&self,
query: Option<ListAllocationsQuery>,
) -> Result<ListAllocationsResponse, crate::error::Error> {
let mut path = String::from("/allocations");
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
if let Some(v) = &query.limit {
q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
}
if let Some(v) = &query.pagination_token {
q.push(format!(
"paginationToken={}",
urlencoding::encode(&v.to_string())
));
}
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<ListAllocationsResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn create_allocation(
&self,
body: CreateAllocationRequest,
) -> Result<CreateAllocationResponse, crate::error::Error> {
let path = String::from("/allocations");
let body = serde_json::to_value(&body)?;
self.client
.request::<CreateAllocationResponse>(reqwest::Method::POST, &path, Some(&body), true)
.await
}
pub async fn list_allocation_actions(
&self,
allocation_id: String,
query: Option<ListAllocationActionsQuery>,
) -> Result<ListAllocationActionsResponse, crate::error::Error> {
let mut path = format!(
"/allocations/{}/actions",
urlencoding::encode(&allocation_id)
);
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
if let Some(v) = &query.limit {
q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
}
if let Some(v) = &query.pagination_token {
q.push(format!(
"paginationToken={}",
urlencoding::encode(&v.to_string())
));
}
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<ListAllocationActionsResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn create_allocation_action(
&self,
allocation_id: String,
body: CreateAllocationActionRequest,
) -> Result<CreateAllocationActionResponse, crate::error::Error> {
let path = format!(
"/allocations/{}/actions",
urlencoding::encode(&allocation_id)
);
let body = serde_json::to_value(&body)?;
self.client
.request::<CreateAllocationActionResponse>(
reqwest::Method::POST,
&path,
Some(&body),
true,
)
.await
}
pub async fn get_allocation(
&self,
allocation_id: String,
) -> Result<GetAllocationResponse, crate::error::Error> {
let path = format!("/allocations/{}", urlencoding::encode(&allocation_id));
self.client
.request::<GetAllocationResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn get_allocations_info(
&self,
) -> Result<GetAllocationsInfoResponse, crate::error::Error> {
let path = String::from("/allocations/info");
self.client
.request::<GetAllocationsInfoResponse>(reqwest::Method::GET, &path, None, false)
.await
}
}