Skip to content

Commit

Permalink
feat: implement get location operation
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymesC committed Jun 21, 2024
1 parent e8278fb commit 8f0ea01
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/connectors/shopify/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewConnector() (*sdk.ConnectorPlugin, error) {
Triggers: []sdk.ITrigger{},
Operations: []sdk.IOperation{
NewGetProductVariantOperation(),
NewGetLocationsOperation(),
NewCreateProductOperation(),
NewGetCustomerOperation(),
NewGetProductOperation(),
Expand Down
91 changes: 91 additions & 0 deletions internal/connectors/shopify/operation_get_locations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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 shopify

import (
"context"
"errors"
// "fmt"

// "strings"

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

type GetLocationsOperation struct {
options *sdk.OperationInfo
}

func NewGetLocationsOperation() *GetLocationsOperation {
return &GetLocationsOperation{
options: &sdk.OperationInfo{
Name: "Get Locations",
Description: "get locations",
RequireAuth: true,
Auth: sharedAuth,
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
},
}
}

func (c *GetLocationsOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {

if ctx.Auth.Extra["token"] == "" {
return nil, errors.New("missing shopify auth token")
}

domain := ctx.Auth.Extra["domain"]
shopName := domain + ".myshopify.com"

client := getShopifyClient(shopName, ctx.Auth.Extra["token"])

locations, err := client.Location.List(context.Background(),nil)
if err != nil {
return nil, err
}

simplifiedLocations := make([]map[string]interface{}, len(locations))

for i, location := range locations {
simplifiedLocations[i] = map[string]interface{}{
"Id": location.Id,
"Name": location.Name,
"Address1": location.Address1,
"Address2": location.Address2,
"City": location.City,
"Zip": location.Zip,
"Country": location.Country,
"Phone": location.Phone,
"Active": location.Active,
}
}

return map[string]interface{}{
"locations": simplifiedLocations,
}, nil
}

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

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

0 comments on commit 8f0ea01

Please sign in to comment.