Skip to content

Commit

Permalink
Added address search lookup capabilities for US Enrichment API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Amundson committed Sep 6, 2024
1 parent 697bca3 commit 4ce1eb9
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 28 deletions.
55 changes: 55 additions & 0 deletions examples/us-enrichment-api/address-search/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"

us_enrichment "github.com/smartystreets/smartystreets-go-sdk/us-enrichment-api"
"github.com/smartystreets/smartystreets-go-sdk/wireup"
)

func main() {
log.SetFlags(log.Ltime | log.Llongfile)

client := wireup.BuildUSEnrichmentAPIClient(
//wireup.WebsiteKeyCredential(os.Getenv("SMARTY_AUTH_WEB"), os.Getenv("SMARTY_AUTH_REFERER")),
wireup.SecretKeyCredential(os.Getenv("SMARTY_AUTH_ID"), os.Getenv("SMARTY_AUTH_TOKEN")),
)

// Perform a property principal lookup by address instead of by SmartyKey

// Documentation for input fields can be found at:
// https://www.smarty.com/docs/cloud/us-address-enrichment-api#http-request-input-fields

lookup := us_enrichment.Lookup{
SmartyKey: "search", // smartyKey value is "search" when doing an address search
Include: "", // optional: only include these attributes in the returned data
Exclude: "", // optional: exclude attributes from the returned data
ETag: "", // optional: check if the record has been updated
Freeform: "171 W University Pkwy, Orem, UT 84058", // optional: Query by full freeform address instead of by SmartyKey
Street: "", // optional: Query by address components instead of by SmartyKey
City: "", // optional: Query by address components instead of by SmartyKey
State: "", // optional: Query by address components instead of by SmartyKey
ZIPCode: "", // optional: Query by address components instead of by SmartyKey
}

err, results := client.SendPropertyPrincipal(&lookup)

if err != nil {
// If ETag was supplied in the lookup, this status will be returned if the ETag value for the record is current
if client.IsHTTPErrorCode(err, http.StatusNotModified) {
log.Printf("Record has not been modified since the last request")
return
}
log.Fatal("Error sending lookup:", err)
}

fmt.Println("Results for address search:")
for s, response := range results {
jsonResponse, _ := json.MarshalIndent(response, "", " ")
fmt.Printf("#%d: %s\n", s, string(jsonResponse))
}
}
21 changes: 1 addition & 20 deletions examples/us-enrichment-api/property-principal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
smartyKey := "87844267"

lookup := us_enrichment.Lookup{
SmartyKey: smartyKey,
SmartyKey: smartyKey, //smartyKey,
Include: "group_structural,sale_date", // optional: only include these attributes in the returned data
Exclude: "", // optional: exclude attributes from the returned data
ETag: "", // optional: check if the record has been updated
Expand All @@ -47,23 +47,4 @@ func main() {
jsonResponse, _ := json.MarshalIndent(response, "", " ")
fmt.Printf("#%d: %s\n", s, string(jsonResponse))
}

client = wireup.BuildUSEnrichmentAPIClient(
//wireup.WebsiteKeyCredential(os.Getenv("SMARTY_AUTH_WEB"), os.Getenv("SMARTY_AUTH_REFERER")),
wireup.SecretKeyCredential(os.Getenv("SMARTY_AUTH_ID"), os.Getenv("SMARTY_AUTH_TOKEN")),
// The appropriate license values to be used for your subscriptions
// can be found on the Subscriptions page the account dashboard.
// https://www.smarty.com/docs/cloud/licensing
wireup.WithLicenses("us-property-data-financial-cloud"),
// wireup.DebugHTTPOutput(), // uncomment this line to see detailed HTTP request/response information.
)
err, financialResults := client.SendPropertyFinancialLookup(smartyKey)
if err != nil {
log.Fatal("Error sending lookup:", err)
}
fmt.Printf("Results for input: (%s, %s)\n", smartyKey, "financial")
for s, response := range financialResults {
jsonResponse, _ := json.MarshalIndent(response, "", " ")
fmt.Printf("#%d: %s\n", s, string(jsonResponse))
}
}
66 changes: 66 additions & 0 deletions us-enrichment-api/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ type Lookup struct {
SmartyKey string
Include string
Exclude string
Freeform string
Street string
City string
State string
ZIPCode string
ETag string
}

Expand Down Expand Up @@ -61,6 +66,12 @@ func (g *universalLookup) unmarshalResponse(bytes []byte, headers http.Header) e
func (g *universalLookup) populate(query url.Values) {
g.Lookup.populateInclude(query)
g.Lookup.populateExclude(query)
g.Lookup.populateFreeform(query)
g.Lookup.populateStreet(query)
g.Lookup.populateCity(query)
g.Lookup.populateState(query)
g.Lookup.populateZIPCode(query)

}

////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -109,6 +120,11 @@ func (f *financialLookup) unmarshalResponse(bytes []byte, headers http.Header) e
func (e *financialLookup) populate(query url.Values) {
e.Lookup.populateInclude(query)
e.Lookup.populateExclude(query)
e.Lookup.populateFreeform(query)
e.Lookup.populateStreet(query)
e.Lookup.populateCity(query)
e.Lookup.populateState(query)
e.Lookup.populateZIPCode(query)
}

