Skip to content

Commit

Permalink
feat(api): Add connect sessions endpoints (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Sep 20, 2024
1 parent 9fa8c1e commit 77639ad
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 36
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-0b6874fdff2a5ed63c4e84830811f10a91e10e9c3e300a33f25422ad0afb945b.yml
configured_endpoints: 38
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-e915b33a18d4e6592966587ef174bbfe316edd9bc1fd7c17f86f372089bf80eb.yml
14 changes: 14 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,17 @@ Methods:

- <code title="get /employer/pay-groups/{pay_group_id}">client.Payroll.PayGroups.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#PayrollPayGroupService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, payGroupID <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#PayrollPayGroupGetResponse">PayrollPayGroupGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /employer/pay-groups">client.Payroll.PayGroups.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#PayrollPayGroupService.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#PayrollPayGroupListParams">PayrollPayGroupListParams</a>) (<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go/internal/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go/internal/pagination#SinglePage">SinglePage</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#PayrollPayGroupListResponse">PayrollPayGroupListResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

# Connect

## Sessions

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

Methods:

- <code title="post /connect/sessions">client.Connect.Sessions.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#ConnectSessionService.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#ConnectSessionNewParams">ConnectSessionNewParams</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#ConnectSessionNewResponse">ConnectSessionNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="post /connect/sessions/reauthenticate">client.Connect.Sessions.<a href="https://pkg.go.dev/github.com/Finch-API/finch-api-go#ConnectSessionService.Reauthenticate">Reauthenticate</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#ConnectSessionReauthenticateParams">ConnectSessionReauthenticateParams</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#ConnectSessionReauthenticateResponse">ConnectSessionReauthenticateResponse</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 @@ -25,6 +25,7 @@ type Client struct {
Jobs *JobService
Sandbox *SandboxService
Payroll *PayrollService
Connect *ConnectService
}

// NewClient generates a new client with the default option read from the
Expand Down Expand Up @@ -62,6 +63,7 @@ func NewClient(opts ...option.RequestOption) (r *Client) {
r.Jobs = NewJobService(opts...)
r.Sandbox = NewSandboxService(opts...)
r.Payroll = NewPayrollService(opts...)
r.Connect = NewConnectService(opts...)

return
}
Expand Down
28 changes: 28 additions & 0 deletions connect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package finchgo

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

// ConnectService 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 [NewConnectService] method instead.
type ConnectService struct {
Options []option.RequestOption
Sessions *ConnectSessionService
}

// NewConnectService 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 NewConnectService(opts ...option.RequestOption) (r *ConnectService) {
r = &ConnectService{}
r.Options = opts
r.Sessions = NewConnectSessionService(opts...)
return
}
217 changes: 217 additions & 0 deletions connectsession.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package finchgo

import (
"context"
"net/http"

"github.com/Finch-API/finch-api-go/internal/apijson"
"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/option"
)

// ConnectSessionService 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 [NewConnectSessionService] method instead.
type ConnectSessionService struct {
Options []option.RequestOption
}

// NewConnectSessionService 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 NewConnectSessionService(opts ...option.RequestOption) (r *ConnectSessionService) {
r = &ConnectSessionService{}
r.Options = opts
return
}

// Create a new connect session for an employer
func (r *ConnectSessionService) New(ctx context.Context, body ConnectSessionNewParams, opts ...option.RequestOption) (res *ConnectSessionNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "connect/sessions"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}

// Create a new Connect session for reauthenticating an existing connection
func (r *ConnectSessionService) Reauthenticate(ctx context.Context, body ConnectSessionReauthenticateParams, opts ...option.RequestOption) (res *ConnectSessionReauthenticateResponse, err error) {
opts = append(r.Options[:], opts...)
path := "connect/sessions/reauthenticate"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}

type ConnectSessionNewResponse struct {
// The Connect URL to redirect the user to for authentication
ConnectURL string `json:"connect_url,required" format:"uri"`
// The unique identifier for the created connect session
SessionID string `json:"session_id,required"`
JSON connectSessionNewResponseJSON `json:"-"`
}

