Skip to content

Commit

Permalink
feat(api): add /jobs endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Dec 4, 2023
1 parent e82c058 commit d2803e5
Show file tree
Hide file tree
Showing 14 changed files with 568 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 18
configured_endpoints: 22
3 changes: 3 additions & 0 deletions aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ const OperationSupportClientAccessOnly = shared.OperationSupportClientAccessOnly

// This is an alias to an internal type.
type OperationSupportMatrix = shared.OperationSupportMatrix

// This is an alias to an internal type.
type Paging = shared.Paging
27 changes: 26 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go/internal/shared">shared</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go/internal/shared#OperationSupport">OperationSupport</a>
- <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go/internal/shared">shared</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go/internal/shared#OperationSupportMatrix">OperationSupportMatrix</a>
- <a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go/internal/shared">shared</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go/internal/shared#Paging">Paging</a>

# finchgo

Expand All @@ -12,7 +13,6 @@ 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#Income">Income</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#Location">Location</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#Money">Money</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#Paging">Paging</a>

## Company

Expand Down Expand Up @@ -157,3 +157,28 @@ Response Types:
Methods:

- <code title="post /forward">client.RequestForwarding.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#RequestForwardingService.Forward">Forward</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <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#RequestForwardingForwardParams">RequestForwardingForwardParams</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#RequestForwardingForwardResponse">RequestForwardingForwardResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

# Jobs

## Automated

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#AutomatedAsyncJob">AutomatedAsyncJob</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#JobAutomatedNewResponse">JobAutomatedNewResponse</a>

Methods:

- <code title="post /jobs/automated">client.Jobs.Automated.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#JobAutomatedService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <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#JobAutomatedNewParams">JobAutomatedNewParams</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#JobAutomatedNewResponse">JobAutomatedNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /jobs/automated/{job_id}">client.Jobs.Automated.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#JobAutomatedService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, jobID <a href="https://pkg.go.dev/builtin#string">string</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#AutomatedAsyncJob">AutomatedAsyncJob</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /jobs/automated">client.Jobs.Automated.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#JobAutomatedService.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#JobAutomatedListParams">JobAutomatedListParams</a>) (<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go/internal/shared">shared</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go/internal/shared#Page">Page</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#AutomatedAsyncJob">AutomatedAsyncJob</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

## Manual

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#ManualAsyncJob">ManualAsyncJob</a>

Methods:

- <code title="get /jobs/manual/{job_id}">client.Jobs.Manual.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#JobManualService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, jobID <a href="https://pkg.go.dev/builtin#string">string</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#ManualAsyncJob">ManualAsyncJob</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Client struct {
Account *AccountService
Webhooks *WebhookService
RequestForwarding *RequestForwardingService
Jobs *JobService
}

// NewClient generates a new client with the default option read from the
Expand All @@ -44,6 +45,7 @@ func NewClient(opts ...option.RequestOption) (r *Client) {
r.Account = NewAccountService(opts...)
r.Webhooks = NewWebhookService(opts...)
r.RequestForwarding = NewRequestForwardingService(opts...)
r.Jobs = NewJobService(opts...)

return
}
20 changes: 0 additions & 20 deletions hris.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,3 @@ type moneyJSON struct {
func (r *Money) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

type Paging struct {
// The total number of elements for the entire query (not just the given page)
Count int64 `json:"count"`
// The current start index of the returned list of elements
Offset int64 `json:"offset"`
JSON pagingJSON `json:"-"`
}

// pagingJSON contains the JSON metadata for the struct [Paging]
type pagingJSON struct {
Count apijson.Field
Offset apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *Paging) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
3 changes: 2 additions & 1 deletion hrisdirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Finch-API/finch-api-go/internal/apiquery"
"github.com/Finch-API/finch-api-go/internal/param"
"github.com/Finch-API/finch-api-go/internal/requestconfig"
"github.com/Finch-API/finch-api-go/internal/shared"
"github.com/Finch-API/finch-api-go/option"
)

