Skip to content

Commit

Permalink
feat: implement cin7 connector
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymesC committed Jul 12, 2024
1 parent 30b3a07 commit 80912db
Show file tree
Hide file tree
Showing 10 changed files with 703 additions and 0 deletions.
2 changes: 2 additions & 0 deletions connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package extensions

import (
"github.com/wakflo/extensions/internal/connectors/calculator"
"github.com/wakflo/extensions/internal/connectors/cin7"
"github.com/wakflo/extensions/internal/connectors/cryptography"
"github.com/wakflo/extensions/internal/connectors/delay"
googledocs "github.com/wakflo/extensions/internal/connectors/google_docs"
Expand Down Expand Up @@ -57,6 +58,7 @@ func RegisterConnectors() []*sdk.ConnectorPlugin {
calculator.NewConnector, // Calculator
shopify.NewConnector, // Shopify
webhook.NewConnector, // Webhook
cin7.NewConnector, // Cin7
}

// 🛑Do-Not-Edit
Expand Down
40 changes: 40 additions & 0 deletions internal/connectors/cin7/lib.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cin7

import (
sdk "github.com/wakflo/go-sdk/connector"
)

func NewConnector() (*sdk.ConnectorPlugin, error) {
return sdk.CreateConnector(&sdk.CreateConnectorArgs{
Name: "Cin7",
Description: "interacts with the cin7 api",
Logo: "twemoji:passenger-ship",
Version: "0.0.1",
Category: sdk.Apps,
Authors: []string{"Wakflo <integrations@wakflo.com>"},
Triggers: []sdk.ITrigger{
NewTriggerNewSales(),
},
Operations: []sdk.IOperation{
NewGetProductsOperation(),
NewGetCustomersOperation(),
NewGetSalesOrderOperation(),
NewGetSalesListOperation(),
NewGetPurchaseInvoiceOperation(),
},
})
}
81 changes: 81 additions & 0 deletions internal/connectors/cin7/operation_get_a_payment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cin7

import (
"log"

"github.com/wakflo/go-sdk/autoform"
sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type getPaymentOperationProps struct {
PaymentID string `json:"id"`
}

type GetPaymentOperation struct {
options *sdk.OperationInfo
}

func NewGetPaymentOperation() *GetPaymentOperation {
return &GetPaymentOperation{
options: &sdk.OperationInfo{
Name: "Get a payment",
Description: "Get payment information",
RequireAuth: true,
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"id": autoform.NewShortTextField().
SetDisplayName("Payment ID").
SetDescription("The paymentId of the payment").
SetRequired(true).
Build(),
},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
},
}
}

func (c *GetPaymentOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
input := sdk.InputToType[getPaymentOperationProps](ctx)

endpoint := "/ExternalApi/"
accountID := ctx.Auth.Extra["account_id"]
applicationKey := ctx.Auth.Extra["key"]
queryParams := map[string]interface{}{
"ID": input.PaymentID,
}

response, err := fetchData(endpoint, accountID, applicationKey, queryParams)
if err != nil {
log.Fatalf("Error fetching data: %v", err)
}

return sdk.JSON(map[string]interface{}{
"data": response,
}), nil
}

func (c *GetPaymentOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *GetPaymentOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
83 changes: 83 additions & 0 deletions internal/connectors/cin7/operation_get_customers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cin7

import (
"log"

"github.com/wakflo/go-sdk/autoform"

sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type getCustomerOperationProps struct {
PageLimit int `json:"page-limit"`
}

type GetCustomersOperation struct {
options *sdk.OperationInfo
}

func NewGetCustomersOperation() *GetCustomersOperation {
return &GetCustomersOperation{
options: &sdk.OperationInfo{
Name: "Get Customers",
Description: "Retrieves a list of customers from Cin7",
RequireAuth: true,
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"page-limit": autoform.NewNumberField().
SetDisplayName("Product limit").
SetDescription(" Specifies the page limit for getting products.").
SetDefaultValue(100).
Build(),
},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
},
}
}

func (c *GetCustomersOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
input := sdk.InputToType[getProductsOperationProps](ctx)

endpoint := "/ExternalApi/Customers"
accountID := ctx.Auth.Extra["account_id"]
applicationKey := ctx.Auth.Extra["key"]
queryParams := map[string]interface{}{
"Page": "1",
"Limit": input.PageLimit,
}

response, err := fetchData(endpoint, accountID, applicationKey, queryParams)
if err != nil {
log.Fatalf("Error fetching data: %v", err)
}

return sdk.JSON(map[string]interface{}{
"customers": response,
}), nil
}

func (c *GetCustomersOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *GetCustomersOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
81 changes: 81 additions & 0 deletions internal/connectors/cin7/operation_get_products.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cin7

import (
"log"

"github.com/wakflo/go-sdk/autoform"
sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type getProductsOperationProps struct {
PageLimit int `json:"page-limit"`
}

type GetProductsOperation struct {
options *sdk.OperationInfo
}

func NewGetProductsOperation() *GetProductsOperation {
return &GetProductsOperation{
options: &sdk.OperationInfo{
Name: "Get Products",
Description: "Retrieves a list of products from Cin7",
RequireAuth: true,
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"page-limit": autoform.NewNumberField().
SetDisplayName("Product limit").
SetDescription(" Specifies the page limit for getting products.").
SetDefaultValue(100).
Build(),
},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
},
}
}

func (c *GetProductsOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
input := sdk.InputToType[getProductsOperationProps](ctx)

endpoint := "/ExternalApi/Products"
accountID := ctx.Auth.Extra["account_id"]
applicationKey := ctx.Auth.Extra["key"]
queryParams := map[string]interface{}{
"Limit": input.PageLimit,
}

response, err := fetchData(endpoint, accountID, applicationKey, queryParams)
if err != nil {
log.Fatalf("Error fetching data: %v", err)
}

return sdk.JSON(map[string]interface{}{
"products": response,
}), nil
}

func (c *GetProductsOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *GetProductsOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
82 changes: 82 additions & 0 deletions internal/connectors/cin7/operation_get_purchase_invoice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cin7

import (
"log"

"github.com/wakflo/go-sdk/autoform"
sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type getPurchaseInvoiceOperationProps struct {
TaskID string `json:"id"`
}

type GetPurchaseInvoiceOperation struct {
options *sdk.OperationInfo
}

func NewGetPurchaseInvoiceOperation() *GetPurchaseInvoiceOperation {
return &GetPurchaseInvoiceOperation{
options: &sdk.OperationInfo{
Name: "Get Purchase Invoice",
Description: "Retrieves the purchase invoice",
RequireAuth: true,
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"id": autoform.NewShortTextField().
SetDisplayName("Task ID").
SetDescription("The ID of Task").
SetRequired(true).
Build(),
},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
},
}
}

func (c *GetPurchaseInvoiceOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
input := sdk.InputToType[getPurchaseInvoiceOperationProps](ctx)

endpoint := "/ExternalApi/v2/purchase/invoice"
accountID := ctx.Auth.Extra["account_id"]
applicationKey := ctx.Auth.Extra["key"]
queryParams := map[string]interface{}{
"TaskID": input.TaskID,
"CombineAdditionalCharges": true,
}

response, err := fetchData(endpoint, accountID, applicationKey, queryParams)
if err != nil {
log.Fatalf("Error fetching data: %v", err)
}

return sdk.JSON(map[string]interface{}{
"data": response,
}), nil
}

func (c *GetPurchaseInvoiceOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *GetPurchaseInvoiceOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
Loading

0 comments on commit 80912db

Please sign in to comment.