1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::sdk::client::Client;
use crate::sdk::error::SDKError;
use crate::sdk::options::Options;
use crate::sdk::send_request;
use crate::us_extract_api::lookup::Lookup;
use reqwest::Method;
use smarty_rust_proc_macro::smarty_api;
use url::{ParseError, Url};

#[smarty_api(
    api_path = "",
    default_url = "https://us-extract.api.smarty.com/",
    lookup_style(lookup),
    lookup_type = "Lookup",
    result_type = "ExtractionResult",
    custom_send
)]
pub struct USExtractClient;

impl USExtractClient {
    pub async fn send(&self, lookup: &mut Lookup) -> Result<(), SDKError> {
        let mut req = self
            .client
            .reqwest_client
            .request(Method::POST, self.client.url.clone());
        req = self.client.build_request(req);
        req = req.header("Content-Type", "text/plain");
        req = req.query(&lookup.clone().into_param_array());
        req = req.body(lookup.text.clone());

        let response = send_request(req).await?;

        lookup.result = response;

        Ok(())
    }
}