Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4ce1eb9

Browse files
author
Bryan Amundson
committedSep 6, 2024·
Added address search lookup capabilities for US Enrichment API.
1 parent 697bca3 commit 4ce1eb9

File tree

4 files changed

+141
-28
lines changed

4 files changed

+141
-28
lines changed
 
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"log"
7+
"net/http"
8+
"os"
9+
10+
us_enrichment "github.com/smartystreets/smartystreets-go-sdk/us-enrichment-api"
11+
"github.com/smartystreets/smartystreets-go-sdk/wireup"
12+
)
13+
14+
func main() {
15+
log.SetFlags(log.Ltime | log.Llongfile)
16+
17+
client := wireup.BuildUSEnrichmentAPIClient(
18+
//wireup.WebsiteKeyCredential(os.Getenv("SMARTY_AUTH_WEB"), os.Getenv("SMARTY_AUTH_REFERER")),
19+
wireup.SecretKeyCredential(os.Getenv("SMARTY_AUTH_ID"), os.Getenv("SMARTY_AUTH_TOKEN")),
20+
)
21+
22+
// Perform a property principal lookup by address instead of by SmartyKey
23+
24+
// Documentation for input fields can be found at:
25+
// https://www.smarty.com/docs/cloud/us-address-enrichment-api#http-request-input-fields
26+
27+
lookup := us_enrichment.Lookup{
28+
SmartyKey: "search", // smartyKey value is "search" when doing an address search
29+
Include: "", // optional: only include these attributes in the returned data
30+
Exclude: "", // optional: exclude attributes from the returned data
31+
ETag: "", // optional: check if the record has been updated
32+
Freeform: "171 W University Pkwy, Orem, UT 84058", // optional: Query by full freeform address instead of by SmartyKey
33+
Street: "", // optional: Query by address components instead of by SmartyKey
34+
City: "", // optional: Query by address components instead of by SmartyKey
35+
State: "", // optional: Query by address components instead of by SmartyKey
36+
ZIPCode: "", // optional: Query by address components instead of by SmartyKey
37+
}
38+
39+
err, results := client.SendPropertyPrincipal(&lookup)
40+
41+
if err != nil {
42+
// If ETag was supplied in the lookup, this status will be returned if the ETag value for the record is current
43+
if client.IsHTTPErrorCode(err, http.StatusNotModified) {
44+
log.Printf("Record has not been modified since the last request")
45+
return
46+
}
47+
log.Fatal("Error sending lookup:", err)
48+
}
49+
50+
fmt.Println("Results for address search:")
51+
for s, response := range results {
52+
jsonResponse, _ := json.MarshalIndent(response, "", " ")
53+
fmt.Printf("#%d: %s\n", s, string(jsonResponse))
54+
}
55+
}

