Skip to content

Commit

Permalink
updated options with a constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
KamenDimitrov97 committed Feb 28, 2024
2 parents 48ee78e + c2da551 commit a17b658
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ Use the GetScrubber method to send a request to find scrubber results based on q

```go
// Set query parameters - no limit to which keys and values you set - please refer to swagger spec for list of available parameters
query := url.Values{}
query.Add("q", "E00000013,01220")
opt := sdk.OptInit()
opt.Q("E00000013,01220")

resp, err := scrubberAPIClient.GetScrubber(ctx, sdk.Options{sdk.Query: query})
resp, err := scrubberAPIClient.GetScrubber(ctx, opt)
if err != nil {
// handle error
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (cli *Client) Checker(ctx context.Context, check *health.CheckState) error

// GetScrubber gets a list of OAC and SIC codes based on the request
// options contain headers and a query
func (cli *Client) GetScrubber(ctx context.Context, options Options) (*models.ScrubberResp, errors.Error) {
func (cli *Client) GetScrubber(ctx context.Context, options *Options) (*models.ScrubberResp, errors.Error) {
path := fmt.Sprintf("%s/scrubber", cli.URL())
if options.Query != nil {
path = path + "?" + options.Query.Encode()
Expand Down
7 changes: 3 additions & 4 deletions sdk/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"io"
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -131,9 +130,9 @@ func TestGetScrubber(t *testing.T) {
scrubberAPIClient := newScrubberAPIClient(httpClient)

c.Convey("When GetScrubber is called", func() {
query := url.Values{}
query.Add("q", "sic code")
resp, err := scrubberAPIClient.GetScrubber(ctx, Options{Query: query})
opt := OptInit()
opt.Q("sic code")
resp, err := scrubberAPIClient.GetScrubber(ctx, opt)

c.Convey("Then the expected response body is returned", func() {
c.So(*resp, c.ShouldResemble, scrubberResults)
Expand Down
8 changes: 8 additions & 0 deletions sdk/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ type Options struct {
Query url.Values
}

// empty Options
func OptInit() *Options {
return &Options{
Query: url.Values{},
Headers: http.Header{},
}
}

// Q sets the 'q' Query parameter to the request
func (o *Options) Q(val string) *Options {
o.Query.Set("q", val)
Expand Down

0 comments on commit a17b658

Please sign in to comment.