////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -157,6 +173,11 @@ func (p *principalLookup) unmarshalResponse(bytes []byte, headers http.Header) e
func (e *principalLookup) populate(query url.Values) {
e.Lookup.populateInclude(query)
e.Lookup.populateExclude(query)
e.Lookup.populateFreeform(query)
e.Lookup.populateStreet(query)
e.Lookup.populateCity(query)
e.Lookup.populateState(query)
e.Lookup.populateZIPCode(query)
}

////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -173,6 +194,11 @@ func (g *geoReferenceLookup) getDataSubset() string {
func (g *geoReferenceLookup) populate(query url.Values) {
g.Lookup.populateInclude(query)
g.Lookup.populateExclude(query)
g.Lookup.populateFreeform(query)
g.Lookup.populateStreet(query)
g.Lookup.populateCity(query)
g.Lookup.populateState(query)
g.Lookup.populateZIPCode(query)
}

func (g *geoReferenceLookup) getSmartyKey() string {
Expand Down Expand Up @@ -253,6 +279,11 @@ func (s *secondaryLookup) unmarshalResponse(bytes []byte, header http.Header) er
func (s *secondaryLookup) populate(query url.Values) {
s.Lookup.populateInclude(query)
s.Lookup.populateExclude(query)
s.Lookup.populateFreeform(query)
s.Lookup.populateStreet(query)
s.Lookup.populateCity(query)
s.Lookup.populateState(query)
s.Lookup.populateZIPCode(query)
}

////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -301,6 +332,11 @@ func (s *secondaryCountLookup) unmarshalResponse(bytes []byte, header http.Heade
func (s *secondaryCountLookup) populate(query url.Values) {
s.Lookup.populateInclude(query)
s.Lookup.populateExclude(query)
s.Lookup.populateFreeform(query)
s.Lookup.populateStreet(query)
s.Lookup.populateCity(query)
s.Lookup.populateState(query)
s.Lookup.populateZIPCode(query)
}

const (
Expand All @@ -324,3 +360,33 @@ func (l Lookup) populateExclude(query url.Values) {
query.Set("exclude", l.Exclude)
}
}

func (l Lookup) populateFreeform(query url.Values) {
if len(l.Freeform) > 0 {
query.Set("freeform", l.Freeform)
}
}

func (l Lookup) populateStreet(query url.Values) {
if len(l.Street) > 0 {
query.Set("street", l.Street)
}
}

func (l Lookup) populateCity(query url.Values) {
if len(l.City) > 0 {
query.Set("city", l.City)
}
}

func (l Lookup) populateState(query url.Values) {
if len(l.State) > 0 {
query.Set("state", l.State)
}
}

func (l Lookup) populateZIPCode(query url.Values) {
if len(l.ZIPCode) > 0 {
query.Set("zipcode", l.ZIPCode)
}
}
27 changes: 19 additions & 8 deletions us-enrichment-api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ type PrincipalResponse struct {
SmartyKey string `json:"smarty_key"`
DataSetName string `json:"data_set_name"`
DataSubsetName string `json:"data_subset_name"`
MatchedAddress MatchedAddress `json:"matched_address"`
Attributes PrincipalAttributes `json:"attributes"`
Etag string
}

type MatchedAddress struct {
Street string `json:"street"`
City string `json:"city"`
State string `json:"state"`
ZIPCode string `json:"zipcode"`
}

type PrincipalAttributes struct {
FirstFloorSqft string `json:"1st_floor_sqft"`
SecondFloorSqft string `json:"2nd_floor_sqft"`
Expand Down Expand Up @@ -375,6 +383,7 @@ type FinancialResponse struct {
SmartyKey string `json:"smarty_key"`
DataSetName string `json:"data_set_name"`
DataSubsetName string `json:"data_subset_name"`
MatchedAddress MatchedAddress `json:"matched_address"`
Attributes FinancialAttributes `json:"attributes"`
Etag string
}
Expand Down Expand Up @@ -525,10 +534,11 @@ type FinancialAttributes struct {
}

type GeoReferenceResponse struct {
SmartyKey string `json:"smarty_key"`
DataSetName string `json:"data_set_name"`
Attributes GeoReferenceAttributes `json:"attributes"`
Etag string
SmartyKey string `json:"smarty_key"`
DataSetName string `json:"data_set_name"`
MatchedAddress MatchedAddress `json:"matched_address"`
Attributes GeoReferenceAttributes `json:"attributes"`
Etag string
}

type GeoReferenceAttributes struct {
Expand Down Expand Up @@ -584,10 +594,11 @@ type Alias struct {
}

type Secondary struct {
SmartyKey string `json:"smarty_key"`
SecondaryDesignator string `json:"secondary_designator"`
SecondaryNumber string `json:"secondary_number"`
Plus4Code string `json:"plus4_code"`
SmartyKey string `json:"smarty_key"`
MatchedAddress MatchedAddress `json:"matched_address"`
SecondaryDesignator string `json:"secondary_designator"`
SecondaryNumber string `json:"secondary_number"`
Plus4Code string `json:"plus4_code"`
}

type SecondaryResponse struct {
Expand Down

0 comments on commit 4ce1eb9

Please sign in to comment.