/
us_zipcode_api.rs
53 lines (43 loc) · 1.43 KB
/
us_zipcode_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
43
44
45
46
47
48
49
50
51
52
53
extern crate serde_json;
extern crate smarty_rust_sdk;
extern crate tokio;
use smarty_rust_sdk::sdk::authentication::SecretKeyCredential;
use smarty_rust_sdk::sdk::batch::Batch;
use smarty_rust_sdk::sdk::options::OptionsBuilder;
use smarty_rust_sdk::us_zipcode_api::client::USZipcodeClient;
use smarty_rust_sdk::us_zipcode_api::lookup::Lookup;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let lookup1 = Lookup {
city: "PROVO".to_string(),
state: "UT".to_string(),
zipcode: "84604".to_string(),
..Default::default()
};
let lookup2 = Lookup {
zipcode: "90210".to_string(),
..Default::default()
};
let batch = &mut Batch::default();
batch.push(lookup1)?;
batch.push(lookup2)?;
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")
.build();
let client = USZipcodeClient::new(options)?;
client.send(batch).await?;
println!(
"{}",
serde_json::to_string_pretty(&batch.records()[0].results.clone())?
);
println!(
"{}",
serde_json::to_string_pretty(&batch.records()[1].results.clone())?
);
Ok(())
}