square_api_client/api/
inventory_api.rs1use crate::{
13 config::Configuration,
14 http::client::HttpClient,
15 models::{
16 errors::ApiError, BatchChangeInventoryRequest, BatchChangeInventoryResponse,
17 BatchRetrieveInventoryChangesRequest, BatchRetrieveInventoryChangesResponse,
18 BatchRetrieveInventoryCountsRequest, BatchRetrieveInventoryCountsResponse,
19 RetrieveInventoryAdjustmentResponse, RetrieveInventoryCountParams,
20 RetrieveInventoryCountResponse, RetrieveInventoryPhysicalCount,
21 RetrieveInventoryTransferResponse,
22 },
23};
24
25const DEFAULT_URI: &str = "/inventory";
26
27pub struct InventoryApi {
28 config: Configuration,
30 client: HttpClient,
32}
33
34impl InventoryApi {
35 pub fn new(config: Configuration, client: HttpClient) -> Self {
36 Self { config, client }
37 }
38
39 pub async fn retrieve_inventory_count(
41 &self,
42 catalog_object_id: &str,
43 params: RetrieveInventoryCountParams,
44 ) -> Result<RetrieveInventoryCountResponse, ApiError> {
45 let url = format!("{}/{}{}", &self.url(), catalog_object_id, params.to_query_string());
46 let response = self.client.get(&url).await?;
47
48 response.deserialize().await
49 }
50
51 pub async fn retrieve_inventory_transfer(
53 &self,
54 transfer_id: &str,
55 ) -> Result<RetrieveInventoryTransferResponse, ApiError> {
56 let url = format!("{}/{}", &self.url(), transfer_id);
57 let response = self.client.get(&url).await?;
58
59 response.deserialize().await
60 }
61
62 pub async fn retrieve_inventory_adjustment(
64 &self,
65 adjustment_id: &str,
66 ) -> Result<RetrieveInventoryAdjustmentResponse, ApiError> {
67 let url = format!("{}/{}", &self.url(), adjustment_id);
68 let response = self.client.get(&url).await?;
69
70 response.deserialize().await
71 }
72
73 pub async fn retrieve_inventory_physical_count(
75 &self,
76 physical_count_id: &str,
77 ) -> Result<RetrieveInventoryPhysicalCount, ApiError> {
78 let url = format!("{}/{}", &self.url(), physical_count_id);
79 let response = self.client.get(&url).await?;
80
81 response.deserialize().await
82 }
83
84 pub async fn batch_change(
88 &self,
89 body: &BatchChangeInventoryRequest,
90 ) -> Result<BatchChangeInventoryResponse, ApiError> {
91 let url = format!("{}/changes/batch-create", &self.url());
92 let response = self.client.post(&url, body).await?;
93
94 response.deserialize().await
95 }
96
97 pub async fn batch_retrieve_count(
100 &self,
101 body: &BatchRetrieveInventoryCountsRequest,
102 ) -> Result<BatchRetrieveInventoryCountsResponse, ApiError> {
103 let url = format!("{}/counts/batch-retrieve", &self.url());
104 let response = self.client.post(&url, body).await?;
105
106 response.deserialize().await
107 }
108
109 pub async fn batch_retrieve_changes(
112 &self,
113 body: &BatchRetrieveInventoryChangesRequest,
114 ) -> Result<BatchRetrieveInventoryChangesResponse, ApiError> {
115 let url = format!("{}/changes/batch-retrieve", &self.url());
116 let response = self.client.post(&url, body).await?;
117
118 response.deserialize().await
119 }
120
121 fn url(&self) -> String {
122 format!("{}{}", &self.config.get_base_url(), DEFAULT_URI)
123 }
124}