-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathUsEnrichmentExample.java
More file actions
166 lines (143 loc) · 8.15 KB
/
UsEnrichmentExample.java
File metadata and controls
166 lines (143 loc) · 8.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package examples;
import com.smartystreets.api.BasicAuthCredentials;
import com.smartystreets.api.ClientBuilder;
import com.smartystreets.api.exceptions.NotModifiedException;
import com.smartystreets.api.exceptions.SmartyException;
import com.smartystreets.api.us_enrichment.*;
import com.smartystreets.api.us_enrichment.lookup_types.property_principal.PropertyPrincipalLookup;
import com.smartystreets.api.us_enrichment.lookup_types.georeference.GeoReferenceLookup;
import com.smartystreets.api.us_enrichment.lookup_types.risk.RiskLookup;
import com.smartystreets.api.us_enrichment.lookup_types.secondary.SecondaryCountLookup;
import com.smartystreets.api.us_enrichment.lookup_types.secondary.SecondaryLookup;
import com.smartystreets.api.us_enrichment.result_types.georeference.GeoReferenceResponse;
import com.smartystreets.api.us_enrichment.result_types.property_principal.PrincipalResponse;
import com.smartystreets.api.us_enrichment.result_types.risk.RiskResponse;
import com.smartystreets.api.us_enrichment.result_types.secondary.Secondary;
import com.smartystreets.api.us_enrichment.result_types.secondary.SecondaryCountResponse;
import com.smartystreets.api.us_enrichment.result_types.secondary.SecondaryResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;
public class UsEnrichmentExample {
public static void main(String[] args) {
// 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).buildUsEnrichmentClient()) {
String smartyKey = "87844267";
String smartyKeyWithSecondaries = "325023201";
String include = ""; // example: "group_structural,sale_date";
String exclude = "";
String features = "financial";
// ************************ Property Principal ************************
PropertyPrincipalLookup principalLookup = new PropertyPrincipalLookup();
principalLookup.setSmartyKey(smartyKey);
principalLookup.setInclude(include);
principalLookup.setFeatures(features);
// To perform an address lookup instead of by SmartyKey you would uncomment the following line and comment setting the SmartyKey
// principalLookup.setAddressSearch(new AddressSearch().withStreet("56 Union Ave").withCity("Somerville").withState("NJ").withZipcode("08876"));
// To set the ETag value from a previous call, uncomment the following line and set the appropriate ETag value
// principalLookup.setEtag("GMYDMOBZGIZTGMJQ");
PrincipalResponse[] principalResults = null;
try {
principalResults = client.sendPropertyPrincipal(principalLookup);
} catch (NotModifiedException ex) {
System.out.println(ex.getMessage());
return;
} catch (SmartyException | InterruptedException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
if(principalResults != null){
System.out.println("Address Lookup:\n" + Arrays.toString(principalResults));
} else {
System.out.println("Result was null");
}
// ************************ GeoReference ************************
GeoReferenceLookup geoReferenceLookup = new GeoReferenceLookup(""); // the parameter is the subset (2010 or 2020)
geoReferenceLookup.setSmartyKey(smartyKey);
//geoReferenceLookup.setAddressSearch(new AddressSearch().withStreet("56 Union Ave").withCity("Somerville").withState("NJ").withZipcode("08876"));
//geoReferenceLookup.setEtag("GEYTENBXGY3TKMRU");
GeoReferenceResponse[] geoReferenceResults = null;
try {
geoReferenceResults = client.sendGeoReference(geoReferenceLookup);
} catch (NotModifiedException ex) {
System.out.println(ex.getMessage());
return;
} catch (SmartyException | InterruptedException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
if (geoReferenceResults != null) {
System.out.println(Arrays.toString(geoReferenceResults));
} else {
System.out.println("Result was null");
}
// ************************ Risk ************************
RiskLookup riskLookup = new RiskLookup();
riskLookup.setSmartyKey(smartyKey);
//riskLookup.setAddressSearch(new AddressSearch().withStreet("56 Union Ave").withCity("Somerville").withState("NJ").withZipcode("08876"));
//riskLookup.setEtag("GEYTENBXGY3TKMRU");
RiskResponse[] riskResults = null;
try {
riskResults = client.sendRisk(riskLookup);
} catch (NotModifiedException ex) {
System.out.println(ex.getMessage());
return;
} catch (SmartyException | InterruptedException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
if (riskResults != null) {
System.out.println(Arrays.toString(riskResults));
} else {
System.out.println("Result was null");
}
// ************************ Secondary Count ************************
SecondaryCountLookup secondaryCountLookup = new SecondaryCountLookup();
secondaryCountLookup.setSmartyKey(smartyKeyWithSecondaries);
//secondaryCountLookup.setAddressSearch(new AddressSearch().withStreet("56 Union Ave").withCity("Somerville").withState("NJ").withZipcode("08876"));
//secondaryCountLookup.setEtag("GEYTENBXGY3TKMRU");
SecondaryCountResponse[] secondaryCountResults = null;
try {
secondaryCountResults = client.sendSecondaryCount(secondaryCountLookup);
} catch (NotModifiedException ex) {
System.out.println(ex.getMessage());
return;
} catch (SmartyException | InterruptedException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
if (secondaryCountResults != null){
System.out.println(Arrays.toString(secondaryCountResults));
} else {
System.out.println("Result was null");
}
// ************************ Secondary ************************
SecondaryLookup secondaryLookup = new SecondaryLookup();
secondaryLookup.setSmartyKey(smartyKeyWithSecondaries);
//secondaryLookup.setAddressSearch(new AddressSearch().withStreet("56 Union Ave").withCity("Somerville").withState("NJ").withZipcode("08876"));
//secondaryLookup.setEtag("GEYTENBXGY3TKMRU");
SecondaryResponse[] secondaryResults = null;
try {
secondaryResults = client.sendSecondary(secondaryLookup);
} catch (NotModifiedException ex) {
System.out.println(ex.getMessage());
return;
} catch (SmartyException | InterruptedException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
if (secondaryResults != null){
System.out.println(Arrays.toString(secondaryResults));
System.out.println(Arrays.stream(secondaryResults).flatMap(s -> s.getSecondaries().stream() ).map(Secondary::toString).collect(Collectors.joining("\n")));
} else {
System.out.println("Result was null");
}
} catch (IOException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
}