-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add
/forward
endpoint and other updates (#24)
- Loading branch information
1 parent
24b06e2
commit 723b3f7
Showing
14 changed files
with
1,531 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
configured_endpoints: 18 | ||
configured_endpoints: 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// File generated from our OpenAPI spec by Stainless. | ||
|
||
package finchgo | ||
|
||
import ( | ||
"github.com/Finch-API/finch-api-go/option" | ||
) | ||
|
||
// EmployerService 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 [NewEmployerService] method instead. | ||
type EmployerService struct { | ||
Options []option.RequestOption | ||
Benefits *EmployerBenefitService | ||
} | ||
|
||
// NewEmployerService 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 NewEmployerService(opts ...option.RequestOption) (r *EmployerService) { | ||
r = &EmployerService{} | ||
r.Options = opts | ||
r.Benefits = NewEmployerBenefitService(opts...) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// File generated from our OpenAPI spec by Stainless. | ||
|
||
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" | ||
) | ||
|
||
// EmployerBenefitService 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 [NewEmployerBenefitService] method | ||
// instead. | ||
type EmployerBenefitService struct { | ||
Options []option.RequestOption | ||
} | ||
|
||
// NewEmployerBenefitService 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 NewEmployerBenefitService(opts ...option.RequestOption) (r *EmployerBenefitService) { | ||
r = &EmployerBenefitService{} | ||
r.Options = opts | ||
return | ||
} | ||
|
||
// **Availability: Assisted Benefits providers only** | ||
// | ||
// Register existing benefits from the customer on the provider, on Finch's end. | ||
// Please use the `/provider` endpoint to view available types for each provider. | ||
func (r *EmployerBenefitService) Register(ctx context.Context, body EmployerBenefitRegisterParams, opts ...option.RequestOption) (res *RegisterCompanyBenefitsResponse, err error) { | ||
opts = append(r.Options[:], opts...) | ||
path := "employer/benefits/register" | ||
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) | ||
return | ||
} | ||
|
||
type RegisterCompanyBenefitsResponse struct { | ||
BenefitID string `json:"benefit_id,required"` | ||
JobID string `json:"job_id,required"` | ||
JSON registerCompanyBenefitsResponseJSON | ||
} | ||
|
||
// registerCompanyBenefitsResponseJSON contains the JSON metadata for the struct | ||
// [RegisterCompanyBenefitsResponse] | ||
type registerCompanyBenefitsResponseJSON struct { | ||
BenefitID apijson.Field | ||
JobID apijson.Field | ||
raw string | ||
ExtraFields map[string]apijson.Field | ||
} | ||
|
||
func (r *RegisterCompanyBenefitsResponse) UnmarshalJSON(data []byte) (err error) { | ||
return apijson.UnmarshalRoot(data, r) | ||
} | ||
|
||
type EmployerBenefitRegisterParams struct { | ||
Description param.Field[string] `json:"description"` | ||
Frequency param.Field[BenefitFrequency] `json:"frequency"` | ||
// Type of benefit. | ||
Type param.Field[BenefitType] `json:"type"` | ||
} | ||
|
||
func (r EmployerBenefitRegisterParams) MarshalJSON() (data []byte, err error) { | ||
return apijson.MarshalRoot(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// File generated from our OpenAPI spec by Stainless. | ||
|
||
package finchgo_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
"testing" | ||
|
||
finchgo "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 TestEmployerBenefitRegisterWithOptionalParams(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.Employer.Benefits.Register(context.TODO(), finchgo.EmployerBenefitRegisterParams{ | ||
Description: finchgo.F("string"), | ||
Frequency: finchgo.F(finchgo.BenefitFrequencyOneTime), | ||
Type: finchgo.F(finchgo.BenefitType401k), | ||
}) | ||
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// File generated from our OpenAPI spec by Stainless. | ||
|
||
package finchgo | ||
|
||
import ( | ||
"github.com/Finch-API/finch-api-go/internal/apijson" | ||
"github.com/Finch-API/finch-api-go/internal/param" | ||
) | ||
|
||
type FinchgoForwardResponse struct { | ||
// A string representation of the HTTP response body of the forwarded request’s | ||
// response received from the underlying integration’s API. This field may be null | ||
// in the case where the upstream system’s response is empty. | ||
Data string `json:"data,required,nullable"` | ||
// The HTTP headers of the forwarded request’s response, exactly as received from | ||
// the underlying integration’s API. | ||
Headers interface{} `json:"headers,required,nullable"` | ||
// An object containing details of your original forwarded request, for your ease | ||
// of reference. | ||
Request FinchgoForwardResponseRequest `json:"request,required"` | ||
// The HTTP status code of the forwarded request’s response, exactly received from | ||
// the underlying integration’s API. This value will be returned as an integer. | ||
StatusCode int64 `json:"statusCode,required"` | ||
JSON finchgoForwardResponseJSON | ||
} | ||
|
||
// finchgoForwardResponseJSON contains the JSON metadata for the struct | ||
// [FinchgoForwardResponse] | ||
type finchgoForwardResponseJSON struct { | ||
Data apijson.Field | ||
Headers apijson.Field | ||
Request apijson.Field | ||
StatusCode apijson.Field | ||
raw string | ||
ExtraFields map[string]apijson.Field | ||
} | ||
|
||
func (r *FinchgoForwardResponse) UnmarshalJSON(data []byte) (err error) { | ||
return apijson.UnmarshalRoot(data, r) | ||
} | ||
|
||
// An object containing details of your original forwarded request, for your ease | ||
// of reference. | ||
type FinchgoForwardResponseRequest struct { | ||
// The body that was specified for the forwarded request. If a value was not | ||
// specified in the original request, this value will be returned as null ; | ||
// otherwise, this value will always be returned as a string. | ||
Data string `json:"data,required,nullable"` | ||
// The specified HTTP headers that were included in the forwarded request. If no | ||
// headers were specified, this will be returned as `null`. | ||
Headers interface{} `json:"headers,required,nullable"` | ||
// The HTTP method that was specified for the forwarded request. Valid values | ||
// include: `GET` , `POST` , `PUT` , `DELETE` , and `PATCH`. | ||
Method string `json:"method,required"` | ||
// The query parameters that were included in the forwarded request. If no query | ||
// parameters were specified, this will be returned as `null`. | ||
Params interface{} `json:"params,required,nullable"` | ||
// The URL route path that was specified for the forwarded request. | ||
Route string `json:"route,required"` | ||
JSON finchgoForwardResponseRequestJSON | ||
} | ||
|
||
// finchgoForwardResponseRequestJSON contains the JSON metadata for the struct | ||
// [FinchgoForwardResponseRequest] | ||
type finchgoForwardResponseRequestJSON struct { | ||
Data apijson.Field | ||
Headers apijson.Field | ||
Method apijson.Field | ||
Params apijson.Field | ||
Route apijson.Field | ||
raw string | ||
ExtraFields map[string]apijson.Field | ||
} | ||
|
||
func (r *FinchgoForwardResponseRequest) UnmarshalJSON(data []byte) (err error) { | ||
return apijson.UnmarshalRoot(data, r) | ||
} | ||
|
||
type FinchgoForwardParams struct { | ||
// The HTTP method for the forwarded request. Valid values include: `GET` , `POST` | ||
// , `PUT` , `DELETE` , and `PATCH`. | ||
Method param.Field[string] `json:"method,required"` | ||
// The URL route path for the forwarded request. This value must begin with a | ||
// forward-slash ( / ) and may only contain alphanumeric characters, hyphens, and | ||
// underscores. | ||
Route param.Field[string] `json:"route,required"` | ||
// The body for the forwarded request. This value must be specified as either a | ||
// string or a valid JSON object. | ||
Data param.Field[string] `json:"data"` | ||
// The HTTP headers to include on the forwarded request. This value must be | ||
// specified as an object of key-value pairs. Example: | ||
// `{"Content-Type": "application/xml", "X-API-Version": "v1" }` | ||
Headers param.Field[interface{}] `json:"headers"` | ||
// The query parameters for the forwarded request. This value must be specified as | ||
// a valid JSON object rather than a query string. | ||
Params param.Field[interface{}] `json:"params"` | ||
} | ||
|
||
func (r FinchgoForwardParams) MarshalJSON() (data []byte, err error) { | ||
return apijson.MarshalRoot(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// File generated from our OpenAPI spec by Stainless. | ||
|
||
package finchgo_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
"testing" | ||
|
||
finchgo "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 TestFinchgoForwardWithOptionalParams(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.Forward(context.TODO(), finchgo.FinchgoForwardParams{ | ||
Method: finchgo.F("string"), | ||
Route: finchgo.F("string"), | ||
Data: finchgo.F("string"), | ||
Headers: finchgo.F[any](map[string]interface{}{}), | ||
Params: finchgo.F[any](map[string]interface{}{}), | ||
}) | ||
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.