Skip to content

Commit

Permalink
Add support for the county source input field (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
LandonSmarty authored Dec 13, 2024
1 parent 75f6ecf commit e424a6e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions us-street-api/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Lookup struct {
MaxCandidates int `json:"candidates,omitempty"` // Default value: 1
MatchStrategy MatchStrategy `json:"match,omitempty"`
OutputFormat OutputFormat `json:"format,omitempty"`
CountySource CountySource `json:"county_source,omitempty"`

Results []*Candidate `json:"results,omitempty"`
}
Expand All @@ -47,6 +48,9 @@ func (l *Lookup) encodeQueryString(query url.Values) {
if l.OutputFormat != FormatDefault {
encode(query, string(l.OutputFormat), "format")
}
if l.CountySource != PostalCounty {
encode(query, string(l.CountySource), "county_source")
}
}
func encode(query url.Values, source string, target string) {
if source != "" {
Expand All @@ -70,3 +74,10 @@ const (
FormatDefault = OutputFormat("default")
FormatProjectUSA = OutputFormat("project-usa")
)

type CountySource string

const (
PostalCounty = CountySource("postal")
GeographicCounty = CountySource("geographic")
)
8 changes: 8 additions & 0 deletions us-street-api/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ func (this *LookupFixture) TestQueryStringEncoding_OutputFormatSerialized() {
"format": {"project-usa"},
})
}

func (this *LookupFixture) TestQueryStringEncoding_CountySourceSerialized() {
this.So(this.encode(&Lookup{
CountySource: GeographicCounty,
}), should.Resemble, url.Values{
"county_source": {"geographic"},
})
}

0 comments on commit e424a6e

Please sign in to comment.