diff --git a/examples/international-autocomplete-api-deprecated/main.go b/examples/international-autocomplete-api-deprecated/main.go new file mode 100644 index 0000000..1e9cf9b --- /dev/null +++ b/examples/international-autocomplete-api-deprecated/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "context" + "fmt" + international_autocomplete_deprecated "github.com/smartystreets/smartystreets-go-sdk/international-autocomplete-api-deprecated" + "github.com/smartystreets/smartystreets-go-sdk/wireup" + "log" + "os" +) + +func main() { + log.SetFlags(log.Ltime | log.Llongfile) + + client := wireup.BuildInternationalAutocompleteAPIDeprecatedClient( + 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.smartystreets.com/docs/cloud/licensing + wireup.WithLicenses("international-autocomplete-cloud"), + ) + + // Documentation for input fields can be found at: + // https://smartystreets.com/docs/cloud/us-autocomplete-api#http-request-input-fields + + lookup := &international_autocomplete_deprecated.Lookup{ + Country: "FRA", + Search: "Louis", + Locality: "Paris", + } + + if err := client.SendLookupWithContext(context.Background(), lookup); err != nil { + log.Fatal("Error sending batch:", err) + } + + fmt.Printf("Results for input: [%s]\n", lookup.Search) + for s, candidate := range lookup.Result.Candidates { + fmt.Printf("#%d: %#v\n", s, candidate) + } + + log.Println("OK") +} diff --git a/examples/international-autocomplete-api/main.go b/examples/international-autocomplete-api/main.go index aea6dd9..b55d981 100644 --- a/examples/international-autocomplete-api/main.go +++ b/examples/international-autocomplete-api/main.go @@ -34,7 +34,11 @@ func main() { log.Fatal("Error sending batch:", err) } - fmt.Printf("Results for input: [%s]\n", lookup.Search) + if len(lookup.Search) > 0 { + fmt.Printf("Results for input: [%s]\n", lookup.Search) + } else { + fmt.Printf("Results for input: [%s]\n", lookup.AddressID) + } for s, candidate := range lookup.Result.Candidates { fmt.Printf("#%d: %#v\n", s, candidate) } diff --git a/international-autocomplete-api-deprecated/candidate.go b/international-autocomplete-api-deprecated/candidate.go new file mode 100644 index 0000000..4dd0e85 --- /dev/null +++ b/international-autocomplete-api-deprecated/candidate.go @@ -0,0 +1,11 @@ +package international_autocomplete_api + +type Candidate struct { + Street string `json:"street"` + Locality string `json:"locality"` + AdministrativeArea string `json:"administrative_area"` + SuperAdministrativeArea string `json:"super_administrative_area"` + SubAdministrativeArea string `json:"sub_administrative_area"` + PostalCode string `json:"postal_code"` + CountryIso3 string `json:"country_iso3"` +} diff --git a/international-autocomplete-api-deprecated/client.go b/international-autocomplete-api-deprecated/client.go new file mode 100644 index 0000000..661dab3 --- /dev/null +++ b/international-autocomplete-api-deprecated/client.go @@ -0,0 +1,55 @@ +package international_autocomplete_api + +import ( + "context" + "encoding/json" + "net/http" + + sdk "github.com/smartystreets/smartystreets-go-sdk" +) + +type Client struct { + sender sdk.RequestSender +} + +// NewClient creates a client with the provided sender. +func NewClient(sender sdk.RequestSender) *Client { + return &Client{sender: sender} +} + +func (c *Client) SendLookup(lookup *Lookup) error { + return c.SendLookupWithContext(context.Background(), lookup) +} + +func (c *Client) SendLookupWithContext(ctx context.Context, lookup *Lookup) error { + if lookup == nil || len(lookup.Search) == 0 { + return nil + } + + request := buildRequest(lookup) + request = request.WithContext(ctx) + response, err := c.sender.Send(request) + if err != nil { + return err + } else { + return deserializeResponse(response, lookup) + } +} + +func deserializeResponse(response []byte, lookup *Lookup) error { + err := json.Unmarshal(response, &lookup.Result) + if err != nil { + return err + } + return nil +} + +func buildRequest(lookup *Lookup) *http.Request { + request, _ := http.NewRequest("GET", suggestURL, nil) // We control the method and the URL. This is safe. + query := request.URL.Query() + lookup.populate(query) + request.URL.RawQuery = query.Encode() + return request +} + +const suggestURL = "/lookup" // Remaining parts will be completed later by the sdk.BaseURLClient. diff --git a/international-autocomplete-api-deprecated/client_test.go b/international-autocomplete-api-deprecated/client_test.go new file mode 100644 index 0000000..bc5954a --- /dev/null +++ b/international-autocomplete-api-deprecated/client_test.go @@ -0,0 +1,140 @@ +package international_autocomplete_api + +import ( + "context" + "errors" + "net/http" + "testing" + + "github.com/smarty/assertions/should" + "github.com/smarty/gunit" +) + +func TestClientFixture(t *testing.T) { + gunit.Run(new(ClientFixture), t) +} + +type ClientFixture struct { + *gunit.Fixture + + sender *FakeSender + client *Client + + input *Lookup +} + +func (f *ClientFixture) Setup() { + f.sender = &FakeSender{} + f.client = NewClient(f.sender) + f.input = new(Lookup) +} + +func (f *ClientFixture) TestAddressLookupSerializedAndSentWithContext__ResponseSuggestionsIncorporatedIntoLookup() { + f.sender.response = `{ + "candidates": [ + { + "street": "1", + "locality": "2", + "administrative_area": "3", + "super_administrative_area": "4", + "sub_administrative_area": "5", + "postal_code": "6", + "country_iso3": "7" + }, + { + "street": "8", + "locality": "9", + "administrative_area": "10", + "super_administrative_area": "11", + "sub_administrative_area": "12", + "postal_code": "13", + "country_iso3": "14" + } + ] + }` + f.input.Search = "42" + + ctx := context.WithValue(context.Background(), "key", "value") + err := f.client.SendLookupWithContext(ctx, f.input) + + f.So(err, should.BeNil) + f.So(f.sender.request, should.NotBeNil) + f.So(f.sender.request.Method, should.Equal, "GET") + f.So(f.sender.request.URL.Path, should.Equal, suggestURL) + f.So(f.sender.request.URL.Query().Get("search"), should.Equal, "42") + f.So(f.sender.request.URL.String(), should.Equal, suggestURL+"?distance=5&max_results=5&search=42") + f.So(f.sender.request.Context(), should.Resemble, ctx) + + f.So(f.input.Result, should.Resemble, &Result{Candidates: []*Candidate{ + { + Street: "1", + Locality: "2", + AdministrativeArea: "3", + SuperAdministrativeArea: "4", + SubAdministrativeArea: "5", + PostalCode: "6", + CountryIso3: "7", + }, + { + Street: "8", + Locality: "9", + AdministrativeArea: "10", + SuperAdministrativeArea: "11", + SubAdministrativeArea: "12", + PostalCode: "13", + CountryIso3: "14", + }, + }}) +} +func (f *ClientFixture) TestNilLookupNOP() { + err := f.client.SendLookup(nil) + f.So(err, should.BeNil) + f.So(f.sender.request, should.BeNil) +} + +func (f *ClientFixture) TestEmptyLookup_NOP() { + err := f.client.SendLookup(new(Lookup)) + f.So(err, should.BeNil) + f.So(f.sender.request, should.BeNil) +} + +func (f *ClientFixture) TestSenderErrorPreventsDeserialization() { + f.sender.err = errors.New("GOPHERS!") + f.sender.response = `{"candidates":[ + {"text": "1"}, + {"text": "2"}, + {"text": "3"} + ]}` // would be deserialized if not for the err (above) + f.input.Search = "HI" + + err := f.client.SendLookup(f.input) + + f.So(err, should.NotBeNil) + f.So(f.input.Result, should.BeNil) +} + +func (f *ClientFixture) TestDeserializationErrorPreventsDeserialization() { + f.sender.response = `I can't haz JSON` + f.input.Search = "HI" + + err := f.client.SendLookup(f.input) + + f.So(err, should.NotBeNil) + f.So(f.input.Result, should.BeNil) +} + +////////////////////////////////////////////////////////////////// + +type FakeSender struct { + callCount int + request *http.Request + + response string + err error +} + +func (f *FakeSender) Send(request *http.Request) ([]byte, error) { + f.callCount++ + f.request = request + return []byte(f.response), f.err +} diff --git a/international-autocomplete-api-deprecated/lookup.go b/international-autocomplete-api-deprecated/lookup.go new file mode 100644 index 0000000..b714c30 --- /dev/null +++ b/international-autocomplete-api-deprecated/lookup.go @@ -0,0 +1,105 @@ +package international_autocomplete_api + +import ( + "math" + "net/url" + "strconv" +) + +const ( + maxResultsDefault = 5 + distanceDefault = 5 +) + +type Lookup struct { + Country string + Search string + MaxResults int + Distance int + Geolocation InternationalGeolocateType + AdministrativeArea string + Locality string + PostalCode string + Latitude float64 + Longitude float64 + Result *Result +} + +func (l Lookup) populate(query url.Values) { + l.populateCountry(query) + l.populateSearch(query) + l.populateMaxResults(query) + l.populateDistance(query) + l.populateGeolocation(query) + l.populateAdministrativeArea(query) + l.populateLocality(query) + l.populatePostalCode(query) + l.populateLatitude(query) + l.populateLongitude(query) +} +func (l Lookup) populateCountry(query url.Values) { + if len(l.Country) > 0 { + query.Set("country", l.Country) + } +} +func (l Lookup) populateSearch(query url.Values) { + if len(l.Search) > 0 { + query.Set("search", l.Search) + } +} +func (l Lookup) populateMaxResults(query url.Values) { + maxResults := l.MaxResults + if maxResults < 1 { + maxResults = maxResultsDefault + } + query.Set("max_results", strconv.Itoa(maxResults)) +} +func (l Lookup) populateDistance(query url.Values) { + distance := l.Distance + if distance < 1 { + distance = distanceDefault + } + query.Set("distance", strconv.Itoa(distance)) +} +func (l Lookup) populateGeolocation(query url.Values) { + if l.Geolocation != None { + query.Set("geolocation", string(l.Geolocation)) + } else { + query.Del("geolocation") + } +} +func (l Lookup) populateAdministrativeArea(query url.Values) { + if len(l.AdministrativeArea) > 0 { + query.Set("include_only_administrative_area", l.AdministrativeArea) + } +} +func (l Lookup) populateLocality(query url.Values) { + if len(l.Locality) > 0 { + query.Set("include_only_locality", l.Locality) + } +} +func (l Lookup) populatePostalCode(query url.Values) { + if len(l.PostalCode) > 0 { + query.Set("include_only_postal_code", l.PostalCode) + } +} +func (l Lookup) populateLatitude(query url.Values) { + if math.Floor(l.Latitude) != 0 { + query.Set("latitude", strconv.FormatFloat(l.Latitude, 'f', 8, 64)) + } +} +func (l Lookup) populateLongitude(query url.Values) { + if math.Floor(l.Longitude) != 0 { + query.Set("longitude", strconv.FormatFloat(l.Longitude, 'f', 8, 64)) + } +} + +type InternationalGeolocateType string + +const ( + AdminArea = InternationalGeolocateType("adminarea") + Locality = InternationalGeolocateType("locality") + PostalCode = InternationalGeolocateType("postalcode") + Geocodes = InternationalGeolocateType("geocodes") + None = InternationalGeolocateType("") +) diff --git a/international-autocomplete-api-deprecated/lookup_test.go b/international-autocomplete-api-deprecated/lookup_test.go new file mode 100644 index 0000000..8295a4d --- /dev/null +++ b/international-autocomplete-api-deprecated/lookup_test.go @@ -0,0 +1,110 @@ +package international_autocomplete_api + +import ( + "net/url" + "testing" + + "github.com/smarty/assertions/should" + "github.com/smarty/gunit" +) + +func TestLookupFixture(t *testing.T) { + gunit.Run(new(LookupFixture), t) +} + +type LookupFixture struct { + *gunit.Fixture + + lookup *Lookup + query url.Values +} + +func (f *LookupFixture) Setup() { + f.lookup = new(Lookup) + f.query = make(url.Values) +} +func (f *LookupFixture) populate() { + f.lookup.populate(f.query) +} + +func (f *LookupFixture) TestDefaults() { + f.populate() + + f.So(f.query, should.HaveLength, 2) + f.So(f.query.Get("max_results"), should.Equal, "5") + f.So(f.query.Get("distance"), should.Equal, "5") +} +func (f *LookupFixture) TestCountry() { + f.lookup.Country = "Hello, World!" + + f.populate() + + f.So(f.query, should.HaveLength, 3) + f.So(f.query.Get("country"), should.Equal, "Hello, World!") +} +func (f *LookupFixture) TestSearch() { + f.lookup.Search = "Hello, World!" + + f.populate() + + f.So(f.query, should.HaveLength, 3) + f.So(f.query.Get("search"), should.Equal, "Hello, World!") +} +func (f *LookupFixture) TestMaxResults() { + f.lookup.MaxResults = 7 + f.populate() + + f.So(f.query.Get("max_results"), should.Equal, "7") +} +func (f *LookupFixture) TestDistance() { + f.lookup.Distance = 3 + f.populate() + + f.So(f.query.Get("distance"), should.Equal, "3") +} +func (f *LookupFixture) TestGeolocation() { + typeList := []InternationalGeolocateType{AdminArea, Locality, PostalCode, Geocodes, None} + for _, geoLocateType := range typeList { + f.lookup.Geolocation = geoLocateType + f.populate() + f.So(f.query.Get("geolocation"), should.Equal, string(geoLocateType)) + } +} +func (f *LookupFixture) TestAdministrativeArea() { + f.lookup.AdministrativeArea = "Hello, World!" + + f.populate() + + f.So(f.query, should.HaveLength, 3) + f.So(f.query.Get("include_only_administrative_area"), should.Equal, "Hello, World!") +} +func (f *LookupFixture) TestLocality() { + f.lookup.Locality = "Hello, World!" + + f.populate() + + f.So(f.query, should.HaveLength, 3) + f.So(f.query.Get("include_only_locality"), should.Equal, "Hello, World!") +} +func (f *LookupFixture) TestPostalCode() { + f.lookup.PostalCode = "Hello, World!" + + f.populate() + + f.So(f.query, should.HaveLength, 3) + f.So(f.query.Get("include_only_postal_code"), should.Equal, "Hello, World!") +} +func (f *LookupFixture) TestLatitude() { + f.lookup.Latitude = 123.458757987986 + + f.populate() + + f.So(f.query.Get("latitude"), should.Equal, "123.45875799") // Here we only care about 8 digits of accuracy +} +func (f *LookupFixture) TestLongitude() { + f.lookup.Longitude = -134.877532234 + + f.populate() + + f.So(f.query.Get("longitude"), should.Equal, "-134.87753223") // Here we only care about 8 digits of accuracy +} diff --git a/international-autocomplete-api-deprecated/result.go b/international-autocomplete-api-deprecated/result.go new file mode 100644 index 0000000..34b6c4d --- /dev/null +++ b/international-autocomplete-api-deprecated/result.go @@ -0,0 +1,5 @@ +package international_autocomplete_api + +type Result struct { + Candidates []*Candidate `json:"candidates"` +} diff --git a/international-autocomplete-api/candidate.go b/international-autocomplete-api/candidate.go index 4dd0e85..6bd36a5 100644 --- a/international-autocomplete-api/candidate.go +++ b/international-autocomplete-api/candidate.go @@ -1,11 +1,13 @@ package international_autocomplete_api type Candidate struct { - Street string `json:"street"` - Locality string `json:"locality"` - AdministrativeArea string `json:"administrative_area"` - SuperAdministrativeArea string `json:"super_administrative_area"` - SubAdministrativeArea string `json:"sub_administrative_area"` - PostalCode string `json:"postal_code"` - CountryIso3 string `json:"country_iso3"` + Street string `json:"street"` + Locality string `json:"locality"` + AdministrativeArea string `json:"administrative_area"` + PostalCode string `json:"postal_code"` + CountryIso3 string `json:"country_iso3"` + + Entries int `json:"entries"` + AddressText string `json:"address_text"` + AddressID string `json:"address_id"` } diff --git a/international-autocomplete-api/client.go b/international-autocomplete-api/client.go index 661dab3..6e2d812 100644 --- a/international-autocomplete-api/client.go +++ b/international-autocomplete-api/client.go @@ -22,7 +22,7 @@ func (c *Client) SendLookup(lookup *Lookup) error { } func (c *Client) SendLookupWithContext(ctx context.Context, lookup *Lookup) error { - if lookup == nil || len(lookup.Search) == 0 { + if lookup == nil || len(lookup.Country) == 0 || (len(lookup.Search) == 0 && len(lookup.AddressID) == 0) { return nil } @@ -45,11 +45,16 @@ func deserializeResponse(response []byte, lookup *Lookup) error { } func buildRequest(lookup *Lookup) *http.Request { - request, _ := http.NewRequest("GET", suggestURL, nil) // We control the method and the URL. This is safe. + var addressID = "" + if len(lookup.AddressID) > 0 { + addressID = "/" + lookup.AddressID + } + request, _ := http.NewRequest("GET", suggestURL+addressID, nil) // We control the method and the URL. This is safe. query := request.URL.Query() lookup.populate(query) request.URL.RawQuery = query.Encode() return request } +// TODO support /lookup and /v2/lookup const suggestURL = "/lookup" // Remaining parts will be completed later by the sdk.BaseURLClient. diff --git a/international-autocomplete-api/client_test.go b/international-autocomplete-api/client_test.go index bc5954a..488a5e5 100644 --- a/international-autocomplete-api/client_test.go +++ b/international-autocomplete-api/client_test.go @@ -36,23 +36,20 @@ func (f *ClientFixture) TestAddressLookupSerializedAndSentWithContext__ResponseS "street": "1", "locality": "2", "administrative_area": "3", - "super_administrative_area": "4", - "sub_administrative_area": "5", - "postal_code": "6", - "country_iso3": "7" + "postal_code": "4", + "country_iso3": "5" }, { - "street": "8", - "locality": "9", - "administrative_area": "10", - "super_administrative_area": "11", - "sub_administrative_area": "12", - "postal_code": "13", - "country_iso3": "14" + "street": "6", + "locality": "7", + "administrative_area": "8", + "postal_code": "9", + "country_iso3": "10" } ] }` f.input.Search = "42" + f.input.Country = "FRA" ctx := context.WithValue(context.Background(), "key", "value") err := f.client.SendLookupWithContext(ctx, f.input) @@ -62,27 +59,23 @@ func (f *ClientFixture) TestAddressLookupSerializedAndSentWithContext__ResponseS f.So(f.sender.request.Method, should.Equal, "GET") f.So(f.sender.request.URL.Path, should.Equal, suggestURL) f.So(f.sender.request.URL.Query().Get("search"), should.Equal, "42") - f.So(f.sender.request.URL.String(), should.Equal, suggestURL+"?distance=5&max_results=5&search=42") + f.So(f.sender.request.URL.String(), should.Equal, suggestURL+"?country=FRA&max_results=5&search=42") f.So(f.sender.request.Context(), should.Resemble, ctx) f.So(f.input.Result, should.Resemble, &Result{Candidates: []*Candidate{ { - Street: "1", - Locality: "2", - AdministrativeArea: "3", - SuperAdministrativeArea: "4", - SubAdministrativeArea: "5", - PostalCode: "6", - CountryIso3: "7", + Street: "1", + Locality: "2", + AdministrativeArea: "3", + PostalCode: "4", + CountryIso3: "5", }, { - Street: "8", - Locality: "9", - AdministrativeArea: "10", - SuperAdministrativeArea: "11", - SubAdministrativeArea: "12", - PostalCode: "13", - CountryIso3: "14", + Street: "6", + Locality: "7", + AdministrativeArea: "8", + PostalCode: "9", + CountryIso3: "10", }, }}) } @@ -106,6 +99,7 @@ func (f *ClientFixture) TestSenderErrorPreventsDeserialization() { {"text": "3"} ]}` // would be deserialized if not for the err (above) f.input.Search = "HI" + f.input.Country = "FRA" err := f.client.SendLookup(f.input) @@ -116,6 +110,7 @@ func (f *ClientFixture) TestSenderErrorPreventsDeserialization() { func (f *ClientFixture) TestDeserializationErrorPreventsDeserialization() { f.sender.response = `I can't haz JSON` f.input.Search = "HI" + f.input.Country = "FRA" err := f.client.SendLookup(f.input) @@ -123,6 +118,20 @@ func (f *ClientFixture) TestDeserializationErrorPreventsDeserialization() { f.So(f.input.Result, should.BeNil) } +func (f *ClientFixture) TestAddressIDAppendsToURL() { + f.input.Country = "FRA" + f.input.AddressID = "thisisid" + + err := f.client.SendLookup(f.input) + + f.So(err, should.NotBeNil) + + f.So(f.sender.request, should.NotBeNil) + f.So(f.sender.request.Method, should.Equal, "GET") + f.So(f.sender.request.URL.Path, should.Equal, suggestURL+"/thisisid") + f.So(f.sender.request.URL.String(), should.Equal, suggestURL+"/thisisid?country=FRA&max_results=5") +} + ////////////////////////////////////////////////////////////////// type FakeSender struct { diff --git a/international-autocomplete-api/lookup.go b/international-autocomplete-api/lookup.go index b714c30..486d8f0 100644 --- a/international-autocomplete-api/lookup.go +++ b/international-autocomplete-api/lookup.go @@ -1,7 +1,6 @@ package international_autocomplete_api import ( - "math" "net/url" "strconv" ) @@ -12,30 +11,21 @@ const ( ) type Lookup struct { - Country string - Search string - MaxResults int - Distance int - Geolocation InternationalGeolocateType - AdministrativeArea string - Locality string - PostalCode string - Latitude float64 - Longitude float64 - Result *Result + Country string + Search string + AddressID string + MaxResults int + Locality string + PostalCode string + Result *Result } func (l Lookup) populate(query url.Values) { l.populateCountry(query) l.populateSearch(query) l.populateMaxResults(query) - l.populateDistance(query) - l.populateGeolocation(query) - l.populateAdministrativeArea(query) l.populateLocality(query) l.populatePostalCode(query) - l.populateLatitude(query) - l.populateLongitude(query) } func (l Lookup) populateCountry(query url.Values) { if len(l.Country) > 0 { @@ -54,25 +44,6 @@ func (l Lookup) populateMaxResults(query url.Values) { } query.Set("max_results", strconv.Itoa(maxResults)) } -func (l Lookup) populateDistance(query url.Values) { - distance := l.Distance - if distance < 1 { - distance = distanceDefault - } - query.Set("distance", strconv.Itoa(distance)) -} -func (l Lookup) populateGeolocation(query url.Values) { - if l.Geolocation != None { - query.Set("geolocation", string(l.Geolocation)) - } else { - query.Del("geolocation") - } -} -func (l Lookup) populateAdministrativeArea(query url.Values) { - if len(l.AdministrativeArea) > 0 { - query.Set("include_only_administrative_area", l.AdministrativeArea) - } -} func (l Lookup) populateLocality(query url.Values) { if len(l.Locality) > 0 { query.Set("include_only_locality", l.Locality) @@ -83,23 +54,3 @@ func (l Lookup) populatePostalCode(query url.Values) { query.Set("include_only_postal_code", l.PostalCode) } } -func (l Lookup) populateLatitude(query url.Values) { - if math.Floor(l.Latitude) != 0 { - query.Set("latitude", strconv.FormatFloat(l.Latitude, 'f', 8, 64)) - } -} -func (l Lookup) populateLongitude(query url.Values) { - if math.Floor(l.Longitude) != 0 { - query.Set("longitude", strconv.FormatFloat(l.Longitude, 'f', 8, 64)) - } -} - -type InternationalGeolocateType string - -const ( - AdminArea = InternationalGeolocateType("adminarea") - Locality = InternationalGeolocateType("locality") - PostalCode = InternationalGeolocateType("postalcode") - Geocodes = InternationalGeolocateType("geocodes") - None = InternationalGeolocateType("") -) diff --git a/international-autocomplete-api/lookup_test.go b/international-autocomplete-api/lookup_test.go index 8295a4d..a11cbfb 100644 --- a/international-autocomplete-api/lookup_test.go +++ b/international-autocomplete-api/lookup_test.go @@ -30,16 +30,15 @@ func (f *LookupFixture) populate() { func (f *LookupFixture) TestDefaults() { f.populate() - f.So(f.query, should.HaveLength, 2) + f.So(f.query, should.HaveLength, 1) f.So(f.query.Get("max_results"), should.Equal, "5") - f.So(f.query.Get("distance"), should.Equal, "5") } func (f *LookupFixture) TestCountry() { f.lookup.Country = "Hello, World!" f.populate() - f.So(f.query, should.HaveLength, 3) + f.So(f.query, should.HaveLength, 2) f.So(f.query.Get("country"), should.Equal, "Hello, World!") } func (f *LookupFixture) TestSearch() { @@ -47,7 +46,7 @@ func (f *LookupFixture) TestSearch() { f.populate() - f.So(f.query, should.HaveLength, 3) + f.So(f.query, should.HaveLength, 2) f.So(f.query.Get("search"), should.Equal, "Hello, World!") } func (f *LookupFixture) TestMaxResults() { @@ -56,34 +55,12 @@ func (f *LookupFixture) TestMaxResults() { f.So(f.query.Get("max_results"), should.Equal, "7") } -func (f *LookupFixture) TestDistance() { - f.lookup.Distance = 3 - f.populate() - - f.So(f.query.Get("distance"), should.Equal, "3") -} -func (f *LookupFixture) TestGeolocation() { - typeList := []InternationalGeolocateType{AdminArea, Locality, PostalCode, Geocodes, None} - for _, geoLocateType := range typeList { - f.lookup.Geolocation = geoLocateType - f.populate() - f.So(f.query.Get("geolocation"), should.Equal, string(geoLocateType)) - } -} -func (f *LookupFixture) TestAdministrativeArea() { - f.lookup.AdministrativeArea = "Hello, World!" - - f.populate() - - f.So(f.query, should.HaveLength, 3) - f.So(f.query.Get("include_only_administrative_area"), should.Equal, "Hello, World!") -} func (f *LookupFixture) TestLocality() { f.lookup.Locality = "Hello, World!" f.populate() - f.So(f.query, should.HaveLength, 3) + f.So(f.query, should.HaveLength, 2) f.So(f.query.Get("include_only_locality"), should.Equal, "Hello, World!") } func (f *LookupFixture) TestPostalCode() { @@ -91,20 +68,6 @@ func (f *LookupFixture) TestPostalCode() { f.populate() - f.So(f.query, should.HaveLength, 3) + f.So(f.query, should.HaveLength, 2) f.So(f.query.Get("include_only_postal_code"), should.Equal, "Hello, World!") } -func (f *LookupFixture) TestLatitude() { - f.lookup.Latitude = 123.458757987986 - - f.populate() - - f.So(f.query.Get("latitude"), should.Equal, "123.45875799") // Here we only care about 8 digits of accuracy -} -func (f *LookupFixture) TestLongitude() { - f.lookup.Longitude = -134.877532234 - - f.populate() - - f.So(f.query.Get("longitude"), should.Equal, "-134.87753223") // Here we only care about 8 digits of accuracy -} diff --git a/wireup/builder.go b/wireup/builder.go index a01be03..11584cb 100644 --- a/wireup/builder.go +++ b/wireup/builder.go @@ -12,6 +12,7 @@ import ( "github.com/smartystreets/smartystreets-go-sdk" internal "github.com/smartystreets/smartystreets-go-sdk/internal/sdk" international_autocomplete "github.com/smartystreets/smartystreets-go-sdk/international-autocomplete-api" + international_autocomplete_deprecated "github.com/smartystreets/smartystreets-go-sdk/international-autocomplete-api-deprecated" international_street "github.com/smartystreets/smartystreets-go-sdk/international-street-api" "github.com/smartystreets/smartystreets-go-sdk/us-autocomplete-api" autocomplete_pro "github.com/smartystreets/smartystreets-go-sdk/us-autocomplete-pro-api" @@ -163,6 +164,11 @@ func (b *clientBuilder) buildInternationalAutocompleteAPIClient() *international return international_autocomplete.NewClient(b.buildHTTPSender()) } +func (b *clientBuilder) buildInternationalAutocompleteAPIDeprecatedClient() *international_autocomplete_deprecated.Client { + b.ensureBaseURLNotNil(defaultBaseURL_InternationalAutocompleteAPIDeprecated) + return international_autocomplete_deprecated.NewClient(b.buildHTTPSender()) +} + func (b *clientBuilder) buildUSReverseGeocodingAPIClient() *us_reverse_geo.Client { b.ensureBaseURLNotNil(defaultBaseURL_USReverseGeocodingAPI) return us_reverse_geo.NewClient(b.buildHTTPSender()) @@ -222,12 +228,13 @@ func (b *clientBuilder) buildTransport() *http.Transport { } var ( - defaultBaseURL_InternationalStreetAPI = &url.URL{Scheme: "https", Host: "international-street.api.smarty.com"} - defaultBaseURL_InternationalAutocompleteAPI = &url.URL{Scheme: "https", Host: "international-autocomplete.api.smarty.com"} - defaultBaseURL_USStreetAPI = &url.URL{Scheme: "https", Host: "us-street.api.smarty.com"} - defaultBaseURL_USZIPCodeAPI = &url.URL{Scheme: "https", Host: "us-zipcode.api.smarty.com"} - defaultBaseURL_USAutocompleteAPI = &url.URL{Scheme: "https", Host: "us-autocomplete.api.smarty.com"} - defaultBaseURL_USExtractAPI = &url.URL{Scheme: "https", Host: "us-extract.api.smarty.com"} - defaultBaseURL_USReverseGeocodingAPI = &url.URL{Scheme: "https", Host: "us-reverse-geo.api.smarty.com"} - defaultBaseURL_USAutocompleteProAPI = &url.URL{Scheme: "https", Host: "us-autocomplete-pro.api.smarty.com"} + defaultBaseURL_InternationalStreetAPI = &url.URL{Scheme: "https", Host: "international-street.api.smarty.com"} + defaultBaseURL_InternationalAutocompleteAPI = &url.URL{Scheme: "https", Host: "international-autocomplete.api.smarty.com/v2"} + defaultBaseURL_InternationalAutocompleteAPIDeprecated = &url.URL{Scheme: "https", Host: "international-autocomplete.api.smarty.com"} + defaultBaseURL_USStreetAPI = &url.URL{Scheme: "https", Host: "us-street.api.smarty.com"} + defaultBaseURL_USZIPCodeAPI = &url.URL{Scheme: "https", Host: "us-zipcode.api.smarty.com"} + defaultBaseURL_USAutocompleteAPI = &url.URL{Scheme: "https", Host: "us-autocomplete.api.smarty.com"} + defaultBaseURL_USExtractAPI = &url.URL{Scheme: "https", Host: "us-extract.api.smarty.com"} + defaultBaseURL_USReverseGeocodingAPI = &url.URL{Scheme: "https", Host: "us-reverse-geo.api.smarty.com"} + defaultBaseURL_USAutocompleteProAPI = &url.URL{Scheme: "https", Host: "us-autocomplete-pro.api.smarty.com"} ) diff --git a/wireup/options.go b/wireup/options.go index ac00ca7..4ed9f5a 100644 --- a/wireup/options.go +++ b/wireup/options.go @@ -5,6 +5,7 @@ import ( "time" international_autocomplete "github.com/smartystreets/smartystreets-go-sdk/international-autocomplete-api" + international_autocomplete_deprecated "github.com/smartystreets/smartystreets-go-sdk/international-autocomplete-api-deprecated" international_street "github.com/smartystreets/smartystreets-go-sdk/international-street-api" "github.com/smartystreets/smartystreets-go-sdk/us-autocomplete-api" autocomplete_pro "github.com/smartystreets/smartystreets-go-sdk/us-autocomplete-pro-api" @@ -49,6 +50,11 @@ func BuildInternationalAutocompleteAPIClient(options ...Option) *international_a return configure(options...).buildInternationalAutocompleteAPIClient() } +// BuildInternationalAutocompleteAPIDeprecatedClient builds a client for the International Autocomplete API (Deprecated) using the provided options. +func BuildInternationalAutocompleteAPIDeprecatedClient(options ...Option) *international_autocomplete_deprecated.Client { + return configure(options...).buildInternationalAutocompleteAPIDeprecatedClient() +} + // BuildUSReverseGeocodingAPIClient builds a client for the US Reverse Geocoding API using the provided options. func BuildUSReverseGeocodingAPIClient(options ...Option) *us_reverse_geo.Client { return configure(options...).buildUSReverseGeocodingAPIClient()