Skip to content

Commit 0434602

Browse files
Updating component analysis and adding example.
1 parent 6f40950 commit 0434602

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ us_reverse_geo_api:
4242
RUST_LOG=trace cargo run --example us_reverse_geo_api
4343

4444
us_street_api:
45-
RUST_LOG=trace cargo run --example us_street_api
45+
RUST_LOG=trace cargo run --example us_street_api && RUST_LOG=trace cargo run --example us_street_component_analysis
4646

4747
us_zipcode_api:
4848
RUST_LOG=trace cargo run --example us_zipcode_api
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
extern crate serde_json;
2+
extern crate smarty_rust_sdk;
3+
extern crate tokio;
4+
5+
use smarty_rust_sdk::us_street_api::lookup::{Lookup, MatchStrategy};
6+
7+
use smarty_rust_sdk::sdk::authentication::SecretKeyCredential;
8+
use smarty_rust_sdk::sdk::batch::Batch;
9+
use smarty_rust_sdk::sdk::options::OptionsBuilder;
10+
use smarty_rust_sdk::us_street_api::client::USStreetAddressClient;
11+
use std::error::Error;
12+
13+
#[tokio::main]
14+
async fn main() -> Result<(), Box<dyn Error>> {
15+
let lookup = Lookup {
16+
street: "1600 Amphitheatre Pkwy".to_string(),
17+
last_line: "Mountain View, CA".to_string(),
18+
max_candidates: 10,
19+
match_strategy: MatchStrategy::Enhanced, // Enhanced matching is required to return component analysis results.
20+
..Default::default()
21+
};
22+
23+
let mut batch = Batch::default();
24+
batch.push(lookup)?;
25+
26+
let authentication = SecretKeyCredential::new(
27+
std::env::var("SMARTY_AUTH_ID").expect("Missing SMARTY_AUTH_ID env variable"),
28+
std::env::var("SMARTY_AUTH_TOKEN").expect("Missing SMARTY_AUTH_TOKEN env variable"),
29+
);
30+
31+
let options = OptionsBuilder::new(Some(authentication))
32+
.with_component_analysis() // To add component analysis feature you need to specify when you create the options for the client.
33+
.build();
34+
35+
let client = USStreetAddressClient::new(options)?;
36+
37+
client.send(&mut batch).await?;
38+
39+
// Here is an example of how to access component analysis
40+
for record in batch.records() {
41+
if !record.results.is_empty() {
42+
println!("Component Analysis Results:\n {}",serde_json::to_string_pretty(&record.results[0].analysis.components)?);
43+
}
44+
}
45+
46+
Ok(())
47+
}

smarty-rust-sdk/src/us_street_api/candidate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ pub struct Analysis {
8787
}
8888

8989
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
90+
#[serde(default)]
9091
pub struct MatchInfo {
9192
pub status: String,
9293
pub change: Vec<String>,
9394
}
9495

9596
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
97+
#[serde(default)]
9698
pub struct ComponentAnalysis {
9799
pub primary_number: MatchInfo,
98100
pub street_predirection: MatchInfo,

0 commit comments

Comments
 (0)