thunkmetrc_client/services/
items.rs1use 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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