Skip to content

Commit

Permalink
Merge branch 'master' into us-enrichment-api
Browse files Browse the repository at this point in the history
  • Loading branch information
LandonSmarty committed Oct 5, 2023
2 parents 4b0cbef + 13013d5 commit 00e8028
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 26 deletions.
4 changes: 2 additions & 2 deletions internal/sdk/doc_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sdk

import (
"io/ioutil"
"io"
"net/http"
)

Expand Down Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions internal/sdk/http_sender.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sdk

import (
"io/ioutil"
"io"
"net/http"

"github.com/smartystreets/smartystreets-go-sdk"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/sdk/keep_alive_close_client_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sdk

import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/sdk/retry_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sdk
import (
"bytes"
"io"
"io/ioutil"
"math/rand"
"net/http"
"sync"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions us-autocomplete-pro-api/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type (
PreferZIP []string
PreferRatio int
Geolocation Geolocation
Selected string

Results []*Suggestion
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
}
9 changes: 9 additions & 0 deletions us-autocomplete-pro-api/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
7 changes: 4 additions & 3 deletions us-extract-api/lookup.go
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions us-extract-api/lookup_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package extract

import (
"io/ioutil"
"io"
"net/http"
"net/url"
"testing"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions us-street-api/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package street
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
)

Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions us-street-api/batch_processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package street
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"testing"
Expand Down Expand Up @@ -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))
}

Expand Down
4 changes: 2 additions & 2 deletions us-street-api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package street
import (
"context"
"errors"
"io/ioutil"
"io"
"net/http"
"net/url"
"testing"
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions us-zipcode-api/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package zipcode
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
)

Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions us-zipcode-api/batch_processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package zipcode
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"testing"
Expand Down Expand Up @@ -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))
}

Expand Down
4 changes: 2 additions & 2 deletions us-zipcode-api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package zipcode
import (
"context"
"errors"
"io/ioutil"
"io"
"net/http"
"net/url"
"testing"
Expand Down Expand Up @@ -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
}

0 comments on commit 00e8028

Please sign in to comment.