diff --git a/internal/sdk/doc_test.go b/internal/sdk/doc_test.go index 152fcb1..34678b3 100644 --- a/internal/sdk/doc_test.go +++ b/internal/sdk/doc_test.go @@ -1,7 +1,7 @@ package sdk import ( - "io/ioutil" + "io" "net/http" ) @@ -35,7 +35,7 @@ func (f *FakeMultiHTTPClient) Do(request *http.Request) (*http.Response, error) func (f *FakeMultiHTTPClient) simulateServerReadingRequestBody(request *http.Request) { if request.Body != nil { - body, _ := ioutil.ReadAll(request.Body) + body, _ := io.ReadAll(request.Body) f.bodies = append(f.bodies, string(body)) } else { f.bodies = append(f.bodies, request.URL.Query().Get("body")) diff --git a/internal/sdk/http_sender.go b/internal/sdk/http_sender.go index bfe18e6..440bf84 100644 --- a/internal/sdk/http_sender.go +++ b/internal/sdk/http_sender.go @@ -1,7 +1,7 @@ package sdk import ( - "io/ioutil" + "io" "net/http" "github.com/smartystreets/smartystreets-go-sdk" @@ -38,7 +38,7 @@ func readResponseBody(response *http.Response) ([]byte, error) { // TODO: Since we already copy response.Body in retry_client.go -> readBody() // It would behoove us to prevent a second copy in that case. - if content, err := ioutil.ReadAll(response.Body); err != nil { + if content, err := io.ReadAll(response.Body); err != nil { _ = response.Body.Close() return nil, err } else { diff --git a/internal/sdk/keep_alive_close_client_test.go b/internal/sdk/keep_alive_close_client_test.go index f61bd4b..bebf84d 100644 --- a/internal/sdk/keep_alive_close_client_test.go +++ b/internal/sdk/keep_alive_close_client_test.go @@ -1,7 +1,7 @@ package sdk import ( - "io/ioutil" + "io" "net/http" "net/http/httptest" "strings" @@ -26,7 +26,7 @@ func (f *KeepAliveCloseClientFixture) Setup() { f.inner.response = &http.Response{ ProtoMajor: 1, ProtoMinor: 1, StatusCode: http.StatusTeapot, - Body: ioutil.NopCloser(strings.NewReader("Goodbye, World!")), + Body: io.NopCloser(strings.NewReader("Goodbye, World!")), } f.request = httptest.NewRequest("GET", "/", nil) } diff --git a/internal/sdk/retry_client.go b/internal/sdk/retry_client.go index 82d4adb..55508ce 100644 --- a/internal/sdk/retry_client.go +++ b/internal/sdk/retry_client.go @@ -3,7 +3,6 @@ package sdk import ( "bytes" "io" - "io/ioutil" "math/rand" "net/http" "sync" @@ -54,13 +53,13 @@ func (r *RetryClient) doGet(request *http.Request) (response *http.Response, err } func (r *RetryClient) doBufferedPost(request *http.Request) (response *http.Response, err error) { - body, err := ioutil.ReadAll(request.Body) + body, err := io.ReadAll(request.Body) if err != nil { return nil, err } for attempt := 0; r.backOff(attempt); attempt++ { - request.Body = ioutil.NopCloser(bytes.NewReader(body)) + request.Body = io.NopCloser(bytes.NewReader(body)) if response, err = r.inner.Do(request); err == nil && response.StatusCode == http.StatusOK { if r.readBody(response) { break @@ -82,6 +81,7 @@ func (r *RetryClient) handleHttpStatusCode(response *http.Response, attempt *int } if response.StatusCode == http.StatusTooManyRequests { r.sleeper(time.Second * time.Duration(r.random(backOffRateLimit))) + // Setting attempt to 1 will make 429s retry indefinitely; this is intended behavior. *attempt = 1 } return true diff --git a/us-autocomplete-pro-api/lookup.go b/us-autocomplete-pro-api/lookup.go index 227531d..b43d0ae 100644 --- a/us-autocomplete-pro-api/lookup.go +++ b/us-autocomplete-pro-api/lookup.go @@ -22,6 +22,7 @@ type ( PreferZIP []string PreferRatio int Geolocation Geolocation + Selected string Results []*Suggestion } @@ -46,6 +47,7 @@ func (l Lookup) populate(query url.Values) { l.populatePreferRatio(query) l.populateGeolocation(query) l.populateSource(query) + l.populateSelected(query) } func (l Lookup) populateSearch(query url.Values) { @@ -116,3 +118,8 @@ func (l Lookup) populateSource(query url.Values) { query.Set("source", l.Source) } } +func (l Lookup) populateSelected(query url.Values) { + if len(l.Selected) > 0 { + query.Set("selected", l.Selected) + } +} diff --git a/us-autocomplete-pro-api/lookup_test.go b/us-autocomplete-pro-api/lookup_test.go index 70b68e8..e1273d4 100644 --- a/us-autocomplete-pro-api/lookup_test.go +++ b/us-autocomplete-pro-api/lookup_test.go @@ -147,3 +147,12 @@ func (f *LookupSerializationFixture) TestGeolocateCity_DefaultValue() { f.So(f.query, should.HaveLength, 1) f.So(f.query.Get("prefer_geolocation"), should.Equal, "city") } + +func (f *LookupSerializationFixture) TestSelect() { + f.lookup.Selected = "Hello World!" + + f.populate() + + f.So(f.query, should.HaveLength, 1) + f.So(f.query.Get("selected"), should.Equal, "Hello World!") +} diff --git a/us-extract-api/lookup.go b/us-extract-api/lookup.go index bb9bd68..4ecb29e 100644 --- a/us-extract-api/lookup.go +++ b/us-extract-api/lookup.go @@ -1,11 +1,12 @@ package extract import ( - "github.com/smartystreets/smartystreets-go-sdk/us-street-api" - "io/ioutil" + "io" "net/http" "strconv" "strings" + + "github.com/smartystreets/smartystreets-go-sdk/us-street-api" ) // Lookup represents all input fields documented here: @@ -64,7 +65,7 @@ func (l *Lookup) setBody(request *http.Request) { } body := strings.NewReader(l.Text) - request.Body = ioutil.NopCloser(body) + request.Body = io.NopCloser(body) request.ContentLength = int64(body.Len()) } func (l *Lookup) setHeaders(request *http.Request) { diff --git a/us-extract-api/lookup_test.go b/us-extract-api/lookup_test.go index 7e15954..3facef5 100644 --- a/us-extract-api/lookup_test.go +++ b/us-extract-api/lookup_test.go @@ -1,7 +1,7 @@ package extract import ( - "io/ioutil" + "io" "net/http" "net/url" "testing" @@ -33,7 +33,7 @@ func (f *LookupFixture) query() url.Values { } func readBody(request *http.Request) string { - bytes, _ := ioutil.ReadAll(request.Body) + bytes, _ := io.ReadAll(request.Body) return string(bytes) } diff --git a/us-street-api/batch.go b/us-street-api/batch.go index 8b0ea30..6498bbc 100644 --- a/us-street-api/batch.go +++ b/us-street-api/batch.go @@ -3,7 +3,7 @@ package street import ( "bytes" "encoding/json" - "io/ioutil" + "io" "net/http" ) @@ -79,7 +79,7 @@ func (b *Batch) serializeGET(request *http.Request) { func (b *Batch) serializePOST(request *http.Request) { request.Method = http.MethodPost payload, _ := json.Marshal(b.lookups) // We control the types being serialized. This is safe. - request.Body = ioutil.NopCloser(bytes.NewReader(payload)) + request.Body = io.NopCloser(bytes.NewReader(payload)) request.ContentLength = int64(len(payload)) request.Header.Set("Content-Type", "application/json") } diff --git a/us-street-api/batch_processing_test.go b/us-street-api/batch_processing_test.go index 8d88796..586a674 100644 --- a/us-street-api/batch_processing_test.go +++ b/us-street-api/batch_processing_test.go @@ -3,7 +3,7 @@ package street import ( "errors" "fmt" - "io/ioutil" + "io" "net/http" "strconv" "testing" @@ -130,7 +130,7 @@ func (f *FakeMultiSender) Send(request *http.Request) ([]byte, error) { f.requests = append(f.requests, request) if request.Body != nil { - body, _ := ioutil.ReadAll(request.Body) + body, _ := io.ReadAll(request.Body) f.requestBodies = append(f.requestBodies, string(body)) } diff --git a/us-street-api/client_test.go b/us-street-api/client_test.go index 4b0394f..eb34944 100644 --- a/us-street-api/client_test.go +++ b/us-street-api/client_test.go @@ -3,7 +3,7 @@ package street import ( "context" "errors" - "io/ioutil" + "io" "net/http" "net/url" "testing" @@ -292,7 +292,7 @@ func (f *FakeSender) Send(request *http.Request) ([]byte, error) { f.callCount++ f.request = request if request != nil && request.Body != nil { - f.requestBody, _ = ioutil.ReadAll(request.Body) + f.requestBody, _ = io.ReadAll(request.Body) } return []byte(f.response), f.err } diff --git a/us-zipcode-api/batch.go b/us-zipcode-api/batch.go index 51c8c03..ac02c01 100644 --- a/us-zipcode-api/batch.go +++ b/us-zipcode-api/batch.go @@ -3,7 +3,7 @@ package zipcode import ( "bytes" "encoding/json" - "io/ioutil" + "io" "net/http" ) @@ -77,7 +77,7 @@ func (b *Batch) serializeGET(request *http.Request) { func (b *Batch) serializePOST(request *http.Request) { request.Method = http.MethodPost payload, _ := json.Marshal(b.lookups) // We control the types being serialized. This is safe. - request.Body = ioutil.NopCloser(bytes.NewReader(payload)) + request.Body = io.NopCloser(bytes.NewReader(payload)) request.ContentLength = int64(len(payload)) request.Header.Set("Content-Type", "application/json") } diff --git a/us-zipcode-api/batch_processing_test.go b/us-zipcode-api/batch_processing_test.go index 1dc5937..a72cba8 100644 --- a/us-zipcode-api/batch_processing_test.go +++ b/us-zipcode-api/batch_processing_test.go @@ -3,7 +3,7 @@ package zipcode import ( "errors" "fmt" - "io/ioutil" + "io" "net/http" "strconv" "testing" @@ -130,7 +130,7 @@ func (f *FakeMultiSender) Send(request *http.Request) ([]byte, error) { f.requests = append(f.requests, request) if request.Body != nil { - body, _ := ioutil.ReadAll(request.Body) + body, _ := io.ReadAll(request.Body) f.requestBodies = append(f.requestBodies, string(body)) } diff --git a/us-zipcode-api/client_test.go b/us-zipcode-api/client_test.go index 11cc1b9..8b576c7 100644 --- a/us-zipcode-api/client_test.go +++ b/us-zipcode-api/client_test.go @@ -3,7 +3,7 @@ package zipcode import ( "context" "errors" - "io/ioutil" + "io" "net/http" "net/url" "testing" @@ -133,7 +133,7 @@ func (f *FakeSender) Send(request *http.Request) ([]byte, error) { f.callCount++ f.request = request if request.Body != nil { - f.requestBody, _ = ioutil.ReadAll(request.Body) + f.requestBody, _ = io.ReadAll(request.Body) } return []byte(f.response), f.err }