dfns_sdk_rust/allocations/
mod.rs1pub mod delegated;
4pub mod types;
5
6#[allow(unused_imports)]
7use types::*;
8
9#[derive(Clone)]
11pub struct AllocationsClient {
12 client: crate::client::Client,
13}
14
15impl AllocationsClient {
16 pub fn new(client: crate::client::Client) -> Self {
17 AllocationsClient { client }
18 }
19
20 pub async fn list_allocations(
22 &self,
23 query: Option<ListAllocationsQuery>,
24 ) -> Result<ListAllocationsResponse, crate::error::Error> {
25 let mut path = String::from("/allocations");
26 if let Some(query) = &query {
27 let mut q: Vec<String> = Vec::new();
28 if let Some(v) = &query.limit {
29 q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
30 }
31 if let Some(v) = &query.pagination_token {
32 q.push(format!(
33 "paginationToken={}",
34 urlencoding::encode(&v.to_string())
35 ));
36 }
37 if !q.is_empty() {
38 path.push('?');
39 path.push_str(&q.join("&"));
40 }
41 }
42 self.client
43 .request::<ListAllocationsResponse>(reqwest::Method::GET, &path, None, false)
44 .await
45 }
46
47 pub async fn create_allocation(
52 &self,
53 body: CreateAllocationRequest,
54 ) -> Result<CreateAllocationResponse, crate::error::Error> {
55 let path = String::from("/allocations");
56 let body = serde_json::to_value(&body)?;
57 self.client
58 .request::<CreateAllocationResponse>(reqwest::Method::POST, &path, Some(&body), true)
59 .await
60 }
61
62 pub async fn list_allocation_actions(
64 &self,
65 allocation_id: String,
66 query: Option<ListAllocationActionsQuery>,
67 ) -> Result<ListAllocationActionsResponse, crate::error::Error> {
68 let mut path = format!(
69 "/allocations/{}/actions",
70 urlencoding::encode(&allocation_id)
71 );
72 if let Some(query) = &query {
73 let mut q: Vec<String> = Vec::new();
74 if let Some(v) = &query.limit {
75 q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
76 }
77 if let Some(v) = &query.pagination_token {
78 q.push(format!(
79 "paginationToken={}",
80 urlencoding::encode(&v.to_string())
81 ));
82 }
83 if !q.is_empty() {
84 path.push('?');
85 path.push_str(&q.join("&"));
86 }
87 }
88 self.client
89 .request::<ListAllocationActionsResponse>(reqwest::Method::GET, &path, None, false)
90 .await
91 }
92
93 pub async fn create_allocation_action(
95 &self,
96 allocation_id: String,
97 body: CreateAllocationActionRequest,
98 ) -> Result<CreateAllocationActionResponse, crate::error::Error> {
99 let path = format!(
100 "/allocations/{}/actions",
101 urlencoding::encode(&allocation_id)
102 );
103 let body = serde_json::to_value(&body)?;
104 self.client
105 .request::<CreateAllocationActionResponse>(
106 reqwest::Method::POST,
107 &path,
108 Some(&body),
109 true,
110 )
111 .await
112 }
113
114 pub async fn get_allocation(
116 &self,
117 allocation_id: String,
118 ) -> Result<GetAllocationResponse, crate::error::Error> {
119 let path = format!("/allocations/{}", urlencoding::encode(&allocation_id));
120 self.client
121 .request::<GetAllocationResponse>(reqwest::Method::GET, &path, None, false)
122 .await
123 }
124
125 pub async fn get_allocations_info(
127 &self,
128 ) -> Result<GetAllocationsInfoResponse, crate::error::Error> {
129 let path = String::from("/allocations/info");
130 self.client
131 .request::<GetAllocationsInfoResponse>(reqwest::Method::GET, &path, None, false)
132 .await
133 }
134}