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