/
us_extract_api.rs
42 lines (34 loc) · 1.36 KB
/
us_extract_api.rs
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
38
39
40
41
42
extern crate serde_json;
extern crate smarty_rust_sdk;
extern crate tokio;
use smarty_rust_sdk::sdk::authentication::SecretKeyCredential;
use smarty_rust_sdk::sdk::options::OptionsBuilder;
use smarty_rust_sdk::us_extract_api::client::USExtractClient;
use smarty_rust_sdk::us_extract_api::lookup::Lookup;
use smarty_rust_sdk::us_street_api::lookup::MatchStrategy;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let lookup = &mut Lookup {
text: "Meet me at 3214 N University Ave Provo UT 84604 just after 3pm.\n\
Or! We could meet at 1600 Pennsylvania Ave, Washington DC."
.to_string(),
aggressive: true,
addresses_with_line_breaks: true,
addresses_per_line: 2,
match_strategy: MatchStrategy::Enhanced,
..Default::default()
};
let authentication = SecretKeyCredential::new(
std::env::var("SMARTY_AUTH_ID").expect("Missing SMARTY_AUTH_ID env variable"),
std::env::var("SMARTY_AUTH_TOKEN").expect("Missing SMARTY_AUTH_TOKEN env variable"),
);
let options = OptionsBuilder::new(Some(authentication))
.with_license("us-core-cloud")
.with_logging()
.build();
let client = USExtractClient::new(options)?;
client.send(lookup).await?;
println!("{}", serde_json::to_string_pretty(&lookup.result)?);
Ok(())
}