Skip to main content

thunkmetrc_client/services/
items.rs

1use crate::client::MetrcClient;
2use serde_json::Value;
3use std::error::Error;
4
5pub struct ItemsClient<'a> {
6    pub(crate) client: &'a MetrcClient,
7}
8
9impl<'a> ItemsClient<'a> {
10    /// POST CreateBrand
11    /// Creates one or more new item brands for the specified Facility identified by the License Number.
12    /// Permissions Required:
13    /// - Manage Items
14    /// Parameters:
15    /// - body (Option<&Value>): Request body
16    /// - license_number (Option<String>): Filter by licenseNumber
17    pub async fn create_items_brand(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
18        let mut path = format!("/items/v2/brand");
19        let mut query_params = Vec::new();
20        if let Some(p) = license_number {
21            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
22        }
23        if !query_params.is_empty() {
24            path.push_str("?");
25            path.push_str(&query_params.join("&"));
26        }
27
28        self.client.send(reqwest::Method::POST, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
29    }
30    /// POST CreateFile
31    /// Uploads one or more image or PDF files for products, labels, packaging, or documents at the specified Facility.
32    /// Permissions Required:
33    /// - Manage Items
34    /// Parameters:
35    /// - body (Option<&Value>): Request body
36    /// - license_number (Option<String>): Filter by licenseNumber
37    pub async fn create_items_file(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
38        let mut path = format!("/items/v2/file");
39        let mut query_params = Vec::new();
40        if let Some(p) = license_number {
41            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
42        }
43        if !query_params.is_empty() {
44            path.push_str("?");
45            path.push_str(&query_params.join("&"));
46        }
47
48        self.client.send(reqwest::Method::POST, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
49    }
50    /// POST CreateItems
51    /// Permissions Required:
52    /// - Manage Items
53    /// Parameters:
54    /// - body (Option<&Value>): Request body
55    /// - license_number (Option<String>): Filter by licenseNumber
56    pub async fn create_items(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
57        let mut path = format!("/items/v2");
58        let mut query_params = Vec::new();
59        if let Some(p) = license_number {
60            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
61        }
62        if !query_params.is_empty() {
63            path.push_str("?");
64            path.push_str(&query_params.join("&"));
65        }
66
67        self.client.send(reqwest::Method::POST, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
68    }
69    /// POST CreatePhoto
70    /// This endpoint allows only BMP, GIF, JPG, and PNG files and uploaded files can be no more than 5 MB in size.
71    /// Permissions Required:
72    /// - Manage Items
73    /// Parameters:
74    /// - body (Option<&Value>): Request body
75    /// - license_number (Option<String>): Filter by licenseNumber
76    pub async fn create_items_photo(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
77        let mut path = format!("/items/v2/photo");
78        let mut query_params = Vec::new();
79        if let Some(p) = license_number {
80            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
81        }
82        if !query_params.is_empty() {
83            path.push_str("?");
84            path.push_str(&query_params.join("&"));
85        }
86
87        self.client.send(reqwest::Method::POST, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
88    }
89    /// DELETE DeleteBrandById
90    /// Archives the specified Item Brand by Id for the given Facility License Number.
91    /// Permissions Required:
92    /// - Manage Items
93    /// Parameters:
94    /// - id (str): Path parameter id
95    /// - license_number (Option<String>): Filter by licenseNumber
96    pub async fn delete_items_brand_by_id(&self, id: &str, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
97        let mut path = format!("/items/v2/brand/{}", urlencoding::encode(id).as_ref());
98        let mut query_params = Vec::new();
99        if let Some(p) = license_number {
100            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
101        }
102        if !query_params.is_empty() {
103            path.push_str("?");
104            path.push_str(&query_params.join("&"));
105        }
106
107        self.client.send(reqwest::Method::DELETE, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
108    }
109    /// DELETE DeleteItemsById
110    /// Archives the specified Product by Id for the given Facility License Number.
111    /// Permissions Required:
112    /// - Manage Items
113    /// Parameters:
114    /// - id (str): Path parameter id
115    /// - license_number (Option<String>): Filter by licenseNumber
116    pub async fn delete_items_by_id(&self, id: &str, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
117        let mut path = format!("/items/v2/{}", urlencoding::encode(id).as_ref());
118        let mut query_params = Vec::new();
119        if let Some(p) = license_number {
120            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
121        }
122        if !query_params.is_empty() {
123            path.push_str("?");
124            path.push_str(&query_params.join("&"));
125        }
126
127        self.client.send(reqwest::Method::DELETE, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
128    }
129    /// GET GetActiveItems
130    /// Returns a list of active items for the specified Facility.
131    /// Permissions Required:
132    /// - Manage Items
133    /// Parameters:
134    /// - last_modified_end (Option<String>): Filter by lastModifiedEnd
135    /// - last_modified_start (Option<String>): Filter by lastModifiedStart
136    /// - license_number (Option<String>): Filter by licenseNumber
137    /// - page_number (Option<String>): Filter by pageNumber
138    /// - page_size (Option<String>): Filter by pageSize
139    pub async fn get_active_items(&self, last_modified_end: Option<String>, last_modified_start: Option<String>, license_number: Option<String>, page_number: Option<String>, page_size: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
140        let mut path = format!("/items/v2/active");
141        let mut query_params = Vec::new();
142        if let Some(p) = last_modified_end {
143            query_params.push(format!("lastModifiedEnd={}", urlencoding::encode(&p)));
144        }
145        if let Some(p) = last_modified_start {
146            query_params.push(format!("lastModifiedStart={}", urlencoding::encode(&p)));
147        }
148        if let Some(p) = license_number {
149            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
150        }
151        if let Some(p) = page_number {
152            query_params.push(format!("pageNumber={}", urlencoding::encode(&p)));
153        }
154        if let Some(p) = page_size {
155            query_params.push(format!("pageSize={}", urlencoding::encode(&p)));
156        }
157        if !query_params.is_empty() {
158            path.push_str("?");
159            path.push_str(&query_params.join("&"));
160        }
161
162        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
163    }
164    /// GET GetBrands
165    /// Retrieves a list of active item brands for the specified Facility.
166    /// Permissions Required:
167    /// - Manage Items
168    /// Parameters:
169    /// - license_number (Option<String>): Filter by licenseNumber
170    /// - page_number (Option<String>): Filter by pageNumber
171    /// - page_size (Option<String>): Filter by pageSize
172    pub async fn get_items_brands(&self, license_number: Option<String>, page_number: Option<String>, page_size: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
173        let mut path = format!("/items/v2/brands");
174        let mut query_params = Vec::new();
175        if let Some(p) = license_number {
176            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
177        }
178        if let Some(p) = page_number {
179            query_params.push(format!("pageNumber={}", urlencoding::encode(&p)));
180        }
181        if let Some(p) = page_size {
182            query_params.push(format!("pageSize={}", urlencoding::encode(&p)));
183        }
184        if !query_params.is_empty() {
185            path.push_str("?");
186            path.push_str(&query_params.join("&"));
187        }
188
189        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
190    }
191    /// GET GetCategories
192    /// Retrieves a list of item categories.
193    /// Parameters:
194    /// - license_number (Option<String>): Filter by licenseNumber
195    /// - page_number (Option<String>): Filter by pageNumber
196    /// - page_size (Option<String>): Filter by pageSize
197    pub async fn get_items_categories(&self, license_number: Option<String>, page_number: Option<String>, page_size: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
198        let mut path = format!("/items/v2/categories");
199        let mut query_params = Vec::new();
200        if let Some(p) = license_number {
201            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
202        }
203        if let Some(p) = page_number {
204            query_params.push(format!("pageNumber={}", urlencoding::encode(&p)));
205        }
206        if let Some(p) = page_size {
207            query_params.push(format!("pageSize={}", urlencoding::encode(&p)));
208        }
209        if !query_params.is_empty() {
210            path.push_str("?");
211            path.push_str(&query_params.join("&"));
212        }
213
214        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
215    }
216    /// GET GetFileById
217    /// Retrieves a file by its Id for the specified Facility.
218    /// Permissions Required:
219    /// - Manage Items
220    /// Parameters:
221    /// - id (str): Path parameter id
222    /// - license_number (Option<String>): Filter by licenseNumber
223    pub async fn get_items_file_by_id(&self, id: &str, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
224        let mut path = format!("/items/v2/file/{}", urlencoding::encode(id).as_ref());
225        let mut query_params = Vec::new();
226        if let Some(p) = license_number {
227            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
228        }
229        if !query_params.is_empty() {
230            path.push_str("?");
231            path.push_str(&query_params.join("&"));
232        }
233
234        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
235    }
236    /// GET GetInactiveItems
237    /// Retrieves a list of inactive items for the specified Facility.
238    /// Permissions Required:
239    /// - Manage Items
240    /// Parameters:
241    /// - license_number (Option<String>): Filter by licenseNumber
242    /// - page_number (Option<String>): Filter by pageNumber
243    /// - page_size (Option<String>): Filter by pageSize
244    pub async fn get_inactive_items(&self, license_number: Option<String>, page_number: Option<String>, page_size: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
245        let mut path = format!("/items/v2/inactive");
246        let mut query_params = Vec::new();
247        if let Some(p) = license_number {
248            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
249        }
250        if let Some(p) = page_number {
251            query_params.push(format!("pageNumber={}", urlencoding::encode(&p)));
252        }
253        if let Some(p) = page_size {
254            query_params.push(format!("pageSize={}", urlencoding::encode(&p)));
255        }
256        if !query_params.is_empty() {
257            path.push_str("?");
258            path.push_str(&query_params.join("&"));
259        }
260
261        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
262    }
263    /// GET GetItemsById
264    /// Retrieves detailed information about a specific Item by Id.
265    /// Permissions Required:
266    /// - Manage Items
267    /// Parameters:
268    /// - id (str): Path parameter id
269    /// - license_number (Option<String>): Filter by licenseNumber
270    pub async fn get_items_by_id(&self, id: &str, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
271        let mut path = format!("/items/v2/{}", urlencoding::encode(id).as_ref());
272        let mut query_params = Vec::new();
273        if let Some(p) = license_number {
274            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
275        }
276        if !query_params.is_empty() {
277            path.push_str("?");
278            path.push_str(&query_params.join("&"));
279        }
280
281        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
282    }
283    /// GET GetPhotoById
284    /// Retrieves an image by its Id for the specified Facility.
285    /// Permissions Required:
286    /// - Manage Items
287    /// Parameters:
288    /// - id (str): Path parameter id
289    /// - license_number (Option<String>): Filter by licenseNumber
290    pub async fn get_items_photo_by_id(&self, id: &str, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
291        let mut path = format!("/items/v2/photo/{}", urlencoding::encode(id).as_ref());
292        let mut query_params = Vec::new();
293        if let Some(p) = license_number {
294            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
295        }
296        if !query_params.is_empty() {
297            path.push_str("?");
298            path.push_str(&query_params.join("&"));
299        }
300
301        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
302    }
303    /// PUT UpdateBrand
304    /// Updates one or more existing item brands for the specified Facility.
305    /// Permissions Required:
306    /// - Manage Items
307    /// Parameters:
308    /// - body (Option<&Value>): Request body
309    /// - license_number (Option<String>): Filter by licenseNumber
310    pub async fn update_items_brand(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
311        let mut path = format!("/items/v2/brand");
312        let mut query_params = Vec::new();
313        if let Some(p) = license_number {
314            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
315        }
316        if !query_params.is_empty() {
317            path.push_str("?");
318            path.push_str(&query_params.join("&"));
319        }
320
321        self.client.send(reqwest::Method::PUT, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
322    }
323    /// PUT UpdateItems
324    /// Updates one or more existing products for the specified Facility.
325    /// Permissions Required:
326    /// - Manage Items
327    /// Parameters:
328    /// - body (Option<&Value>): Request body
329    /// - license_number (Option<String>): Filter by licenseNumber
330    pub async fn update_items(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
331        let mut path = format!("/items/v2");
332        let mut query_params = Vec::new();
333        if let Some(p) = license_number {
334            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
335        }
336        if !query_params.is_empty() {
337            path.push_str("?");
338            path.push_str(&query_params.join("&"));
339        }
340
341        self.client.send(reqwest::Method::PUT, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
342    }
343}
344