-
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.
- Loading branch information
Showing
4 changed files
with
457 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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 asana | ||
|
||
import ( | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
) | ||
|
||
func NewConnector() (*sdk.ConnectorPlugin, error) { | ||
return sdk.CreateConnector(&sdk.CreateConnectorArgs{ | ||
Name: "Asana", | ||
Description: "Work management platform designed to help teams organize, track, and manage their work.", | ||
Logo: "logos:asana-icon", | ||
Version: "0.0.1", | ||
Category: sdk.Apps, | ||
Authors: []string{"Wakflo <integrations@wakflo.com>"}, | ||
Triggers: []sdk.ITrigger{}, | ||
Operations: []sdk.IOperation{ | ||
NewCreateTaskOperation(), | ||
}, | ||
}) | ||
} |
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,175 @@ | ||
// 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 asana | ||
|
||
type WorkspaceNew struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Name string `json:"name"` | ||
EmailDomains []string `json:"email_domains"` | ||
IsOrganization bool `json:"is_organization"` | ||
} | ||
|
||
type WorkspaceResponse struct { | ||
Data []Workspace `json:"data"` | ||
} | ||
|
||
type ProjectResponse struct { | ||
Data []Project `json:"data"` | ||
} | ||
|
||
type Project struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Name string `json:"name"` | ||
Archived bool `json:"archived"` | ||
Color string `json:"color"` | ||
CreatedAt string `json:"created_at"` | ||
CurrentStatus *CurrentStatus `json:"current_status"` | ||
CurrentStatusUpdate *CurrentStatusUpdate `json:"current_status_update"` | ||
CustomFieldSettings []CustomFieldSetting `json:"custom_field_settings"` | ||
DefaultView string `json:"default_view"` | ||
DueDate string `json:"due_date"` | ||
DueOn string `json:"due_on"` | ||
HTMLNotes string `json:"html_notes"` | ||
Members []User `json:"members"` | ||
ModifiedAt string `json:"modified_at"` | ||
Notes string `json:"notes"` | ||
PrivacySetting string `json:"privacy_setting"` | ||
StartOn string `json:"start_on"` | ||
DefaultAccessLevel string `json:"default_access_level"` | ||
MinimumAccessLevelForCustomization string `json:"minimum_access_level_for_customization"` | ||
MinimumAccessLevelForSharing string `json:"minimum_access_level_for_sharing"` | ||
CustomFields []CustomField `json:"custom_fields"` | ||
Completed bool `json:"completed"` | ||
CompletedAt string `json:"completed_at"` | ||
CompletedBy *User `json:"completed_by"` | ||
Followers []User `json:"followers"` | ||
Owner *User `json:"owner"` | ||
Team *Team `json:"team"` | ||
Icon string `json:"icon"` | ||
PermalinkURL string `json:"permalink_url"` | ||
ProjectBrief *ProjectBrief `json:"project_brief"` | ||
CreatedFromTemplate *Template `json:"created_from_template"` | ||
Workspace *Workspace `json:"workspace"` | ||
} | ||
|
||
type CurrentStatus struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Title string `json:"title"` | ||
Text string `json:"text"` | ||
HTMLText string `json:"html_text"` | ||
Color string `json:"color"` | ||
Author *User `json:"author"` | ||
CreatedAt string `json:"created_at"` | ||
CreatedBy *User `json:"created_by"` | ||
ModifiedAt string `json:"modified_at"` | ||
} | ||
|
||
type CurrentStatusUpdate struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Title string `json:"title"` | ||
ResourceSubtype string `json:"resource_subtype"` | ||
} | ||
|
||
type CustomFieldSetting struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Project *Project `json:"project"` | ||
IsImportant bool `json:"is_important"` | ||
Parent *Project `json:"parent"` | ||
CustomField *CustomField `json:"custom_field"` | ||
} | ||
|
||
type CustomField struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Name string `json:"name"` | ||
ResourceSubtype string `json:"resource_subtype"` | ||
Type string `json:"type"` | ||
EnumOptions []EnumOption `json:"enum_options"` | ||
Enabled bool `json:"enabled"` | ||
RepresentationType string `json:"representation_type"` | ||
IDPrefix string `json:"id_prefix"` | ||
IsFormulaField bool `json:"is_formula_field"` | ||
DateValue *DateValue `json:"date_value"` | ||
EnumValue *EnumOption `json:"enum_value"` | ||
MultiEnumValues []EnumOption `json:"multi_enum_values"` | ||
NumberValue float64 `json:"number_value"` | ||
TextValue string `json:"text_value"` | ||
DisplayValue string `json:"display_value"` | ||
Description string `json:"description,omitempty"` | ||
Precision int `json:"precision,omitempty"` | ||
Format string `json:"format,omitempty"` | ||
CurrencyCode string `json:"currency_code,omitempty"` | ||
CustomLabel string `json:"custom_label,omitempty"` | ||
CustomLabelPosition string `json:"custom_label_position,omitempty"` | ||
IsGlobalToWorkspace bool `json:"is_global_to_workspace,omitempty"` | ||
HasNotificationsEnabled bool `json:"has_notifications_enabled,omitempty"` | ||
AsanaCreatedField string `json:"asana_created_field,omitempty"` | ||
IsValueReadOnly bool `json:"is_value_read_only,omitempty"` | ||
CreatedBy *User `json:"created_by,omitempty"` | ||
PeopleValue []User `json:"people_value,omitempty"` | ||
} | ||
|
||
type EnumOption struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Name string `json:"name"` | ||
Enabled bool `json:"enabled"` | ||
Color string `json:"color"` | ||
} | ||
|
||
type DateValue struct { | ||
Date string `json:"date"` | ||
DateTime string `json:"date_time"` | ||
} | ||
|
||
type User struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type Team struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type ProjectBrief struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
} | ||
|
||
type Template struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type Workspace struct { | ||
GID string `json:"gid"` | ||
ResourceType string `json:"resource_type"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type Task struct { | ||
Name string `json:"name"` | ||
Workspace string `json:"workspace"` // Add a default workspace ID | ||
Projects []string `json:"projects"` | ||
} |
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,121 @@ | ||
// 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 asana | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/wakflo/go-sdk/autoform" | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type createTaskOperationProps struct { | ||
Name string `json:"name"` | ||
Project *string `json:"projects"` | ||
Workspace *string `json:"workspace"` | ||
} | ||
|
||
type CreateTaskOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewCreateTaskOperation() *CreateTaskOperation { | ||
return &CreateTaskOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "Create Task", | ||
Description: "Create a task", | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"name": autoform.NewShortTextField(). | ||
SetDisplayName("Task Name"). | ||
SetDescription("The task's Name."). | ||
SetRequired(true).Build(), | ||
"workspace": getWorkspacesInput(), | ||
"projects": getProjectsInput(), | ||
}, | ||
SampleOutput: map[string]interface{}{}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
RequireAuth: true, | ||
}, | ||
} | ||
} | ||
|
||
func (c *CreateTaskOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
input := sdk.InputToType[createTaskOperationProps](ctx) | ||
|
||
var projects []string | ||
if input.Project != nil { | ||
projects = append(projects, *input.Project) | ||
} | ||
|
||
taskData := map[string]interface{}{ | ||
"data": map[string]interface{}{ | ||
"name": input.Name, | ||
"workspace": input.Workspace, | ||
"projects": projects, | ||
}, | ||
} | ||
|
||
taskJSON, err := json.Marshal(taskData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
reqURL := "https://app.asana.com/api/1.0/tasks" | ||
|
||
req, err := http.NewRequest(http.MethodPost, reqURL, bytes.NewBuffer(taskJSON)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req.Header.Add("Content-Type", "application/json") | ||
req.Header.Add("Accept", "application/json") | ||
req.Header.Add("Authorization", "Bearer "+ctx.Auth.AccessToken) | ||
client := &http.Client{} | ||
res, err := client.Do(req) | ||
if err != nil { | ||
fmt.Println("Error sending request:", err) | ||
return nil, nil | ||
} | ||
defer res.Body.Close() | ||
|
||
body, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
fmt.Println("Error reading response:", err) | ||
return nil, nil | ||
} | ||
|
||
fmt.Println(string(body)) | ||
|
||
return map[string]interface{}{ | ||
"Result": "Task created Successfully", | ||
}, nil | ||
} | ||
|
||
func (c *CreateTaskOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *CreateTaskOperation) GetInfo() *sdk.OperationInfo { | ||
return c.options | ||
} |
Oops, something went wrong.