Skip to content

Commit

Permalink
Address more review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
NipunaRanasinghe committed Apr 6, 2024
1 parent b2a2b59 commit 660780f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 55 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Now, utilize the available connector operations.
#### Get all projects for the authenticated user

```ballerina
Inline_response_200_19 asanaProjects = check asana->/projects();
record {asana:ProjectCompact[] data?;} projects = check asana->/projects();
```

#### Create a new task in a project
Expand All @@ -88,7 +88,7 @@ asana:Tasks_body taskReq = {
}
};
var createdTask = check asana->/tasks.post(taskReq);
record {asana:TaskResponse data?;} taskCreated = check asana->/tasks.post(taskReq);
```

## Examples
Expand Down
4 changes: 2 additions & 2 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Now, utilize the available connector operations.
#### Get all projects for the authenticated user

```ballerina
Inline_response_200_19 asanaProjects = check asana->/projects();
record {asana:ProjectCompact[] data?;} projects = check asana->/projects();
```

#### Create a new task in a project
Expand All @@ -80,7 +80,7 @@ asana:Tasks_body taskReq = {
}
};
var createdTask = check asana->/tasks.post(taskReq);
record {asana:TaskResponse data?;} taskCreated = check asana->/tasks.post(taskReq);
```

## Examples
Expand Down
4 changes: 2 additions & 2 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Now, utilize the available connector operations.
#### Get all projects for the authenticated user

```ballerina
var asanaProjects = check asana->/projects();
record {asana:ProjectCompact[] data?;} projects = check asana->/projects();
```

#### Create a new task in a project
Expand All @@ -80,7 +80,7 @@ asana:Tasks_body taskReq = {
}
};
var createdTask = check asana->/tasks.post(taskReq);
record {asana:TaskResponse data?;} taskCreated = check asana->/tasks.post(taskReq);
```

## Examples
Expand Down
57 changes: 8 additions & 49 deletions examples/employee-onboarding-process-automation/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerinax/asana;

configurable string authToken = ?;
Expand All @@ -32,55 +31,15 @@ asana:Client asana = check new (asanaConfig);
// Function to automate the creation of an employee onboarding project with tasks
public function main() returns error? {

// Step 1: Create a new onboarding project
asana:Projects_body projectBody = {
record {asana:ProjectCompact[] data?;} projects = check asana->/projects();

asana:Tasks_body taskReq = {
data: {
name: "Onboarding - " + newEmployeeName,
workspace: workspaceId,
team: teamId
name: "Email Marketing Campaign",
notes: "Create a new email marketing campaign for the upcoming product launch.",
workspace: "<workspaceId>",
projects: ["<projectId>"]
}
};

asana:Inline_response_201_5|error projectResponse = asana->/projects.post(projectBody);
if projectResponse is error {
return error("error creating project: " + projectResponse.message());
}

string? projectId = projectResponse?.data?.gid;
if projectId is () {
return error("project ID not found in response");
}

// Step 2: Add sections to the new project
string[] sections = ["Documentation", "Training", "Setup"];
foreach string sectionName in sections {
asana:Project_gid_sections_body sectionBody = {
data: {
name: sectionName
}
};

asana:Inline_response_200_30|error sectionCreationResult = asana->/projects/[projectId]/sections.post(sectionBody);
if sectionCreationResult is error {
return error("error creating section: " + sectionCreationResult.message());
}
}

// Step 3: Create tasks within each section (simplified for brevity)
// In a complete implementation, you'd likely query the sections of the project first to get their IDs.
string[] tasks = ["Complete HR paperwork", "Setup work email", "Attend orientation session"];
foreach string taskName in tasks {
asana:Tasks_body newTaskPayload = {
data: {
name: taskName,
projects: [projectId],
assignee_section: "<section_id>"
}
};

asana:Inline_response_201_7|error taskCreationResponse = asana->/tasks.post(newTaskPayload);
if taskCreationResponse is error {
return error("error creating task: " + taskCreationResponse.message());
}
}
record {asana:TaskResponse data?;} taskCreated = check asana->/tasks.post(taskReq);
}

0 comments on commit 660780f

Please sign in to comment.