Skip to content

Commit 4146490

Browse files
authored
Merge pull request #39 from smartystreets/jacob/enrichment-search-fix
Enabling Search for enrichment lookups
2 parents e424a6e + a3407f5 commit 4146490

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

us-enrichment-api/client.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ func (c *Client) sendLookupWithContext(ctx context.Context, lookup enrichmentLoo
7373
if lookup == nil || lookup.getLookup() == nil {
7474
return nil
7575
}
76-
if len(lookup.getSmartyKey()) == 0 {
77-
return nil
78-
}
7976

8077
request := buildRequest(lookup)
8178
request = request.WithContext(ctx)
@@ -112,20 +109,29 @@ func buildRequest(lookup enrichmentLookup) *http.Request {
112109
func buildLookupURL(lookup enrichmentLookup) string {
113110
var newLookupURL string
114111
if len(lookup.getDataSubset()) == 0 {
115-
newLookupURL = strings.Replace(lookupURLWithoutSubSet, lookupURLSmartyKey, lookup.getSmartyKey(), 1)
112+
newLookupURL = strings.Replace(lookupURLWithoutSubSet, lookupURLSmartyKey, getLookupURLSmartyKeyReplacement(lookup), 1)
116113
} else {
117-
newLookupURL = strings.Replace(lookupURLWithSubSet, lookupURLSmartyKey, lookup.getSmartyKey(), 1)
114+
newLookupURL = strings.Replace(lookupURLWithSubSet, lookupURLSmartyKey, getLookupURLSmartyKeyReplacement(lookup), 1)
118115
}
119116

120117
newLookupURL = strings.Replace(newLookupURL, lookupURLDataSet, lookup.getDataSet(), 1)
121118
return strings.TrimSuffix(strings.Replace(newLookupURL, lookupURLDataSubSet, lookup.getDataSubset(), 1), "/")
122119
}
123120

121+
func getLookupURLSmartyKeyReplacement(lookup enrichmentLookup) string {
122+
if len(lookup.getSmartyKey()) > 0 {
123+
return lookup.getSmartyKey()
124+
} else {
125+
return addressSearch
126+
}
127+
}
128+
124129
const (
125130
lookupURLSmartyKey = ":smartykey"
126131
lookupURLDataSet = ":dataset"
127132
lookupURLDataSubSet = ":datasubset"
128133
lookupURLWithSubSet = "/lookup/" + lookupURLSmartyKey + "/" + lookupURLDataSet + "/" + lookupURLDataSubSet // Remaining parts will be completed later by the sdk.BaseURLClient.
129134
lookupURLWithoutSubSet = "/lookup/" + lookupURLSmartyKey + "/" + lookupURLDataSet // Remaining parts will be completed later by the sdk.BaseURLClient.
130135
lookupETagHeader = "Etag"
136+
addressSearch = "search"
131137
)

us-enrichment-api/lookup.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ type universalLookup struct {
3636
Response []byte
3737
}
3838

39-
func (g *universalLookup) getSmartyKey() string { return g.Lookup.SmartyKey }
39+
func (g *universalLookup) getSmartyKey() string {
40+
return g.Lookup.SmartyKey
41+
}
4042
func (g *universalLookup) getDataSet() string { return g.DataSet }
4143
func (g *universalLookup) getDataSubset() string { return g.DataSubset }
4244
func (g *universalLookup) getLookup() *Lookup { return g.Lookup }

0 commit comments

Comments
 (0)