‎examples/us-enrichment-api/property-principal/main.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func main() {
2525
smartyKey := "87844267"
2626

2727
lookup := us_enrichment.Lookup{
28-
SmartyKey: smartyKey,
28+
SmartyKey: smartyKey, //smartyKey,
2929
Include: "group_structural,sale_date", // optional: only include these attributes in the returned data
3030
Exclude: "", // optional: exclude attributes from the returned data
3131
ETag: "", // optional: check if the record has been updated
@@ -47,23 +47,4 @@ func main() {
4747
jsonResponse, _ := json.MarshalIndent(response, "", " ")
4848
fmt.Printf("#%d: %s\n", s, string(jsonResponse))
4949
}
50-
51-
client = wireup.BuildUSEnrichmentAPIClient(
52-
//wireup.WebsiteKeyCredential(os.Getenv("SMARTY_AUTH_WEB"), os.Getenv("SMARTY_AUTH_REFERER")),
53-
wireup.SecretKeyCredential(os.Getenv("SMARTY_AUTH_ID"), os.Getenv("SMARTY_AUTH_TOKEN")),
54-
// The appropriate license values to be used for your subscriptions
55-
// can be found on the Subscriptions page the account dashboard.
56-
// https://www.smarty.com/docs/cloud/licensing
57-
wireup.WithLicenses("us-property-data-financial-cloud"),
58-
// wireup.DebugHTTPOutput(), // uncomment this line to see detailed HTTP request/response information.
59-
)
60-
err, financialResults := client.SendPropertyFinancialLookup(smartyKey)
61-
if err != nil {
62-
log.Fatal("Error sending lookup:", err)
63-
}
64-
fmt.Printf("Results for input: (%s, %s)\n", smartyKey, "financial")
65-
for s, response := range financialResults {
66-
jsonResponse, _ := json.MarshalIndent(response, "", " ")
67-
fmt.Printf("#%d: %s\n", s, string(jsonResponse))
68-
}
6950
}

‎us-enrichment-api/lookup.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ type Lookup struct {
1111
SmartyKey string
1212
Include string
1313
Exclude string
14+
Freeform string
15+
Street string
16+
City string
17+
State string
18+
ZIPCode string
1419
ETag string
1520
}
1621

@@ -61,6 +66,12 @@ func (g *universalLookup) unmarshalResponse(bytes []byte, headers http.Header) e
6166
func (g *universalLookup) populate(query url.Values) {
6267
g.Lookup.populateInclude(query)
6368
g.Lookup.populateExclude(query)
69+
g.Lookup.populateFreeform(query)
70+
g.Lookup.populateStreet(query)
71+
g.Lookup.populateCity(query)
72+
g.Lookup.populateState(query)
73+
g.Lookup.populateZIPCode(query)
74+
6475
}
6576

6677
////////////////////////////////////////////////////////////////////////////////////////
@@ -109,6 +120,11 @@ func (f *financialLookup) unmarshalResponse(bytes []byte, headers http.Header) e
109120
func (e *financialLookup) populate(query url.Values) {
110121
e.Lookup.populateInclude(query)
111122
e.Lookup.populateExclude(query)
123+
e.Lookup.populateFreeform(query)
124+
e.Lookup.populateStreet(query)
125+
e.Lookup.populateCity(query)
126+
e.Lookup.populateState(query)
127+
e.Lookup.populateZIPCode(query)
112128
}
113129

114130
////////////////////////////////////////////////////////////////////////////////////////
@@ -157,6 +173,11 @@ func (p *principalLookup) unmarshalResponse(bytes []byte, headers http.Header) e
157173
func (e *principalLookup) populate(query url.Values) {
158174
e.Lookup.populateInclude(query)
159175
e.Lookup.populateExclude(query)
176+
e.Lookup.populateFreeform(query)
177+
e.Lookup.populateStreet(query)
178+
e.Lookup.populateCity(query)
179+
e.Lookup.populateState(query)
180+
e.Lookup.populateZIPCode(query)
160181
}
161182

162183
////////////////////////////////////////////////////////////////////////////////////////
@@ -173,6 +194,11 @@ func (g *geoReferenceLookup) getDataSubset() string {
173194
func (g *geoReferenceLookup) populate(query url.Values) {
174195
g.Lookup.populateInclude(query)
175196
g.Lookup.populateExclude(query)
197+
g.Lookup.populateFreeform(query)
198+
g.Lookup.populateStreet(query)
199+
g.Lookup.populateCity(query)
200+
g.Lookup.populateState(query)
201+
g.Lookup.populateZIPCode(query)
176202
}
177203

178204
func (g *geoReferenceLookup) getSmartyKey() string {
@@ -253,6 +279,11 @@ func (s *secondaryLookup) unmarshalResponse(bytes []byte, header http.Header) er
253279
func (s *secondaryLookup) populate(query url.Values) {
254280
s.Lookup.populateInclude(query)
255281
s.Lookup.populateExclude(query)
282+
s.Lookup.populateFreeform(query)
283+
s.Lookup.populateStreet(query)
284+
s.Lookup.populateCity(query)
285+
s.Lookup.populateState(query)
286+
s.Lookup.populateZIPCode(query)
256287
}
257288

258289
////////////////////////////////////////////////////////////////////////////////////////
@@ -301,6 +332,11 @@ func (s *secondaryCountLookup) unmarshalResponse(bytes []byte, header http.Heade
301332
func (s *secondaryCountLookup) populate(query url.Values) {
302333
s.Lookup.populateInclude(query)
303334
s.Lookup.populateExclude(query)
335+
s.Lookup.populateFreeform(query)
336+
s.Lookup.populateStreet(query)
337+
s.Lookup.populateCity(query)
338+
s.Lookup.populateState(query)
339+
s.Lookup.populateZIPCode(query)
304340
}
305341

306342
const (
@@ -324,3 +360,33 @@ func (l Lookup) populateExclude(query url.Values) {
324360
query.Set("exclude", l.Exclude)
325361
}
326362
}
363+
364+
func (l Lookup) populateFreeform(query url.Values) {
365+
if len(l.Freeform) > 0 {
366+
query.Set("freeform", l.Freeform)
367+
}
368+
}
369+
370+
func (l Lookup) populateStreet(query url.Values) {
371+
if len(l.Street) > 0 {
372+
query.Set("street", l.Street)
373+
}
374+
}
375+
376+
func (l Lookup) populateCity(query url.Values) {
377+
if len(l.City) > 0 {
378+
query.Set("city", l.City)
379+
}
380+
}
381+
382+
func (l Lookup) populateState(query url.Values) {
383+
if len(l.State) > 0 {
384+
query.Set("state", l.State)
385+
}
386+
}
387+
388+
func (l Lookup) populateZIPCode(query url.Values) {
389+
if len(l.ZIPCode) > 0 {
390+
query.Set("zipcode", l.ZIPCode)
391+
}
392+
}

‎us-enrichment-api/response.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ type PrincipalResponse struct {
44
SmartyKey string `json:"smarty_key"`
55
DataSetName string `json:"data_set_name"`
66
DataSubsetName string `json:"data_subset_name"`
7+
MatchedAddress MatchedAddress `json:"matched_address"`
78
Attributes PrincipalAttributes `json:"attributes"`
89
Etag string
910
}
1011

12+
type MatchedAddress struct {
13+
Street string `json:"street"`
14+
City string `json:"city"`
15+
State string `json:"state"`
16+
ZIPCode string `json:"zipcode"`
17+
}
18+
1119
type PrincipalAttributes struct {
1220
FirstFloorSqft string `json:"1st_floor_sqft"`
1321
SecondFloorSqft string `json:"2nd_floor_sqft"`
@@ -375,6 +383,7 @@ type FinancialResponse struct {
375383
SmartyKey string `json:"smarty_key"`
376384
DataSetName string `json:"data_set_name"`
377385
DataSubsetName string `json:"data_subset_name"`
386+
MatchedAddress MatchedAddress `json:"matched_address"`
378387
Attributes FinancialAttributes `json:"attributes"`
379388
Etag string
380389
}
@@ -525,10 +534,11 @@ type FinancialAttributes struct {
525534
}
526535

527536
type GeoReferenceResponse struct {
528-
SmartyKey string `json:"smarty_key"`
529-
DataSetName string `json:"data_set_name"`
530-
Attributes GeoReferenceAttributes `json:"attributes"`
531-
Etag string
537+
SmartyKey string `json:"smarty_key"`
538+
DataSetName string `json:"data_set_name"`
539+
MatchedAddress MatchedAddress `json:"matched_address"`
540+
Attributes GeoReferenceAttributes `json:"attributes"`
541+
Etag string
532542
}
533543

534544
type GeoReferenceAttributes struct {
@@ -584,10 +594,11 @@ type Alias struct {
584594
}
585595

586596
type Secondary struct {
587-
SmartyKey string `json:"smarty_key"`
588-
SecondaryDesignator string `json:"secondary_designator"`
589-
SecondaryNumber string `json:"secondary_number"`
590-
Plus4Code string `json:"plus4_code"`
597+
SmartyKey string `json:"smarty_key"`
598+
MatchedAddress MatchedAddress `json:"matched_address"`
599+
SecondaryDesignator string `json:"secondary_designator"`
600+
SecondaryNumber string `json:"secondary_number"`
601+
Plus4Code string `json:"plus4_code"`
591602
}
592603

593604
type SecondaryResponse struct {

0 commit comments

Comments
 (0)
Please sign in to comment.