From cc9850c0a5d452ede6c87db76f8364af798ef852 Mon Sep 17 00:00:00 2001 From: Spencer Jorgensen Date: Tue, 20 Feb 2024 14:08:17 -0700 Subject: [PATCH] Commit adding geo-reference functionality --- examples/us-enrichment-api/main.go | 9 ++--- us-enrichment-api/client.go | 6 ++++ us-enrichment-api/lookup.go | 57 ++++++++++++++++++++++++++++-- us-enrichment-api/response.go | 31 ++++++++++++++++ 4 files changed, 96 insertions(+), 7 deletions(-) diff --git a/examples/us-enrichment-api/main.go b/examples/us-enrichment-api/main.go index 24f5990..d5ee11e 100644 --- a/examples/us-enrichment-api/main.go +++ b/examples/us-enrichment-api/main.go @@ -20,6 +20,7 @@ func main() { // can be found on the Subscriptions page the account dashboard. // https://www.smarty.com/docs/cloud/licensing wireup.WithLicenses("us-property-data-principal-cloud"), + wireup.CustomBaseURL("https://us-enrichment.api.rivendell.smartyops.net"), // wireup.DebugHTTPOutput(), // uncomment this line to see detailed HTTP request/response information. ) @@ -30,12 +31,12 @@ func main() { lookup := us_enrichment.Lookup{ 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 + 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 } - err, results := client.SendPropertyPrincipal(&lookup) + err, results := client.SendPropertyGeoReference(&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 diff --git a/us-enrichment-api/client.go b/us-enrichment-api/client.go index 67dadc3..e416ac1 100644 --- a/us-enrichment-api/client.go +++ b/us-enrichment-api/client.go @@ -36,6 +36,12 @@ func (c *Client) SendPropertyPrincipal(lookup *Lookup) (error, []*PrincipalRespo return err, propertyLookup.Response } +func (c *Client) SendPropertyGeoReference(lookup *Lookup) (error, []*GeoReferenceResponse) { + geoReferenceLookup := &geoReferenceLookup{Lookup: lookup} + err := c.sendLookup(geoReferenceLookup) + return err, geoReferenceLookup.Response +} + func (c *Client) sendLookup(lookup enrichmentLookup) error { return c.sendLookupWithContext(context.Background(), lookup) } diff --git a/us-enrichment-api/lookup.go b/us-enrichment-api/lookup.go index a7fdd71..383455c 100644 --- a/us-enrichment-api/lookup.go +++ b/us-enrichment-api/lookup.go @@ -119,12 +119,63 @@ func (e *principalLookup) populate(query url.Values) { e.Lookup.populateExclude(query) } +//////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////// + +type geoReferenceLookup struct { + Lookup *Lookup + Response []*GeoReferenceResponse +} + +func (g *geoReferenceLookup) getDataSubset() string { + return geoReferenceDataSubset +} + +func (g *geoReferenceLookup) populate(query url.Values) { + g.Lookup.populateInclude(query) + g.Lookup.populateExclude(query) +} + +func (g *geoReferenceLookup) getSmartyKey() string { + return g.Lookup.SmartyKey +} + +func (g *geoReferenceLookup) getDataSet() string { + return geoReferenceDataSet +} + +func (g *geoReferenceLookup) getLookup() *Lookup { + return g.Lookup +} + +func (g *geoReferenceLookup) getResponse() interface{} { + return g.Response +} + +func (g *geoReferenceLookup) unmarshalResponse(bytes []byte, headers http.Header) error { + if err := json.Unmarshal(bytes, &g.Response); err != nil { + return err + } + + if headers != nil { + if etag, found := headers[lookupETagHeader]; found { + if len(etag) > 0 && len(g.Response) > 0 { + g.Response[0].Etag = etag[0] + } + } + } + + return nil +} + //////////////////////////////////////////////////////////////////////////////////////// const ( - financialDataSubset = "financial" - principalDataSubset = "principal" - propertyDataSet = "property" + financialDataSubset = "financial" + principalDataSubset = "principal" + propertyDataSet = "property" + geoReferenceDataSet = "geo-reference" + geoReferenceDataSubset = "" ) func (l Lookup) populateInclude(query url.Values) { diff --git a/us-enrichment-api/response.go b/us-enrichment-api/response.go index e8c821b..5718a6e 100644 --- a/us-enrichment-api/response.go +++ b/us-enrichment-api/response.go @@ -502,3 +502,34 @@ type FinancialAttributes struct { VeteranTaxExemption string `json:"veteran_tax_exemption"` WidowTaxExemption string `json:"widow_tax_exemption"` } +type GeoReferenceResponse struct { + SmartyKey string `json:"smarty_key"` + DataSetName string `json:"data_set_name"` + Attributes GeoReferenceAttributes `json:"attributes"` + Etag string +} + +type GeoReferenceAttributes struct { + CensusBlock struct { + Accuracy string `json:"accuracy"` + Id string `json:"id"` + } `json:"census_block"` + + CensusCountyDivision struct { + Accuracy string `json:"accuracy"` + Id string `json:"id"` + Name string `json:"name"` + } `json:"census_county_division"` + + CoreBasedStatArea struct { + Id string `json:"id"` + Name string `json:"name"` + } `json:"core_based_stat_area"` + + Place struct { + Accuracy string `json:"accuracy"` + Id string `json:"id"` + Name string `json:"name"` + Type string `json:"type"` + } `json:"place"` +}