Skip to content

Commit

Permalink
update method visibility (#973)
Browse files Browse the repository at this point in the history
* update method visibility

* update comment
  • Loading branch information
etsai-stripe committed Sep 16, 2022
1 parent 91f03bf commit af04d45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions pkg/requests/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (rb *Base) MakeMultiPartRequest(ctx context.Context, apiKey, path string, p

// MakeRequest will make a request to the Stripe API with the specific variables given to it
func (rb *Base) MakeRequest(ctx context.Context, apiKey, path string, params *RequestParameters, errOnStatus bool) ([]byte, error) {
data, err := rb.buildDataForRequest(params)
data, err := rb.BuildDataForRequest(params)
if err != nil {
return []byte{}, err
}
Expand Down Expand Up @@ -274,13 +274,14 @@ func (rb *Base) Confirm() (bool, error) {
return rb.confirmCommand()
}

// BuildDataForRequest builds request payload
// Note: We converted to using two arrays to track keys and values, with our own
// implementation of Go's url.Values Encode function due to our query parameters being
// order sensitive for API requests involving arrays like `items` for `/v1/orders`.
// Go's url.Values uses Go's map, which jumbles the key ordering, and their Encode
// implementation sorts keys by alphabetical order, but this doesn't work for us since
// some API endpoints have required parameter ordering. Yes, this is hacky, but it works.
func (rb *Base) buildDataForRequest(params *RequestParameters) (string, error) {
func (rb *Base) BuildDataForRequest(params *RequestParameters) (string, error) {
keys := []string{}
values := []string{}

Expand Down
12 changes: 6 additions & 6 deletions pkg/requests/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestBuildDataForRequest(t *testing.T) {
params := &RequestParameters{data: []string{"bender=robot", "fry=human"}}
expected := "bender=robot&fry=human"

output, _ := rb.buildDataForRequest(params)
output, _ := rb.BuildDataForRequest(params)
require.Equal(t, expected, output)
}

Expand All @@ -28,7 +28,7 @@ func TestBuildDataForRequestParamOrdering(t *testing.T) {
params := &RequestParameters{data: []string{"fry=human", "bender=robot"}}
expected := "fry=human&bender=robot"

output, _ := rb.buildDataForRequest(params)
output, _ := rb.BuildDataForRequest(params)
require.Equal(t, expected, output)
}

Expand All @@ -37,7 +37,7 @@ func TestBuildDataForRequestExpand(t *testing.T) {
params := &RequestParameters{expand: []string{"futurama.employees", "futurama.ships"}}
expected := "expand[]=futurama.employees&expand[]=futurama.ships"

output, _ := rb.buildDataForRequest(params)
output, _ := rb.BuildDataForRequest(params)
require.Equal(t, expected, output)
}

Expand All @@ -53,7 +53,7 @@ func TestBuildDataForRequestPagination(t *testing.T) {

expected := "limit=10&starting_after=bender&ending_before=leela"

output, _ := rb.buildDataForRequest(params)
output, _ := rb.BuildDataForRequest(params)
require.Equal(t, expected, output)
}

Expand All @@ -69,7 +69,7 @@ func TestBuildDataForRequestGetOnly(t *testing.T) {

expected := ""

output, _ := rb.buildDataForRequest(params)
output, _ := rb.BuildDataForRequest(params)
require.Equal(t, expected, output)
}

Expand All @@ -78,7 +78,7 @@ func TestBuildDataForRequestInvalidArgument(t *testing.T) {
params := &RequestParameters{data: []string{"bender=robot", "fry"}}
expected := "Invalid data argument: fry"

data, err := rb.buildDataForRequest(params)
data, err := rb.BuildDataForRequest(params)
require.Equal(t, "", data)
require.Equal(t, expected, err.Error())
}
Expand Down

0 comments on commit af04d45

Please sign in to comment.