Skip to content

Commit

Permalink
Add documentation for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuvindu committed Nov 16, 2023
1 parent 76ed956 commit 3c62ee6
Showing 1 changed file with 170 additions and 5 deletions.
175 changes: 170 additions & 5 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Execute the following commands to build an example from the source.

`bal build <example-name>`


* To run an example

`bal run <example-name>`
Expand All @@ -28,17 +27,38 @@ Execute the following commands to build all the examples against the changes you

`./build.sh build`


* To run all the examples

`./build.sh run`

## Scenario 01:

### Sarah's Work Schedule Management with Google Calendar API
## Scenario 01: Sarah's Work Schedule Management with Google Calendar API

Sarah relies on the Google Calendar API to efficiently manage her work schedule. Her application interacts with the API for various tasks related to scheduling and organizing work-related events and meetings.

### Step 1: Import connector
Import the `ballerinax/googleapis.calendar` module into the Ballerina project.
```ballerina
import ballerinax/googleapis.calendar;
```

### Step 2: Create a new connector instance
Create a `calendar:ConnectionConfig` with the OAuth2.0 tokens obtained and initialize the connector with it.

```ballerina
calendar:ConnectionConfig config = {
auth: {
clientId: <CLIENT_ID>,
clientSecret: <CLIENT_SECRET>
refreshToken: <REFRESH_TOKEN>,
refreshUrl: <REFRESH_URL>,
}
};
calendar:Client calendarClient = check new(config);
```

Now, the `calendar:Client` instance can be used for the following steps.

#### Creating a Work Calendar:

To keep her work events organized, Sarah's application creates a dedicated calendar. It sets the calendar's title, ensuring clarity for work-related events.
Expand Down Expand Up @@ -156,3 +176,148 @@ calendar:AclRule|error response = calendarClient->updateAclRule(<string>calendar
role: "writer"
});
```

## Scenario 02: Alex's Personal Project Management with Google Calendar API in Ballerina

Let's explore how Alex, a software developer, leverages the Google Calendar API in Ballerina for managing his personal project schedule and collaborating with team members.

### Step 1: Import Google Calendar Connector
Alex begins by importing the `ballerinax/googleapis.calendar` module into his Ballerina project.

```ballerina
import ballerinax/googleapis.calendar;
```

### Step 2: Create a Connector Instance
Next, Alex creates a `calendar:ConnectionConfig` with his OAuth2.0 tokens and initializes the connector.

```ballerina
calendar:ConnectionConfig config = {
auth: {
clientId: <CLIENT_ID>,
clientSecret: <CLIENT_SECRET>,
refreshToken: <REFRESH_TOKEN>,
refreshUrl: <REFRESH_URL>,
}
};
calendar:Client calendarClient = check new(config);
```

### Step 3: Create a Project Calendar

To keep his project events organized, Alex's application creates a dedicated calendar with a descriptive title.

```ballerina
calendar:Calendar projectCalendar = check calendarClient->createCalendar({
summary: "Software Project - Alex"
});
```

### Step 4: Schedule Project Tasks

Alex schedules various project-related tasks using the Google Calendar API. This includes coding sessions, design reviews, and testing phases.

```ballerina
calendar:Event codingSession = check calendarClient->createEvent(<string>projectCalendar.id, {
'start: {
dateTime: "2023-10-20T10:00:00+00:00",
timeZone: "UTC"
},
end: {
dateTime: "2023-10-20T12:00:00+00:00",
timeZone: "UTC"
},
summary: "Code Review"
});
calendar:Event designReview = check calendarClient->createEvent(<string>projectCalendar.id, {
'start: {
dateTime: "2023-10-25T14:00:00+00:00",
timeZone: "UTC"
},
end: {
dateTime: "2023-10-25T16:00:00+00:00",
timeZone: "UTC"
},
summary: "Design Review"
});
// More tasks scheduled...
```

### Step 5: Collaborate with Team

Alex invites team members to project events by utilizing the Google Calendar API. This ensures that everyone involved is aware of and aligned on project milestones.

```ballerina
calendar:Event updatedCodingSession = check calendarClient->updateEvent(<string>projectCalendar.id, <string>codingSession.id, {
'start: {
dateTime: "2023-10-20T10:00:00+00:00",
timeZone: "UTC"
},
end: {
dateTime: "2023-10-20T12:00:00+00:00",
timeZone: "UTC"
},
summary: "Code Review - Team A",
attendees: [
{
"email": "team-member1@gmail.com"
},
{
"email": "team-member2@gmail.com"
}
]
});
// Similar updates for other events...
```

### Step 6: Set Project Milestone Reminders

To stay on top of project deadlines, Alex sets reminders for important milestones using the Google Calendar API.

```ballerina
calendar:Event milestoneEvent = check calendarClient->createEvent(<string>projectCalendar.id, {
'start: {
dateTime: "2023-11-15T09:00:00+00:00",
timeZone: "UTC"
},
end: {
dateTime: "2023-11-15T17:00:00+00:00",
timeZone: "UTC"
},
summary: "Project Beta Release"
reminders: {
useDefault: false,
overrides: [
{
method: "popup",
minutes: 60
},
{
method: "email",
minutes: 1440
}
]
}
});
```

### Step 7: Monitor Project Progress

Alex regularly retrieves and analyzes project events using the Google Calendar API to monitor progress and make data-driven decisions.

```ballerina
calendar:Events projectEvents = check calendarClient->getEvents(<string>projectCalendar.id, {
'timeMin': "2023-10-01T00:00:00Z",
'timeMax': "2023-12-31T23:59:59Z",
'orderBy': "startTime",
'singleEvents': true
});
// Analyze project events for progress monitoring...
```

This scenario illustrates how Alex, a software developer, utilizes the Google Calendar API in Ballerina for effective personal project management and collaboration with his team.

0 comments on commit 3c62ee6

Please sign in to comment.