diff --git a/ballerina/client.bal b/ballerina/client.bal index 37f9b3f..ea8e3c8 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -24,7 +24,6 @@ import ballerinax/'client.config; @display {label: "Google Sheets", iconPath: "icon.png"} public isolated client class Client { final http:Client httpClient; - final http:Client driveClient; # Gets invoked to initialize the `connector`. # @@ -33,7 +32,6 @@ public isolated client class Client { public isolated function init(ConnectionConfig config) returns error? { http:ClientConfiguration httpClientConfig = check config:constructHTTPClientConfig(config); self.httpClient = check new (BASE_URL, httpClientConfig); - self.driveClient = check new (DRIVE_URL, httpClientConfig); } // Spreadsheet Management Operations @@ -73,15 +71,6 @@ public isolated client class Client { return self->openSpreadsheetById(spreadsheetId); } - # Get all spreadsheet files. - # - # + return - Stream of `sheets:File` records on success, or else an error - @display {label: "Get All Spreadsheets"} - remote isolated function getAllSpreadsheets() returns @display {label: "Stream of Files"} stream|error { - SpreadsheetStream spreadsheetStream = check new SpreadsheetStream(self.driveClient); - return new stream(spreadsheetStream); - } - # Renames the spreadsheet with the given name. # # + spreadsheetId - ID of the spreadsheet diff --git a/ballerina/constants.bal b/ballerina/constants.bal index d66136a..97ce219 100644 --- a/ballerina/constants.bal +++ b/ballerina/constants.bal @@ -49,18 +49,6 @@ const string URL_START = "https://docs.google.com/spreadsheets/d/"; const string URL_END = "/edit"; const int ID_START_INDEX = 39; -//Drive -const string DRIVE_URL = "https://www.googleapis.com"; -const string DRIVE_PATH = "/drive/v3"; -const string FILES = "/files"; -const string Q = "q"; -const string MIME_TYPE = "mimeType"; -const string APPLICATION = "'application/vnd.google-apps.spreadsheet'"; -const string AND = "&"; -const string AND_SIGN = "and"; -const string TRASH_FALSE ="trashed=false"; -const string PAGE_TOKEN = "pageToken"; - // Error const string ERR_FILE_RESPONSE = "Error occurred while constructing FileResponse record."; diff --git a/ballerina/data_mappings.bal b/ballerina/data_mappings.bal index 29ddff2..b78a657 100644 --- a/ballerina/data_mappings.bal +++ b/ballerina/data_mappings.bal @@ -150,8 +150,3 @@ isolated function convertToArray(json jsonResponse) returns (string|int|decimal) } return values; } - -isolated function convertToFiles(json payload) returns File[]|error { - FilesResponse res = check payload.cloneWithType(FilesResponse); - return res.files; -} diff --git a/ballerina/stream_implementer.bal b/ballerina/stream_implementer.bal deleted file mode 100644 index 0256b9e..0000000 --- a/ballerina/stream_implementer.bal +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. 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/http; - -class SpreadsheetStream { - private final http:Client httpClient; - private string? pageToken; - private File[] currentEntries = []; - int index = 0; - - isolated function init(http:Client httpClient) returns error? { - self.httpClient = httpClient; - self.pageToken = EMPTY_STRING; - self.currentEntries = check self.fetchFiles(); - } - - public isolated function next() returns record {|File value;|}|error? { - if self.index < self.currentEntries.length() { - record {|File value;|} file = {value: self.currentEntries[self.index]}; - self.index += 1; - return file; - } - if self.pageToken is string { - self.index = 0; - self.currentEntries = check self.fetchFiles(); - record {|File value;|} file = {value: self.currentEntries[self.index]}; - self.index += 1; - return file; - } - return; - } - - isolated function fetchFiles() returns File[]|error { - string drivePath = prepareDriveUrl(self.pageToken); - json response = check sendRequest(self.httpClient, drivePath); - FilesResponse|error filesResponse = response.cloneWithType(FilesResponse); - if filesResponse is FilesResponse { - self.pageToken = filesResponse?.nextPageToken; - return filesResponse.files; - } else { - return error(ERR_FILE_RESPONSE, filesResponse); - } - } -} diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 9075cab..d629654 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -103,26 +103,9 @@ function testRenameSpreadsheet() { } } -@test:Config { - dependsOn: [testRenameSpreadsheet] -} -function testGetAllSpreadSheets() { - stream|error response = spreadsheetClient->getAllSpreadsheets(); - if response is stream { - record {|File value;|}|error? fileResponse = response.next(); - if fileResponse is record {|File value;|} { - test:assertNotEquals(fileResponse.value["id"], "", msg = "Found 0 records"); - } else if fileResponse is error { - test:assertFail(fileResponse.message()); - } - } else { - test:assertFail(response.message()); - } -} - // Sheet management operations tests @test:Config { - dependsOn: [testGetAllSpreadSheets] + dependsOn: [testRenameSpreadsheet] } function testAddSheet() { Sheet|error spreadsheetRes = spreadsheetClient->addSheet(spreadsheetId, testSheetName); diff --git a/ballerina/types.bal b/ballerina/types.bal index 97fdfc0..ba7745e 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -213,50 +213,6 @@ public type Cell record { (int|string|decimal) value; }; -# Response from File search -# -# + kind - Identifies what kind of resource is this. Value: the fixed string "drive#fileList". -# + nextPageToken - The page token for the next page of files. -# This will be absent if the end of the files list has been reached. -# If the token is rejected for any reason, it should be discarded, -# and pagination should be restarted from the first page of results. -# + files - The list of files. -# If nextPageToken is populated, -# then this list may be incomplete and an additional page of results should be fetched. -# + incompleteSearch - Whether the search process was incomplete. If true, then some search results may be missing, -# Since all documents were not searched. This may occur when searching multiple drives with the -# "allDrives" corpora, but all corpora could not be searched. When this happens, it is suggested -# that clients narrow their query by choosing a different corpus such as "user" or "drive". -@display {label: "Files Response"} -public type FilesResponse record { - @display {label: "Kind"} - string kind; - @display {label: "Next Page Token"} - string nextPageToken?; - @display {label: "Incomplete Search"} - boolean incompleteSearch; - @display {label: "Array of Files"} - File[] files; -}; - -# File information -# -# + kind - Identifies what kind of resource is this. Value: the fixed string "drive#file". -# + id - The Id of the file -# + name - The name of the file -# + mimeType - The MIME type of the file -@display {label: "File"} -public type File record { - @display {label: "Kind"} - string kind; - @display {label: "Id"} - string id; - @display {label: "Name"} - string name; - @display {label: "Mime Type"} - string mimeType; -}; - # The metadata visibility # @display {label: "Metadata Visibility"} diff --git a/ballerina/utils.bal b/ballerina/utils.bal index 212fd28..6568b4e 100644 --- a/ballerina/utils.bal +++ b/ballerina/utils.bal @@ -83,22 +83,6 @@ isolated function getErrorMessage(http:Response response) returns error { return error(payload.toString()); } -# Get the drive url path to get a list of files. -# -# + pageToken - Token for retrieving next page (Optional) -# + return - drive url on success, else an error -isolated function prepareDriveUrl(string? pageToken = ()) returns string { - string drivePath; - if pageToken is string { - drivePath = DRIVE_PATH + FILES + QUESTION_MARK + Q + EQUAL + MIME_TYPE + EQUAL + APPLICATION + - AND_SIGN + TRASH_FALSE + AND + PAGE_TOKEN + EQUAL + pageToken; - return drivePath; - } - drivePath = DRIVE_PATH + FILES + QUESTION_MARK + Q + EQUAL + MIME_TYPE + EQUAL + APPLICATION + AND_SIGN + - TRASH_FALSE; - return drivePath; -} - # Create a random UUID removing the unnecessary hyphens which will interrupt querying opearations. # # + return - A string UUID without hyphens