smarty_rust_sdk/us_enrichment_api/
client.rs1use crate::sdk::client::Client;
2use crate::sdk::error::SmartyError;
3use crate::sdk::options::Options;
4use crate::sdk::send_request;
5use crate::us_enrichment_api::lookup::EnrichmentLookup;
6use crate::us_enrichment_api::results::EnrichmentResponse;
7use reqwest::Method;
8use serde::de::DeserializeOwned;
9use smarty_rust_proc_macro::smarty_api;
10
11#[smarty_api(
12 api_path = "lookup",
13 default_url = "https://us-enrichment.api.smarty.com/",
14 lookup_style(lookup),
15 lookup_type = "EnrichmentLookup",
16 result_type = "Results",
17 custom_send = true
18)]
19pub struct USEnrichmentClient;
20
21impl USEnrichmentClient {
22 pub async fn send<R: EnrichmentResponse + DeserializeOwned>(
26 &self,
27 lookup: &mut EnrichmentLookup<R>,
28 ) -> Result<(), SmartyError> {
29 let mut url = self.client.url.clone();
30 url = url.join(&format!(
31 "/lookup/{}/property/{}",
32 lookup.smarty_key,
33 R::lookup_type()
34 ))?;
35
36 let mut req = self.client.reqwest_client.request(Method::GET, url);
37 req = self.client.build_request(req);
38
39 let candidates = send_request::<Vec<R>>(req).await?;
40
41 lookup.set_results(candidates);
42
43 Ok(())
44 }
45}