-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathInternationalPostalCodeExample.java
More file actions
50 lines (44 loc) · 2.15 KB
/
InternationalPostalCodeExample.java
File metadata and controls
50 lines (44 loc) · 2.15 KB
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
package examples;
import com.smartystreets.api.BasicAuthCredentials;
import com.smartystreets.api.ClientBuilder;
import com.smartystreets.api.international_postal_code.Candidate;
import com.smartystreets.api.international_postal_code.Client;
import com.smartystreets.api.international_postal_code.Lookup;
public class InternationalPostalCodeExample {
public static void main(String[] args) throws Exception {
// We recommend storing your authentication credentials in environment variables.
// for client-side requests (browser/mobile), use this code:
// SharedCredentials credentials = new SharedCredentials(System.getenv("SMARTY_AUTH_WEB"), System.getenv("SMARTY_AUTH_REFERER"));
BasicAuthCredentials credentials = new BasicAuthCredentials(System.getenv("SMARTY_AUTH_ID"), System.getenv("SMARTY_AUTH_TOKEN"));
try (Client client = new ClientBuilder(credentials)
.buildInternationalPostalCodeApiClient()) {
Lookup lookup = new Lookup();
lookup.setInputId("ID-8675309");
lookup.setLocality("Sao Paulo");
lookup.setAdministrativeArea("SP");
lookup.setCountry("Brazil");
lookup.setPostalCode("02516");
client.send(lookup);
System.out.println("Results:");
System.out.println();
for (Candidate candidate : lookup.getResult()) {
display(candidate.getInputId());
display(candidate.getCountryIso3());
display(candidate.getLocality());
display(candidate.getDependentLocality());
display(candidate.getDoubleDependentLocality());
display(candidate.getSubAdministrativeArea());
display(candidate.getAdministrativeArea());
display(candidate.getSuperAdministrativeArea());
display(candidate.getPostalCode());
System.out.println();
}
System.out.println("OK");
}
}
private static void display(String value) {
if (value != null && value.length() > 0) {
System.out.printf(" %s\n", value);
}
}
}