// connectSessionNewResponseJSON contains the JSON metadata for the struct
// [ConnectSessionNewResponse]
type connectSessionNewResponseJSON struct {
ConnectURL apijson.Field
SessionID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

func (r connectSessionNewResponseJSON) RawJSON() string {
return r.raw
}

type ConnectSessionReauthenticateResponse struct {
// The Connect URL to redirect the user to for reauthentication
ConnectURL string `json:"connect_url,required" format:"uri"`
// The unique identifier for the created connect session
SessionID string `json:"session_id,required"`
JSON connectSessionReauthenticateResponseJSON `json:"-"`
}

// connectSessionReauthenticateResponseJSON contains the JSON metadata for the
// struct [ConnectSessionReauthenticateResponse]
type connectSessionReauthenticateResponseJSON struct {
ConnectURL apijson.Field
SessionID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

func (r connectSessionReauthenticateResponseJSON) RawJSON() string {
return r.raw
}

type ConnectSessionNewParams struct {
CustomerID param.Field[string] `json:"customer_id,required"`
CustomerName param.Field[string] `json:"customer_name,required"`
Products param.Field[[]ConnectSessionNewParamsProduct] `json:"products,required"`
CustomerEmail param.Field[string] `json:"customer_email" format:"email"`
Integration param.Field[ConnectSessionNewParamsIntegration] `json:"integration"`
Manual param.Field[bool] `json:"manual"`
// The number of minutes until the session expires (defaults to 10,080, which is 7
// days)
MinutesToExpire param.Field[float64] `json:"minutes_to_expire"`
RedirectUri param.Field[string] `json:"redirect_uri"`
Sandbox param.Field[ConnectSessionNewParamsSandbox] `json:"sandbox"`
}

func (r ConnectSessionNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The Finch products that can be requested during the Connect flow.
type ConnectSessionNewParamsProduct string

const (
ConnectSessionNewParamsProductCompany ConnectSessionNewParamsProduct = "company"
ConnectSessionNewParamsProductDirectory ConnectSessionNewParamsProduct = "directory"
ConnectSessionNewParamsProductIndividual ConnectSessionNewParamsProduct = "individual"
ConnectSessionNewParamsProductEmployment ConnectSessionNewParamsProduct = "employment"
ConnectSessionNewParamsProductPayment ConnectSessionNewParamsProduct = "payment"
ConnectSessionNewParamsProductPayStatement ConnectSessionNewParamsProduct = "pay_statement"
ConnectSessionNewParamsProductBenefits ConnectSessionNewParamsProduct = "benefits"
ConnectSessionNewParamsProductSsn ConnectSessionNewParamsProduct = "ssn"
)

func (r ConnectSessionNewParamsProduct) IsKnown() bool {
switch r {
case ConnectSessionNewParamsProductCompany, ConnectSessionNewParamsProductDirectory, ConnectSessionNewParamsProductIndividual, ConnectSessionNewParamsProductEmployment, ConnectSessionNewParamsProductPayment, ConnectSessionNewParamsProductPayStatement, ConnectSessionNewParamsProductBenefits, ConnectSessionNewParamsProductSsn:
return true
}
return false
}

type ConnectSessionNewParamsIntegration struct {
AuthMethod param.Field[ConnectSessionNewParamsIntegrationAuthMethod] `json:"auth_method"`
Provider param.Field[string] `json:"provider"`
}

func (r ConnectSessionNewParamsIntegration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type ConnectSessionNewParamsIntegrationAuthMethod string

const (
ConnectSessionNewParamsIntegrationAuthMethodAssisted ConnectSessionNewParamsIntegrationAuthMethod = "assisted"
ConnectSessionNewParamsIntegrationAuthMethodCredential ConnectSessionNewParamsIntegrationAuthMethod = "credential"
ConnectSessionNewParamsIntegrationAuthMethodOAuth ConnectSessionNewParamsIntegrationAuthMethod = "oauth"
ConnectSessionNewParamsIntegrationAuthMethodAPIToken ConnectSessionNewParamsIntegrationAuthMethod = "api_token"
)

func (r ConnectSessionNewParamsIntegrationAuthMethod) IsKnown() bool {
switch r {
case ConnectSessionNewParamsIntegrationAuthMethodAssisted, ConnectSessionNewParamsIntegrationAuthMethodCredential, ConnectSessionNewParamsIntegrationAuthMethodOAuth, ConnectSessionNewParamsIntegrationAuthMethodAPIToken:
return true
}
return false
}

type ConnectSessionNewParamsSandbox string

const (
ConnectSessionNewParamsSandboxFinch ConnectSessionNewParamsSandbox = "finch"
ConnectSessionNewParamsSandboxProvider ConnectSessionNewParamsSandbox = "provider"
)

func (r ConnectSessionNewParamsSandbox) IsKnown() bool {
switch r {
case ConnectSessionNewParamsSandboxFinch, ConnectSessionNewParamsSandboxProvider:
return true
}
return false
}

type ConnectSessionReauthenticateParams struct {
// The ID of the existing connection to reauthenticate
ConnectionID param.Field[string] `json:"connection_id,required"`
// The number of minutes until the session expires (defaults to 10,080, which is 7
// days)
MinutesToExpire param.Field[int64] `json:"minutes_to_expire"`
// The products to request access to (optional for reauthentication)
Products param.Field[[]ConnectSessionReauthenticateParamsProduct] `json:"products"`
// The URI to redirect to after the Connect flow is completed
RedirectUri param.Field[string] `json:"redirect_uri" format:"uri"`
}

func (r ConnectSessionReauthenticateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The Finch products that can be requested during the Connect flow.
type ConnectSessionReauthenticateParamsProduct string

const (
ConnectSessionReauthenticateParamsProductCompany ConnectSessionReauthenticateParamsProduct = "company"
ConnectSessionReauthenticateParamsProductDirectory ConnectSessionReauthenticateParamsProduct = "directory"
ConnectSessionReauthenticateParamsProductIndividual ConnectSessionReauthenticateParamsProduct = "individual"
ConnectSessionReauthenticateParamsProductEmployment ConnectSessionReauthenticateParamsProduct = "employment"
ConnectSessionReauthenticateParamsProductPayment ConnectSessionReauthenticateParamsProduct = "payment"
ConnectSessionReauthenticateParamsProductPayStatement ConnectSessionReauthenticateParamsProduct = "pay_statement"
ConnectSessionReauthenticateParamsProductBenefits ConnectSessionReauthenticateParamsProduct = "benefits"
ConnectSessionReauthenticateParamsProductSsn ConnectSessionReauthenticateParamsProduct = "ssn"
)

func (r ConnectSessionReauthenticateParamsProduct) IsKnown() bool {
switch r {
case ConnectSessionReauthenticateParamsProductCompany, ConnectSessionReauthenticateParamsProductDirectory, ConnectSessionReauthenticateParamsProductIndividual, ConnectSessionReauthenticateParamsProductEmployment, ConnectSessionReauthenticateParamsProductPayment, ConnectSessionReauthenticateParamsProductPayStatement, ConnectSessionReauthenticateParamsProductBenefits, ConnectSessionReauthenticateParamsProductSsn:
return true
}
return false
}
80 changes: 80 additions & 0 deletions connectsession_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package finchgo_test

import (
"context"
"errors"
"os"
"testing"

"github.com/Finch-API/finch-api-go"
"github.com/Finch-API/finch-api-go/internal/testutil"
"github.com/Finch-API/finch-api-go/option"
)

func TestConnectSessionNewWithOptionalParams(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("My Access Token"),
option.WithClientID("4ab15e51-11ad-49f4-acae-f343b7794375"),
option.WithClientSecret("My Client Secret"),
)
_, err := client.Connect.Sessions.New(context.TODO(), finchgo.ConnectSessionNewParams{
CustomerID: finchgo.F("x"),
CustomerName: finchgo.F("x"),
Products: finchgo.F([]finchgo.ConnectSessionNewParamsProduct{finchgo.ConnectSessionNewParamsProductCompany, finchgo.ConnectSessionNewParamsProductDirectory, finchgo.ConnectSessionNewParamsProductIndividual}),
CustomerEmail: finchgo.F("[email protected]"),
Integration: finchgo.F(finchgo.ConnectSessionNewParamsIntegration{
AuthMethod: finchgo.F(finchgo.ConnectSessionNewParamsIntegrationAuthMethodAssisted),
Provider: finchgo.F("provider"),
}),
Manual: finchgo.F(true),
MinutesToExpire: finchgo.F(1.000000),
RedirectUri: finchgo.F("redirect_uri"),
Sandbox: finchgo.F(finchgo.ConnectSessionNewParamsSandboxFinch),
})
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 TestConnectSessionReauthenticateWithOptionalParams(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("My Access Token"),
option.WithClientID("4ab15e51-11ad-49f4-acae-f343b7794375"),
option.WithClientSecret("My Client Secret"),
)
_, err := client.Connect.Sessions.Reauthenticate(context.TODO(), finchgo.ConnectSessionReauthenticateParams{
ConnectionID: finchgo.F("connection_id"),
MinutesToExpire: finchgo.F(int64(0)),
Products: finchgo.F([]finchgo.ConnectSessionReauthenticateParamsProduct{finchgo.ConnectSessionReauthenticateParamsProductCompany, finchgo.ConnectSessionReauthenticateParamsProductDirectory, finchgo.ConnectSessionReauthenticateParamsProductIndividual}),
RedirectUri: finchgo.F("https://example.com"),
})
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())
}
}

0 comments on commit 77639ad

Please sign in to comment.