-
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.
Merge pull request #49 from wakflo/feature/web-710-calendly-connector
Feature/web 710 calendly connector
- Loading branch information
Showing
7 changed files
with
605 additions
and
0 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
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,36 @@ | ||
package calendly | ||
|
||
// 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. | ||
|
||
import ( | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
) | ||
|
||
func NewConnector() (*sdk.ConnectorPlugin, error) { | ||
return sdk.CreateConnector(&sdk.CreateConnectorArgs{ | ||
Name: "Calendly", | ||
Description: "All-in-one productivity platform", | ||
Logo: "simple-icons:calendly", | ||
Version: "0.0.1", | ||
Category: sdk.Apps, | ||
Authors: []string{"Wakflo <integrations@wakflo.com>"}, | ||
Triggers: []sdk.ITrigger{}, | ||
Operations: []sdk.IOperation{ | ||
NewListEventsOperation(), | ||
NewGetEventOperation(), | ||
NewCreateSingleUseScheduleLinkOperation(), | ||
}, | ||
}) | ||
} |
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,46 @@ | ||
package calendly | ||
|
||
import "time" | ||
|
||
type User struct { | ||
URI string `json:"uri"` | ||
Name string `json:"name"` | ||
Slug string `json:"slug"` | ||
Email string `json:"email"` | ||
SchedulingURL string `json:"scheduling_url"` | ||
Timezone string `json:"timezone"` | ||
CreatedAt string `json:"created_at"` | ||
UpdatedAt string `json:"updated_at"` | ||
CurrentOrganization string `json:"current_organization"` | ||
AvatarURL string `json:"avatar_url"` | ||
} | ||
type UsersResponse struct { | ||
Users []User `json:"collection"` | ||
} | ||
|
||
type CurrentUserResponse struct { | ||
Resource User `json:"resource"` | ||
} | ||
|
||
type EventsResponse struct { | ||
Events []Event `json:"collection"` | ||
} | ||
|
||
type Event struct { | ||
URI string `json:"uri"` | ||
Name string `json:"name"` | ||
StartTime time.Time `json:"start_time"` | ||
EndTime time.Time `json:"end_time"` | ||
} | ||
|
||
type EventTypesResponse struct { | ||
Collection []EventType `json:"collection"` | ||
} | ||
|
||
type EventType struct { | ||
URI string `json:"uri"` | ||
Name string `json:"name"` | ||
Slug string `json:"slug"` | ||
Description string `json:"description"` | ||
Duration int `json:"duration"` | ||
} |
76 changes: 76 additions & 0 deletions
76
internal/connectors/calendly/operation_create_single_use_schedule_link.go
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,76 @@ | ||
package calendly | ||
|
||
import ( | ||
"errors" | ||
"github.com/wakflo/go-sdk/autoform" | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type createSingleUseScheduleLinkOperationProps struct { | ||
User string `json:"user"` | ||
MaxEventCount int `json:"max_event_count"` | ||
Owner string `json:"owner"` | ||
} | ||
|
||
type CreateSingleUseScheduleLinkOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewCreateSingleUseScheduleLinkOperation() *CreateSingleUseScheduleLinkOperation { | ||
return &CreateSingleUseScheduleLinkOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "Create Single Use Schedule Link", | ||
Description: "Create a single use schedule link", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"user": getCurrentCalendlyUserInput("User", "Select a user", true), | ||
"max_event_count": autoform.NewNumberField(). | ||
SetDisplayName("Max Event Count"). | ||
SetDescription("Maximum number of events that can be scheduled using the schedule link"). | ||
SetRequired(true). | ||
Build(), | ||
"owner": getCalendlyEventTypeInput("Event Type", "Select an event type", false), | ||
}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c *CreateSingleUseScheduleLinkOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
if ctx.Auth.AccessToken == "" { | ||
return nil, errors.New("missing calendly auth token") | ||
} | ||
accessToken := ctx.Auth.AccessToken | ||
|
||
input := sdk.InputToType[createSingleUseScheduleLinkOperationProps](ctx) | ||
|
||
if input.User == "" { | ||
return nil, errors.New("user is required") | ||
} | ||
|
||
if input.MaxEventCount <= 0 { | ||
return nil, errors.New("max event count is required") | ||
} | ||
|
||
if input.Owner == "" { | ||
return nil, errors.New("owner is required") | ||
} | ||
|
||
scheduleLink, _ := createSingleUseLink(accessToken, input.Owner, input.MaxEventCount) | ||
|
||
return scheduleLink, nil | ||
|
||
} | ||
|
||
func (c *CreateSingleUseScheduleLinkOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *CreateSingleUseScheduleLinkOperation) GetInfo() *sdk.OperationInfo { | ||
return c.options | ||
} |
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,67 @@ | ||
package calendly | ||
|
||
import ( | ||
"errors" | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type getEventOperatioinProps struct { | ||
User string `json:"user"` | ||
EventID string `json:"event-id"` | ||
} | ||
|
||
type GetEventOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewGetEventOperation() *GetEventOperation { | ||
return &GetEventOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "Get Event", | ||
Description: "Get Event", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"user": getCurrentCalendlyUserInput("User", "Select a user", true), | ||
"event-id": getCalendlyEventInput("Event", "Select event", true), | ||
}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c *GetEventOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
if ctx.Auth.AccessToken == "" { | ||
return nil, errors.New("missing calendly auth token") | ||
} | ||
accessToken := ctx.Auth.AccessToken | ||
|
||
input := sdk.InputToType[getEventOperatioinProps](ctx) | ||
|
||
println("event-ud", input.EventID) | ||
println("accessToken", accessToken) | ||
|
||
if input.User == "" { | ||
return nil, errors.New("user is required") | ||
} | ||
|
||
if input.EventID == "" { | ||
return nil, errors.New("event id is required") | ||
} | ||
|
||
event, _ := getEvent(accessToken, input.EventID) | ||
|
||
return event, nil | ||
} | ||
|
||
func (c *GetEventOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *GetEventOperation) GetInfo() *sdk.OperationInfo { | ||
return c.options | ||
} |
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 @@ | ||
package calendly | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/wakflo/go-sdk/autoform" | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type listEventOperationProps struct { | ||
User string `json:"user"` | ||
Status string `json:"status"` | ||
} | ||
|
||
type ListEventsOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewListEventsOperation() *ListEventsOperation { | ||
return &ListEventsOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "List Events", | ||
Description: "List Events", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"user": getCurrentCalendlyUserInput("User", "Select a user", true), | ||
"status": autoform.NewSelectField(). | ||
SetDisplayName("Status"). | ||
SetDescription("Event Status"). | ||
SetOptions(calendlyEventStatusType). | ||
SetRequired(true). | ||
Build(), | ||
}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c *ListEventsOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
if ctx.Auth.AccessToken == "" { | ||
return nil, errors.New("missing calendly auth token") | ||
} | ||
accessToken := ctx.Auth.AccessToken | ||
|
||
input := sdk.InputToType[listEventOperationProps](ctx) | ||
|
||
if input.Status == "" { | ||
return nil, errors.New("status is required") | ||
} | ||
|
||
if input.User == "" { | ||
return nil, errors.New("user is required") | ||
} | ||
|
||
reqURL := baseURL + "/scheduled_events" | ||
events, _ := listEvents(accessToken, reqURL, input.Status, input.User) | ||
|
||
return events, nil | ||
} | ||
|
||
func (c *ListEventsOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *ListEventsOperation) GetInfo() *sdk.OperationInfo { | ||
return c.options | ||
} |
Oops, something went wrong.