Skip to content

Commit

Permalink
Commit adding geo-reference functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerSmarty committed Feb 20, 2024
1 parent 6248853 commit cc9850c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 7 deletions.
9 changes: 5 additions & 4 deletions examples/us-enrichment-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
)

Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions us-enrichment-api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
57 changes: 54 additions & 3 deletions us-enrichment-api/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions us-enrichment-api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit cc9850c

Please sign in to comment.