Skip to content

Commit

Permalink
Add examples to the package
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuvindu committed Nov 2, 2023
1 parent e2ec5e6 commit d39b40d
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions examples/work_schedule_management.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you 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 ballerina/log;
import ballerina/os;
import ballerinax/googleapis.calendar;

configurable string clientId = os:getEnv("CLIENT_ID");
configurable string clientSecret = os:getEnv("CLIENT_SECRET");
configurable string refreshToken = os:getEnv("REFRESH_TOKEN");
configurable string refreshUrl = os:getEnv("REFRESH_URL");

public function main() returns error? {
calendar:Client calendarClient = check new ({
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: refreshUrl
}
});

// create new calendar
calendar:Calendar calendarResult = check calendarClient->createCalendar({
summary: "Work Schedule"
});

// create new event
calendar:Event event = check calendarClient->createEvent(<string>calendarResult.id, {
'start: {
dateTime: "2023-10-19T09:00:00+05:30",
timeZone: "Asia/Colombo"
},
end: {
dateTime: "2023-10-19T09:30:00+05:30",
timeZone: "Asia/Colombo"
},
summary: "Project Kickoff Meeting"
});

// update event to invite attendees by email
calendar:Event updatedEvent = check calendarClient->updateEvent(<string>calendarResult.id, <string>event.id, {
'start: {
dateTime: "2023-10-19T09:00:00+05:30",
timeZone: "Asia/Colombo"
},
end: {
dateTime: "2023-10-19T09:30:00+05:30",
timeZone: "Asia/Colombo"
},
summary: "Team Meeting",
location: "Conference Room",
description: "Weekly team meeting to discuss project status.",
attendees: [
{
"email": "team-member1@gmail.com"
},
{
"email": "team-member2@gmail.com"
}
]
});

// update event to add reminders to send timely notifications to attendees before the meeting
calendar:Event|error reminderEvent = calendarClient->updateEvent(<string>calendarResult.id, <string>updatedEvent.id, {
'start: {
dateTime: "2023-10-19T03:00:00+05:30",
timeZone: "Asia/Colombo"
},
end: {
dateTime: "2023-10-19T03:30:00+05:30",
timeZone: "Asia/Colombo"
},
reminders: {
useDefault: false,
overrides: [
{method: "popup", minutes: 15},
{method: "email", minutes: 30}
]
}
});

if reminderEvent is error {
log:printError(reminderEvent.message());
}

// create access control rule and assign it to a team member
calendar:AclRule acl = check calendarClient->createAclRule(<string>calendarResult.id, {
scope: {
'type: "user",
value: "team_member@gmail.com"
},
role: "reader"
});

// change access control rule
calendar:AclRule|error response = calendarClient->updateAclRule(<string>calendarResult.id, <string>acl.id, {
scope: {
'type: "user",
value: "team_member@gmail.com"
},
role: "writer"
});
if response is error {
log:printError(response.message());
}
}

0 comments on commit d39b40d

Please sign in to comment.