Skip to content
Open
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
7 changes: 7 additions & 0 deletions connector/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ var connectorConstructors = map[providers.Provider]outputConstructorFunc{ // nol
providers.Granola: wrapper(newGranolaConnector),
providers.Groove: wrapper(newGrooveConnector),
providers.Gusto: wrapper(newGustoConnector),
providers.GustoDemo: wrapper(newGustoDemoConnector),
providers.HappyFox: wrapper(newHappyFoxConnector),
providers.HelpScoutMailbox: wrapper(newHelpScoutMailboxConnector),
providers.HeyReach: wrapper(newHeyReachConnector),
Expand Down Expand Up @@ -824,6 +825,12 @@ func newGustoConnector(
return gusto.NewConnector(params)
}

func newGustoDemoConnector(
params common.ConnectorParams,
) (*gusto.Connector, error) {
return gusto.NewDemoConnector(params)
}

func newPinterestConnector(
params common.ConnectorParams,
) (*pinterest.Connector, error) {
Expand Down
48 changes: 39 additions & 9 deletions providers/gusto/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,61 @@ package gusto
import (
"github.com/amp-labs/connectors/common"
"github.com/amp-labs/connectors/internal/components"
"github.com/amp-labs/connectors/internal/components/operations"
"github.com/amp-labs/connectors/internal/components/reader"
"github.com/amp-labs/connectors/internal/components/schema"
"github.com/amp-labs/connectors/providers"
"github.com/amp-labs/connectors/providers/gusto/metadata"
)

// metadataKeyCompanyID is the key under ConnectorParams.Metadata that must
// contain the Gusto company UUID the installation is scoped to.
const metadataKeyCompanyID = "companyId"

// Connector is the Gusto connector.
type Connector struct {
*components.Connector
common.RequireAuthenticatedClient

components.SchemaProvider
components.Reader

companyID string
}

// NewConnector creates a new Gusto connector.
// NewConnector creates a new Gusto connector for the production environment.
func NewConnector(params common.ConnectorParams) (*Connector, error) {
return components.Initialize(providers.Gusto, params, constructor)
return components.Initialize(providers.Gusto, params, constructor(params))
}

func constructor(base *components.Connector) (*Connector, error) {
connector := &Connector{Connector: base}
// NewDemoConnector creates a new Gusto connector for the sandbox/demo environment.
func NewDemoConnector(params common.ConnectorParams) (*Connector, error) {
return components.Initialize(providers.GustoDemo, params, constructor(params))
}

func constructor(params common.ConnectorParams) func(*components.Connector) (*Connector, error) {
return func(base *components.Connector) (*Connector, error) {
connector := &Connector{
Connector: base,
companyID: params.Metadata[metadataKeyCompanyID],
}

connector.SchemaProvider = schema.NewOpenAPISchemaProvider(
connector.ProviderContext.Module(),
metadata.Schemas,
)

connector.SchemaProvider = schema.NewOpenAPISchemaProvider(
connector.ProviderContext.Module(),
metadata.Schemas,
)
connector.Reader = reader.NewHTTPReader(
connector.HTTPClient().Client,
components.NewEmptyEndpointRegistry(),
connector.ProviderContext.Module(),
operations.ReadHandlers{
BuildRequest: connector.buildReadRequest,
ParseResponse: connector.parseReadResponse,
ErrorHandler: common.InterpretError,
},
)

return connector, nil
return connector, nil
}
}
Loading
Loading