Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct benfits to benefits #31

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func main() {
client := finchgo.NewClient(
option.WithAccessToken("my access token"),
)
page, err := client.HRIS.Directory.ListIndividuals(context.TODO(), finchgo.HRISDirectoryListIndividualsParams{})
page, err := client.HRIS.Directory.List(context.TODO(), finchgo.HRISDirectoryListParams{})
if err != nil {
panic(err.Error())
}
Expand Down Expand Up @@ -142,7 +142,7 @@ client := finchgo.NewClient(
option.WithHeader("X-Some-Header", "custom_header_info"),
)

client.HRIS.Directory.ListIndividuals(context.TODO(), ...,
client.HRIS.Directory.List(context.TODO(), ...,
// Override the header
option.WithHeader("X-Some-Header", "some_other_custom_header_info"),
// Add an undocumented field to the request body, using sjson syntax
Expand All @@ -159,7 +159,7 @@ This library provides some conveniences for working with paginated list endpoint
You can use `.ListAutoPaging()` methods to iterate through items across all pages:

```go
iter := client.HRIS.Directory.ListIndividualsAutoPaging(context.TODO(), finchgo.HRISDirectoryListIndividualsParams{})
iter := client.HRIS.Directory.ListAutoPaging(context.TODO(), finchgo.HRISDirectoryListParams{})
// Automatically fetches more pages as needed.
for iter.Next() {
individualInDirectory := iter.Current()
Expand All @@ -174,7 +174,7 @@ Or you can use simple `.List()` methods to fetch a single page and receive a sta
with additional helper methods like `.GetNextPage()`, e.g.:

```go
page, err := client.HRIS.Directory.ListIndividuals(context.TODO(), finchgo.HRISDirectoryListIndividualsParams{})
page, err := client.HRIS.Directory.List(context.TODO(), finchgo.HRISDirectoryListParams{})
for page != nil {
for _, directory := range page.Individuals {
fmt.Printf("%+v\n", directory)
Expand All @@ -196,7 +196,7 @@ When the API returns a non-success status code, we return an error with type
To handle errors, we recommend that you use the `errors.As` pattern:

```go
_, err := client.HRIS.Directory.ListIndividuals(context.TODO(), finchgo.HRISDirectoryListIndividualsParams{})
_, err := client.HRIS.Directory.List(context.TODO(), finchgo.HRISDirectoryListParams{})
if err != nil {
var apierr *finchgo.Error
if errors.As(err, &apierr) {
Expand All @@ -221,9 +221,9 @@ To set a per-retry timeout, use `option.WithRequestTimeout()`.
// This sets the timeout for the request, including all the retries.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
client.HRIS.Directory.ListIndividuals(
client.HRIS.Directory.List(
ctx,
finchgo.HRISDirectoryListIndividualsParams{},
finchgo.HRISDirectoryListParams{},
// This sets the per-retry timeout
option.WithRequestTimeout(20*time.Second),
)
Expand All @@ -244,9 +244,9 @@ client := finchgo.NewClient(
)

// Override per-request:
client.HRIS.Directory.ListIndividuals(
client.HRIS.Directory.List(
context.TODO(),
finchgo.HRISDirectoryListIndividualsParams{},
finchgo.HRISDirectoryListParams{},
option.WithMaxRetries(5),
)
```
Expand Down Expand Up @@ -290,7 +290,7 @@ middleware has been applied.

## Semantic Versioning

This package generally attempts to follow [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:

1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_.
2. Changes that we do not expect to impact the vast majority of users in practice.
Expand Down
4 changes: 2 additions & 2 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Response Types:

Methods:

- <code title="get /employer/directory">client.HRIS.Directory.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#HRISDirectoryService.ListIndividuals">ListIndividuals</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#HRISDirectoryListIndividualsParams">HRISDirectoryListIndividualsParams</a>) (<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#IndividualsPage">IndividualsPage</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /employer/directory">client.HRIS.Directory.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#HRISDirectoryService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#HRISDirectoryListParams">HRISDirectoryListParams</a>) (<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#IndividualsPage">IndividualsPage</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

## Individuals

Expand Down Expand Up @@ -82,9 +82,9 @@ Params Types:

Response Types:

- <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#BenefitContribution">BenefitContribution</a>
- <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#BenefitFrequency">BenefitFrequency</a>
- <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#BenefitType">BenefitType</a>
- <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#BenfitContribution">BenfitContribution</a>
- <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#CompanyBenefit">CompanyBenefit</a>
- <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#CreateCompanyBenefitsResponse">CreateCompanyBenefitsResponse</a>
- <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go">finchgo</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#SupportedBenefit">SupportedBenefit</a>
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestContextCancel(t *testing.T) {
)
cancelCtx, cancel := context.WithCancel(context.Background())
cancel()
res, err := client.HRIS.Directory.ListIndividuals(cancelCtx, finchgo.HRISDirectoryListIndividualsParams{})
res, err := client.HRIS.Directory.List(cancelCtx, finchgo.HRISDirectoryListParams{})
if err == nil || res != nil {
t.Error("Expected there to be a cancel error and for the response to be nil")
}
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestContextCancelDelay(t *testing.T) {
time.Sleep(time.Millisecond * time.Duration(2))
cancel()
}()
res, err := client.HRIS.Directory.ListIndividuals(cancelCtx, finchgo.HRISDirectoryListIndividualsParams{})
res, err := client.HRIS.Directory.List(cancelCtx, finchgo.HRISDirectoryListParams{})
if err == nil || res != nil {
t.Error("expected there to be a cancel error and for the response to be nil")
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestContextDeadline(t *testing.T) {
option.WithAccessToken("AccessToken"),
option.WithHTTPClient(&http.Client{Transport: &neverTransport{}}),
)
res, err := client.HRIS.Directory.ListIndividuals(deadlineCtx, finchgo.HRISDirectoryListIndividualsParams{})
res, err := client.HRIS.Directory.List(deadlineCtx, finchgo.HRISDirectoryListParams{})
if err == nil || res != nil {
t.Error("expected there to be a deadline error and for the response to be nil")
}
Expand Down
68 changes: 34 additions & 34 deletions hrisbenefit.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,35 @@ func (r *HRISBenefitService) ListSupportedBenefitsAutoPaging(ctx context.Context
return shared.NewSinglePageAutoPager(r.ListSupportedBenefits(ctx, opts...))
}

type BenefitContribution struct {
// Contribution amount in cents (if `fixed`) or basis points (if `percent`).
Amount int64 `json:"amount,nullable"`
// Contribution type.
Type BenefitContributionType `json:"type,nullable"`
JSON benefitContributionJSON
}

// benefitContributionJSON contains the JSON metadata for the struct
// [BenefitContribution]
type benefitContributionJSON struct {
Amount apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *BenefitContribution) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

// Contribution type.
type BenefitContributionType string

const (
BenefitContributionTypeFixed BenefitContributionType = "fixed"
BenefitContributionTypePercent BenefitContributionType = "percent"
)

type BenefitFrequency string

const (
Expand Down Expand Up @@ -152,41 +181,12 @@ const (
BenefitTypeCustomPreTax BenefitType = "custom_pre_tax"
)

type BenfitContribution struct {
// Contribution amount in cents (if `fixed`) or basis points (if `percent`).
Amount int64 `json:"amount,nullable"`
// Contribution type.
Type BenfitContributionType `json:"type,nullable"`
JSON benfitContributionJSON
}

// benfitContributionJSON contains the JSON metadata for the struct
// [BenfitContribution]
type benfitContributionJSON struct {
Amount apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *BenfitContribution) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

// Contribution type.
type BenfitContributionType string

const (
BenfitContributionTypeFixed BenfitContributionType = "fixed"
BenfitContributionTypePercent BenfitContributionType = "percent"
)

type CompanyBenefit struct {
BenefitID string `json:"benefit_id,required"`
CompanyContribution BenfitContribution `json:"company_contribution,required,nullable"`
Description string `json:"description,required,nullable"`
EmployeeDeduction BenfitContribution `json:"employee_deduction,required,nullable"`
Frequency BenefitFrequency `json:"frequency,required,nullable"`
BenefitID string `json:"benefit_id,required"`
CompanyContribution BenefitContribution `json:"company_contribution,required,nullable"`
Description string `json:"description,required,nullable"`
EmployeeDeduction BenefitContribution `json:"employee_deduction,required,nullable"`
Frequency BenefitFrequency `json:"frequency,required,nullable"`
// Type of benefit.
Type BenefitType `json:"type,required,nullable"`
JSON companyBenefitJSON
Expand Down
6 changes: 3 additions & 3 deletions hrisbenefitindividual.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ type IndividualBenefitBody struct {
AnnualMaximum int64 `json:"annual_maximum,nullable"`
// If the benefit supports catch up (401k, 403b, etc.), whether catch up is enabled
// for this individual.
CatchUp bool `json:"catch_up,nullable"`
CompanyContribution BenfitContribution `json:"company_contribution,nullable"`
EmployeeDeduction BenfitContribution `json:"employee_deduction,nullable"`
CatchUp bool `json:"catch_up,nullable"`
CompanyContribution BenefitContribution `json:"company_contribution,nullable"`
EmployeeDeduction BenefitContribution `json:"employee_deduction,nullable"`
// Type for HSA contribution limit if the benefit is a HSA.
HsaContributionLimit IndividualBenefitBodyHsaContributionLimit `json:"hsa_contribution_limit,nullable"`
JSON individualBenefitBodyJSON
Expand Down
43 changes: 43 additions & 0 deletions hrisdirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ func NewHRISDirectoryService(opts ...option.RequestOption) (r *HRISDirectoryServ
}

// Read company directory and organization structure
func (r *HRISDirectoryService) List(ctx context.Context, query HRISDirectoryListParams, opts ...option.RequestOption) (res *IndividualsPage, err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "employer/directory"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}

// Read company directory and organization structure
func (r *HRISDirectoryService) ListAutoPaging(ctx context.Context, query HRISDirectoryListParams, opts ...option.RequestOption) *IndividualsPageAutoPager {
return NewIndividualsPageAutoPager(r.List(ctx, query, opts...))
}

// Read company directory and organization structure
//
// Deprecated: use `List` instead
func (r *HRISDirectoryService) ListIndividuals(ctx context.Context, query HRISDirectoryListIndividualsParams, opts ...option.RequestOption) (res *IndividualsPage, err error) {
var raw *http.Response
opts = append(r.Options, opts...)
Expand All @@ -50,6 +75,8 @@ func (r *HRISDirectoryService) ListIndividuals(ctx context.Context, query HRISDi
}

// Read company directory and organization structure
//
// Deprecated: use `List` instead
func (r *HRISDirectoryService) ListIndividualsAutoPaging(ctx context.Context, query HRISDirectoryListIndividualsParams, opts ...option.RequestOption) *IndividualsPageAutoPager {
return NewIndividualsPageAutoPager(r.ListIndividuals(ctx, query, opts...))
}
Expand Down Expand Up @@ -219,6 +246,22 @@ func (r *IndividualInDirectoryManager) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

type HRISDirectoryListParams struct {
// Number of employees to return (defaults to all)
Limit param.Field[int64] `query:"limit"`
// Index to start from (defaults to 0)
Offset param.Field[int64] `query:"offset"`
}

// URLQuery serializes [HRISDirectoryListParams]'s query parameters as
// `url.Values`.
func (r HRISDirectoryListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}

type HRISDirectoryListIndividualsParams struct {
// Number of employees to return (defaults to all)
Limit param.Field[int64] `query:"limit"`
Expand Down
25 changes: 25 additions & 0 deletions hrisdirectory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ import (
"github.com/Finch-API/finch-api-go/option"
)

func TestHRISDirectoryListWithOptionalParams(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := finchgo.NewClient(
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
)
_, err := client.HRIS.Directory.List(context.TODO(), finchgo.HRISDirectoryListParams{
Limit: finchgo.F(int64(0)),
Offset: finchgo.F(int64(0)),
})
if err != nil {
var apierr *finchgo.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

func TestHRISDirectoryListIndividualsWithOptionalParams(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
Expand Down
2 changes: 1 addition & 1 deletion paginationauto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAutoPagination(t *testing.T) {
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
)
iter := client.HRIS.Directory.ListIndividualsAutoPaging(context.TODO(), finchgo.HRISDirectoryListIndividualsParams{})
iter := client.HRIS.Directory.ListAutoPaging(context.TODO(), finchgo.HRISDirectoryListParams{})
// Prism mock isn't going to give us real pagination
for i := 0; i < 3 && iter.Next(); i++ {
directory := iter.Current()
Expand Down
2 changes: 1 addition & 1 deletion paginationmanual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestManualPagination(t *testing.T) {
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
)
page, err := client.HRIS.Directory.ListIndividuals(context.TODO(), finchgo.HRISDirectoryListIndividualsParams{})
page, err := client.HRIS.Directory.List(context.TODO(), finchgo.HRISDirectoryListParams{})
if err != nil {
t.Fatalf("err should be nil: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestUsage(t *testing.T) {
option.WithBaseURL(baseURL),
option.WithAccessToken("AccessToken"),
)
page, err := client.HRIS.Directory.ListIndividuals(context.TODO(), finchgo.HRISDirectoryListIndividualsParams{})
page, err := client.HRIS.Directory.List(context.TODO(), finchgo.HRISDirectoryListParams{})
if err != nil {
t.Error(err)
}
Expand Down