Expand Down Expand Up @@ -84,7 +85,7 @@ func (r *HRISDirectoryService) ListIndividualsAutoPaging(ctx context.Context, qu
type IndividualsPage struct {
// The array of employees.
Individuals []IndividualInDirectory `json:"individuals,required"`
Paging Paging `json:"paging,required"`
Paging shared.Paging `json:"paging,required"`
JSON individualsPageJSON `json:"-"`
cfg *requestconfig.RequestConfig
res *http.Response
Expand Down
2 changes: 1 addition & 1 deletion hrispaystatement.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (r *PayStatementResponse) UnmarshalJSON(data []byte) (err error) {
}

type PayStatementResponseBody struct {
Paging Paging `json:"paging"`
Paging shared.Paging `json:"paging"`
// The array of pay statements for the current payment.
PayStatements []PayStatement `json:"pay_statements"`
JSON payStatementResponseBodyJSON `json:"-"`
Expand Down
90 changes: 90 additions & 0 deletions internal/shared/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,93 @@ func (r *ResponsesPageAutoPager[T]) Err() error {
func (r *ResponsesPageAutoPager[T]) Index() int {
return r.run
}

type Page[T any] struct {
Paging Paging `json:"paging,required"`
Data []T `json:"data"`
JSON pageJSON `json:"-"`
cfg *requestconfig.RequestConfig
res *http.Response
}

// pageJSON contains the JSON metadata for the struct [Page[T]]
type pageJSON struct {
Paging apijson.Field
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

// NextPage returns the next page as defined by this pagination style. When there
// is no next page, this function will return a 'nil' for the page value, but will
// not return an error
func (r *Page[T]) GetNextPage() (res *Page[T], err error) {
// This page represents a response that isn't actually paginated at the API level
// so there will never be a next page.
cfg := (*requestconfig.RequestConfig)(nil)
if cfg == nil {
return nil, nil
}
var raw *http.Response
cfg.ResponseInto = &raw
cfg.ResponseBodyInto = &res
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}

func (r *Page[T]) SetPageConfig(cfg *requestconfig.RequestConfig, res *http.Response) {
r.cfg = cfg
r.res = res
}

type PageAutoPager[T any] struct {
page *Page[T]
cur T
idx int
run int
err error
}

func NewPageAutoPager[T any](page *Page[T], err error) *PageAutoPager[T] {
return &PageAutoPager[T]{
page: page,
err: err,
}
}

func (r *PageAutoPager[T]) Next() bool {
if r.page == nil || len(r.page.Data) == 0 {
return false
}
if r.idx >= len(r.page.Data) {
r.idx = 0
r.page, r.err = r.page.GetNextPage()
if r.err != nil || r.page == nil || len(r.page.Data) == 0 {
return false
}
}
r.cur = r.page.Data[r.idx]
r.run += 1
r.idx += 1
return true
}

func (r *PageAutoPager[T]) Current() T {
return r.cur
}

func (r *PageAutoPager[T]) Err() error {
return r.err
}

func (r *PageAutoPager[T]) Index() int {
return r.run
}
20 changes: 20 additions & 0 deletions internal/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,23 @@ type operationSupportMatrixJSON struct {
func (r *OperationSupportMatrix) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

type Paging struct {
// The total number of elements for the entire query (not just the given page)
Count int64 `json:"count"`
// The current start index of the returned list of elements
Offset int64 `json:"offset"`
JSON pagingJSON `json:"-"`
}

// pagingJSON contains the JSON metadata for the struct [Paging]
type pagingJSON struct {
Count apijson.Field
Offset apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *Paging) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
28 changes: 28 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// File generated from our OpenAPI spec by Stainless.

package finchgo

import (
"github.com/Finch-API/finch-api-go/option"
)

// JobService contains methods and other services that help with interacting with
// the Finch API. Note, unlike clients, this service does not read variables from
// the environment automatically. You should not instantiate this service directly,
// and instead use the [NewJobService] method instead.
type JobService struct {
Options []option.RequestOption
Automated *JobAutomatedService
Manual *JobManualService
}

// NewJobService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewJobService(opts ...option.RequestOption) (r *JobService) {
r = &JobService{}
r.Options = opts
r.Automated = NewJobAutomatedService(opts...)
r.Manual = NewJobManualService(opts...)
return
}
Loading

0 comments on commit d2803e5

Please sign in to comment.