Skip to content

Commit

Permalink
chore(internal): rearrange client arguments (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Oct 12, 2023
1 parent c9b26ec commit 81460c8
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (

func main() {
client := finchgo.NewClient(
option.WithAccessToken("my access token"),
option.WithAccessToken("My Access Token"),
)
page, err := client.HRIS.Directory.List(context.TODO(), finchgo.HRISDirectoryListParams{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAccountDisconnect(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.Account.Disconnect(context.TODO())
if err != nil {
Expand All @@ -45,7 +45,7 @@ func TestAccountIntrospect(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.Account.Introspect(context.TODO())
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestContextCancel(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
cancelCtx, cancel := context.WithCancel(context.Background())
cancel()
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestContextCancelDelay(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
option.WithHTTPClient(&http.Client{Transport: &neverTransport{}}),
)
cancelCtx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestContextDeadline(t *testing.T) {
go func() {
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
option.WithHTTPClient(&http.Client{Transport: &neverTransport{}}),
)
res, err := client.HRIS.Directory.List(deadlineCtx, finchgo.HRISDirectoryListParams{})
Expand Down
10 changes: 5 additions & 5 deletions hrisbenefit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestHRISBenefitNewWithOptionalParams(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Benefits.New(context.TODO(), finchgo.HRISBenefitNewParams{
Description: finchgo.F("string"),
Expand All @@ -49,7 +49,7 @@ func TestHRISBenefitGet(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Benefits.Get(context.TODO(), "string")
if err != nil {
Expand All @@ -71,7 +71,7 @@ func TestHRISBenefitUpdateWithOptionalParams(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Benefits.Update(
context.TODO(),
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestHRISBenefitList(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Benefits.List(context.TODO())
if err != nil {
Expand All @@ -121,7 +121,7 @@ func TestHRISBenefitListSupportedBenefits(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Benefits.ListSupportedBenefits(context.TODO())
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions hrisbenefitindividual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestHRISBenefitIndividualEnrolledIDs(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Benefits.Individuals.EnrolledIDs(context.TODO(), "string")
if err != nil {
Expand All @@ -45,7 +45,7 @@ func TestHRISBenefitIndividualGetManyBenefitsWithOptionalParams(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Benefits.Individuals.GetManyBenefits(
context.TODO(),
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestHRISBenefitIndividualUnenrollManyWithOptionalParams(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Benefits.Individuals.UnenrollMany(
context.TODO(),
Expand Down
2 changes: 1 addition & 1 deletion hriscompany_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestHRISCompanyGet(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Company.Get(context.TODO())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions hrisdirectory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestHRISDirectoryListWithOptionalParams(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Directory.List(context.TODO(), finchgo.HRISDirectoryListParams{
Limit: finchgo.F(int64(0)),
Expand All @@ -48,7 +48,7 @@ func TestHRISDirectoryListIndividualsWithOptionalParams(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Directory.ListIndividuals(context.TODO(), finchgo.HRISDirectoryListIndividualsParams{
Limit: finchgo.F(int64(0)),
Expand Down
2 changes: 1 addition & 1 deletion hrisemployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestHRISEmploymentGetMany(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Employments.GetMany(context.TODO(), finchgo.HRISEmploymentGetManyParams{
Requests: finchgo.F([]finchgo.HRISEmploymentGetManyParamsRequest{{
Expand Down
2 changes: 1 addition & 1 deletion hrisindividual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestHRISIndividualGetManyWithOptionalParams(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Individuals.GetMany(context.TODO(), finchgo.HRISIndividualGetManyParams{
Options: finchgo.F(finchgo.HRISIndividualGetManyParamsOptions{
Expand Down
2 changes: 1 addition & 1 deletion hrispayment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestHRISPaymentList(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.Payments.List(context.TODO(), finchgo.HRISPaymentListParams{
EndDate: finchgo.F(time.Now()),
Expand Down
2 changes: 1 addition & 1 deletion hrispaystatement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestHRISPayStatementGetMany(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.HRIS.PayStatements.GetMany(context.TODO(), finchgo.HRISPayStatementGetManyParams{
Requests: finchgo.F([]finchgo.HRISPayStatementGetManyParamsRequest{{
Expand Down
10 changes: 5 additions & 5 deletions internal/requestconfig/requestconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ type RequestConfig struct {
HTTPClient *http.Client
Middlewares []middleware
AccessToken string
ClientID string
ClientSecret string
WebhookSecret string
// If ResponseBodyInto not nil, then we will attempt to deserialize into
// ResponseBodyInto. If Destination is a []byte, then it will return the body as
// is.
ResponseBodyInto interface{}
// ResponseInto copies the \*http.Response of the corresponding request into the
// given address
ResponseInto **http.Response
ClientID string
ClientSecret string
WebhookSecret string
Buffer []byte
ResponseInto **http.Response
Buffer []byte
}

// middleware is exactly the same type as the Middleware type found in the [option] package,
Expand Down
17 changes: 8 additions & 9 deletions option/requestoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,21 @@ func WithRequestTimeout(dur time.Duration) RequestOption {
}
}

// WithAccessToken returns a RequestOption that specifies a Access Token
// to be used as the basis for authentication.
func WithAccessToken(key string) RequestOption {
return func(r *requestconfig.RequestConfig) error {
r.AccessToken = key
return r.Apply(WithHeader("Authorization", fmt.Sprintf("Bearer %s", r.AccessToken)))
}
}

// WithEnvironmentProduction returns a RequestOption that sets the current
// environment to be the "production" environment. An environment specifies which base URL
// to use by default.
func WithEnvironmentProduction() RequestOption {
return WithBaseURL("https://api.tryfinch.com/")
}

// WithAccessToken returns a RequestOption that sets the client setting "access_token".
func WithAccessToken(value string) RequestOption {
return func(r *requestconfig.RequestConfig) error {
r.AccessToken = value
return r.Apply(WithHeader("authorization", fmt.Sprintf("Bearer %s", r.AccessToken)))
}
}

// WithClientID returns a RequestOption that sets the client setting "client_id".
func WithClientID(value string) RequestOption {
return func(r *requestconfig.RequestConfig) error {
Expand Down
2 changes: 1 addition & 1 deletion paginationauto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestAutoPagination(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
iter := client.HRIS.Directory.ListAutoPaging(context.TODO(), finchgo.HRISDirectoryListParams{})
// Prism mock isn't going to give us real pagination
Expand Down
2 changes: 1 addition & 1 deletion paginationmanual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestManualPagination(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
page, err := client.HRIS.Directory.List(context.TODO(), finchgo.HRISDirectoryListParams{})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestProviderList(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.Providers.List(context.TODO())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion requestforwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestRequestForwardingForwardWithOptionalParams(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
_, err := client.RequestForwarding.Forward(context.TODO(), finchgo.RequestForwardingForwardParams{
Method: finchgo.F("POST"),
Expand Down
2 changes: 1 addition & 1 deletion usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestUsage(t *testing.T) {
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
option.WithAccessToken("My Access Token"),
)
page, err := client.HRIS.Directory.List(context.TODO(), finchgo.HRISDirectoryListParams{})
if err != nil {
Expand Down

0 comments on commit 81460c8

Please sign in to comment.