GitHub - kapilraajP/module-ballerinax-googleapis.sheets

WePython 1 Months+


git clone https://github.com/kapilraajP/module-ballerinax-googleapis.sheets

Ballerina Google Spreadsheet Endpoint

Google Sheets is an online spreadsheet that lets users create and format spreadsheets and simultaneously work with other people. The Google Spreadsheet endpoint allows you to access the Google Spreadsheet API Version v4 through Ballerina.

The following sections provide you with information on how to use the Ballerina Google Spreadsheet endpoint.

  • Compatibility
  • Getting started

Compatibility

Ballerina Language Versions Google Spreadsheet API Version
Swan Lake Preview8 V4
Prerequisites

Download the ballerina distribution.

Pull and Install

Pull the Module

You can pull the Spreadsheet client from Ballerina Central:

$ ballerina pull ballerinax/googleapis_sheets

Install from Source

Alternatively, you can install Spreadsheet client from the source using the following instructions.

Building the source

  1. Clone this repository using the following command:

    $ git clone https://github.com/ballerina-platform/module-ballerinax-googleapis.sheets
  2. Run this command from the module-ballerinax-googleapis.sheets root directory:

    $ ballerina build

Working with GSheets Endpoint actions

First, import the ballerinax/googleapis_sheets module into the Ballerina project.

import ballerinax/googleapis_sheets;

All the actions return valid response or error. If the action is a success, then the requested resource will be returned. Else error will be returned.

In order for you to use the GSheets Endpoint, first you need to create a GSheets Client endpoint.

import ballerinax/googleapis_sheets as sheets;

sheets:SpreadsheetConfiguration spreadsheetConfig = {
    oauth2Config: {
        accessToken: "<accessToken>",
        refreshConfig: {
            clientId: "<clientId>",
            clientSecret: "<clientSecret>",
            refreshUrl: "<refreshUrl>",
            refreshToken: "<refreshToken>"
        }
    }
};

sheets:Client spreadsheetClient = new (spreadsheetConfig);

Then the endpoint actions can be invoked as var response = spreadsheetClient->actionName(arguments).

Sample with default truststore

import ballerina/io;
import ballerinax/googleapis_sheets as sheets;

sheets:SpreadsheetConfiguration spreadsheetConfig = {
    oauth2Config: {
        accessToken: "<accessToken>",
        refreshConfig: {
            clientId: "<clientId>",
            clientSecret: "<clientSecret>",
            refreshUrl: "<refreshUrl>",
            refreshToken: "<refreshToken>"
        }
    }
};

sheets:Client spreadsheetClient = new (spreadsheetConfig);

public function main(string... args) {
    var response = spreadsheetClient->openSpreadsheetById(<spreadsheet-id>);
    if (response is sheets:Spreadsheet) {
        io:println("Spreadsheet Details: ", response);
    } else {
        io:println("Error: ", response);
    }
}

Sample with custom truststore

import ballerina/io;
import ballerinax/googleapis_sheets as sheets;

sheets:SpreadsheetConfiguration spreadsheetConfig = {
    oauth2Config: {
        accessToken: "<accessToken>",
        refreshConfig: {
            clientId: "<clientId>",
            clientSecret: "<clientSecret>",
            refreshUrl: "<refreshUrl>",
            refreshToken: "<refreshToken>"
        }
    },
    secureSocketConfig: {
        trustStore: {
            path: "<fullQualifiedPathToTrustStore>",
            password: "<truststorePassword>"
        }
    }
};

sheets:Client spreadsheetClient = new (spreadsheetConfig);

public function main(string... args) {
    var response = spreadsheetClient->openSpreadsheetById(<spreadsheet-id>);
    if (response is sheets:Spreadsheet) {
        io:println("Spreadsheet Details: ", response);
    } else {
        io:println("Error: ", response);
    }
}

How you can contribute

Clone the repository by running the following command git clone https://github.com/ballerina-platform/module-googlespreadsheet.git

As an open source project, we welcome contributions from the community. Check the issue tracker for open issues that interest you. We look forward to receiving your contributions.


Previous : GitHub - kapilraajP/module-ballerinax-googleapis.people-1: Repository for Google People API Connector
Next : GitHub - dp50mm/line-intersect: Line vs line, point vs line in 2D space