Module googleapis.drive.listener
![](https://bcentral-packageicons.azureedge.net/images/ballerinax_googleapis.drive_2.1.0.png)
ballerinax/googleapis.drive.listener Ballerina library
Overview
This module generates a notification when the following events occur in the drive.
- Creation of a new file
- The creation of a new file in a specific folder
- Creation of a new folder
- Creation of a new folder in a specific folder
- File update
- File deletion
- File deletion in a specific folder
- Folder deletion
- Folder deletion in a specific folder
This module supports Google Drive API v3.
Before using this connector in your Ballerina application, complete the following:
Prerequisites
- Domain used in the callback URL needs to be registered in google console as a verified domain. If you are running locally, provide your ngrok url for domain verification. Then you are able to download a HTML file (e.g : google2c627a893434d90e.html). Copy the content of that HTML file and provide it as a configuration (i.e., via the domainVerificationFileContent parameter) to listener initialization.
If you fail to verify or set up, see documentation for domain verification process.
- Obtain tokens - Follow this link
Quickstart
To use the Google Calendar connector in your Ballerina application, update the .bal file as follows:
Step 1: Import listener
Import the Google Drive Listener module to your Ballerina program as follows.
import ballerinax/googleapis.drive; import ballerinax/googleapis.drive.'listener as listen;
Step 2: Create a new listener instance
Initialize the Google Drive configuration as follows.
drive:ConnectionConfig clientConfig = { auth: { clientId: clientId, clientSecret: clientSecret, refreshUrl: refreshUrl, refreshToken: refreshToken } }; listen:ListenerConfiguration listenerConfig = { port: 9090, callbackURL: callbackURL, domainVerificationFileContent : domainVerificationFileContent, clientConfiguration: clientConfig }; listener listen:DriveEventListener gDrivelistener = new (configuration);
Step 3: Define Ballerina service with the listener
Start the listener as a service.
service / on gDrivelistener { isolated remote function onFileCreate(Change changeInfo) returns error? { log:printInfo("Trigger > onFileCreate > changeInfo : ", changeInfo); } }
You can find a list of samples here
NOTE: If an error occurs at function implementation, the HTTP client returns the Status 500 error. If no error occurs and the user logic is successfully executed, there HTTP client returns status 200 OK.
If the user logic in listener remote operations includes heavy processing, you may face HTTP timeout issues. To overcome this, you should use asynchronous processing when the operation includes heavy processing.
listener listen:Listener gDrivelistener = new (configuration); service / on gDrivelistener { remote function onFileCreate(listen:Change event) returns error? { _ = @strand { thread: "any" } start userLogic(event); } } function userLogic(listen:Change event) returns error? { // Write your logic here }