thunkmetrc_client/services/
lab_tests.rs1use crate::client::MetrcClient;
2use serde_json::Value;
3use std::error::Error;
4
5pub struct LabTestsClient<'a> {
6 pub(crate) client: &'a MetrcClient,
7}
8
9impl<'a> LabTestsClient<'a> {
10 pub async fn create_lab_tests_record(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
19 let mut path = format!("/labtests/v2/record");
20 let mut query_params = Vec::new();
21 if let Some(p) = license_number {
22 query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
23 }
24 if !query_params.is_empty() {
25 path.push_str("?");
26 path.push_str(&query_params.join("&"));
27 }
28
29 self.client.send(reqwest::Method::POST, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
30 }
31 pub async fn get_lab_tests_batches(&self, page_number: Option<String>, page_size: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
37 let mut path = format!("/labtests/v2/batches");
38 let mut query_params = Vec::new();
39 if let Some(p) = page_number {
40 query_params.push(format!("pageNumber={}", urlencoding::encode(&p)));
41 }
42 if let Some(p) = page_size {
43 query_params.push(format!("pageSize={}", urlencoding::encode(&p)));
44 }
45 if !query_params.is_empty() {
46 path.push_str("?");
47 path.push_str(&query_params.join("&"));
48 }
49
50 self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
51 }
52 pub async fn get_lab_tests_lab_test_document_by_id(&self, id: &str, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
61 let mut path = format!("/labtests/v2/labtestdocument/{}", urlencoding::encode(id).as_ref());
62 let mut query_params = Vec::new();
63 if let Some(p) = license_number {
64 query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
65 }
66 if !query_params.is_empty() {
67 path.push_str("?");
68 path.push_str(&query_params.join("&"));
69 }
70
71 self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
72 }
73 pub async fn get_lab_tests_types(&self, page_number: Option<String>, page_size: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
79 let mut path = format!("/labtests/v2/types");
80 let mut query_params = Vec::new();
81 if let Some(p) = page_number {
82 query_params.push(format!("pageNumber={}", urlencoding::encode(&p)));
83 }
84 if let Some(p) = page_size {
85 query_params.push(format!("pageSize={}", urlencoding::encode(&p)));
86 }
87 if !query_params.is_empty() {
88 path.push_str("?");
89 path.push_str(&query_params.join("&"));
90 }
91
92 self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
93 }
94 pub async fn get_lab_tests_results(&self, license_number: Option<String>, package_id: Option<String>, page_number: Option<String>, page_size: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
105 let mut path = format!("/labtests/v2/results");
106 let mut query_params = Vec::new();
107 if let Some(p) = license_number {
108 query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
109 }
110 if let Some(p) = package_id {
111 query_params.push(format!("packageId={}", urlencoding::encode(&p)));
112 }
113 if let Some(p) = page_number {
114 query_params.push(format!("pageNumber={}", urlencoding::encode(&p)));
115 }
116 if let Some(p) = page_size {
117 query_params.push(format!("pageSize={}", urlencoding::encode(&p)));
118 }
119 if !query_params.is_empty() {
120 path.push_str("?");
121 path.push_str(&query_params.join("&"));
122 }
123
124 self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
125 }
126 pub async fn get_lab_tests_states(&self, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
130 let path = format!("/labtests/v2/states");
131
132 self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
133 }
134 pub async fn update_lab_tests_lab_test_document(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
143 let mut path = format!("/labtests/v2/labtestdocument");
144 let mut query_params = Vec::new();
145 if let Some(p) = license_number {
146 query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
147 }
148 if !query_params.is_empty() {
149 path.push_str("?");
150 path.push_str(&query_params.join("&"));
151 }
152
153 self.client.send(reqwest::Method::PUT, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
154 }
155 pub async fn update_lab_tests_results_release(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
164 let mut path = format!("/labtests/v2/results/release");
165 let mut query_params = Vec::new();
166 if let Some(p) = license_number {
167 query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
168 }
169 if !query_params.is_empty() {
170 path.push_str("?");
171 path.push_str(&query_params.join("&"));
172 }
173
174 self.client.send(reqwest::Method::PUT, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
175 }
176}
177