Skip to content

Commit

Permalink
Remove the usage of google drive client
Browse files Browse the repository at this point in the history
  • Loading branch information
DimuthuMadushan committed Mar 4, 2024
1 parent 4c3c9f0 commit defe811
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 164 deletions.
11 changes: 0 additions & 11 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
#
Expand All @@ -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
Expand Down Expand Up @@ -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<File, error?>|error {
SpreadsheetStream spreadsheetStream = check new SpreadsheetStream(self.driveClient);
return new stream<File, error?>(spreadsheetStream);
}

# Renames the spreadsheet with the given name.
#
# + spreadsheetId - ID of the spreadsheet
Expand Down
12 changes: 0 additions & 12 deletions ballerina/constants.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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.";

Expand Down
5 changes: 0 additions & 5 deletions ballerina/data_mappings.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
58 changes: 0 additions & 58 deletions ballerina/stream_implementer.bal

This file was deleted.

19 changes: 1 addition & 18 deletions ballerina/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,9 @@ function testRenameSpreadsheet() {
}
}

@test:Config {
dependsOn: [testRenameSpreadsheet]
}
function testGetAllSpreadSheets() {
stream<File,error?>|error response = spreadsheetClient->getAllSpreadsheets();
if response is stream<File,error?> {
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);
Expand Down
44 changes: 0 additions & 44 deletions ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
16 changes: 0 additions & 16 deletions ballerina/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit defe811

Please sign in to comment.