-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathUsEnrichmentBusinessNameSearchExample.java
More file actions
78 lines (66 loc) · 3.29 KB
/
Copy pathUsEnrichmentBusinessNameSearchExample.java
File metadata and controls
78 lines (66 loc) · 3.29 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
package examples;
import com.smartystreets.api.BasicAuthCredentials;
import com.smartystreets.api.ClientBuilder;
import com.smartystreets.api.exceptions.SmartyException;
import com.smartystreets.api.us_enrichment.Client;
import com.smartystreets.api.us_enrichment.lookup_types.business.BusinessSummaryLookup;
import com.smartystreets.api.us_enrichment.result_types.AddressSearch;
import com.smartystreets.api.us_enrichment.result_types.business.BusinessDetailResponse;
import com.smartystreets.api.us_enrichment.result_types.business.BusinessEntry;
import com.smartystreets.api.us_enrichment.result_types.business.BusinessSummaryResponse;
import java.io.IOException;
public class UsEnrichmentBusinessNameSearchExample {
public static void main(String[] args) {
BasicAuthCredentials credentials = new BasicAuthCredentials(System.getenv("SMARTY_AUTH_ID"), System.getenv("SMARTY_AUTH_TOKEN"));
try (Client client = new ClientBuilder(credentials).buildUsEnrichmentClient()) {
String businessName = "delta air";
BusinessSummaryLookup lookup = new BusinessSummaryLookup();
lookup.setAddressSearch(new AddressSearch()
.withBusinessName(businessName)
.withCity("atlanta"));
BusinessSummaryResponse[] summaryResults;
try {
summaryResults = client.sendBusinessSummary(lookup);
} catch (SmartyException | InterruptedException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
return;
}
if (summaryResults == null || summaryResults.length == 0) {
System.out.println("No response returned for the business-name search");
return;
}
BusinessSummaryResponse summary = summaryResults[0];
if (summary.getBusinesses() == null || summary.getBusinesses().length == 0) {
System.out.println("No businesses found for this business name search");
return;
}
System.out.println("Summary results for BusinessName: " + businessName);
for (BusinessEntry entry : summary.getBusinesses()) {
System.out.println(" - " + entry.getCompanyName() + " (ID: " + entry.getBusinessId() + ")");
}
BusinessEntry first = summary.getBusinesses()[0];
System.out.println();
System.out.println("Fetching details for business: " + first.getCompanyName() + " (ID: " + first.getBusinessId() + ")");
BusinessDetailResponse detail;
try {
detail = client.sendBusinessDetail(first.getBusinessId());
} catch (SmartyException | InterruptedException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
return;
}
if (detail != null) {
System.out.println();
System.out.println("Detail result:");
System.out.println(detail);
} else {
System.out.println();
System.out.println("No detail result returned");
}
} catch (IOException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
}