Modules@robinpath/google-drive
google-drive

@robinpath/google-drive

0.1.1Node.jsPublic

Google Drive module for RobinPath.

Google Drive

Google Drive module for RobinPath.

Package: @robinpath/google-drive | Category: Cloud Storage | Type: Integration

Authentication

googleDrive.setCredentials "ya29.xxx"

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the google-drive module when you need to:

  • List files in Google Drive with optional query filter. -- Use google-drive.listFiles to perform this operation
  • Get file metadata by ID. -- Use google-drive.getFile to perform this operation
  • Download file content as text. -- Use google-drive.downloadFile to perform this operation
  • Upload a file to Google Drive. -- Use google-drive.uploadFile to perform this operation
  • Create a new folder in Google Drive. -- Use google-drive.createFolder to perform this operation

Quick Reference

FunctionDescriptionReturns
setCredentialsSet the OAuth2 access token for Google Drive API.Confirmation message.
listFilesList files in Google Drive with optional query filter.Object with files array and nextPageToken.
getFileGet file metadata by ID.File metadata object.
downloadFileDownload file content as text.File content as text.
uploadFileUpload a file to Google Drive.Uploaded file metadata.
createFolderCreate a new folder in Google Drive.Created folder metadata.
deleteFilePermanently delete a file or folder.Confirmation message.
moveFileMove a file to a different folder.Updated file metadata.
copyFileCopy a file, optionally with a new name or destination.Copied file metadata.
shareFileShare a file with a user by email.Permission object.

Functions

setCredentials

Set the OAuth2 access token for Google Drive API.

Module: google-drive | Returns: string -- Confirmation message.

googleDrive.setCredentials "ya29.xxx"
ParameterTypeRequiredDescription
accessTokenstringYesOAuth2 access token

listFiles

List files in Google Drive with optional query filter.

Module: google-drive | Returns: object -- Object with files array and nextPageToken.

googleDrive.listFiles {"q":"mimeType='application/pdf'","pageSize":10}
ParameterTypeRequiredDescription
optionsobjectNoOptions: q (query), pageSize, pageToken, orderBy

getFile

Get file metadata by ID.

Module: google-drive | Returns: object -- File metadata object.

googleDrive.getFile "file-id"
ParameterTypeRequiredDescription
fileIdstringYesThe file ID

downloadFile

Download file content as text.

Module: google-drive | Returns: string -- File content as text.

googleDrive.downloadFile "file-id"
ParameterTypeRequiredDescription
fileIdstringYesThe file ID to download

uploadFile

Upload a file to Google Drive.

Module: google-drive | Returns: object -- Uploaded file metadata.

googleDrive.uploadFile "report.txt" "Hello world" {"folderId":"folder-id"}
ParameterTypeRequiredDescription
namestringYesFile name
contentstringYesFile content
optionsobjectNoOptions: mimeType, folderId

createFolder

Create a new folder in Google Drive.

Module: google-drive | Returns: object -- Created folder metadata.

googleDrive.createFolder "My Folder"
ParameterTypeRequiredDescription
namestringYesFolder name
parentIdstringNoParent folder ID (optional)

deleteFile

Permanently delete a file or folder.

Module: google-drive | Returns: string -- Confirmation message.

googleDrive.deleteFile "file-id"
ParameterTypeRequiredDescription
fileIdstringYesThe file/folder ID to delete

moveFile

Move a file to a different folder.

Module: google-drive | Returns: object -- Updated file metadata.

googleDrive.moveFile "file-id" "folder-id"
ParameterTypeRequiredDescription
fileIdstringYesThe file ID to move
newFolderIdstringYesDestination folder ID

copyFile

Copy a file, optionally with a new name or destination.

Module: google-drive | Returns: object -- Copied file metadata.

googleDrive.copyFile "file-id" {"name":"Copy of Report"}
ParameterTypeRequiredDescription
fileIdstringYesThe file ID to copy
optionsobjectNoOptions: name, folderId

shareFile

Share a file with a user by email.

Module: google-drive | Returns: object -- Permission object.

googleDrive.shareFile "file-id" "user@example.com" "writer"
ParameterTypeRequiredDescription
fileIdstringYesThe file ID to share
emailstringYesEmail of the user to share with
rolestringNoPermission role: reader, writer, commenter (default: reader)

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Google Drive: token not configured. Call googleDrive.setCredentials first.Check the error message for details
Google Drive API error (${res.status}): ${text}Check the error message for details
googleDrive.setCredentials requires an access token.Check the error message for details
googleDrive.getFile requires a fileId.Check the error message for details
googleDrive.downloadFile requires a fileId.Check the error message for details
Google Drive download error (${res.status}): ${text}Check the error message for details
googleDrive.uploadFile requires name and content.Check the error message for details
Google Drive upload error (${res.status}): ${text}Check the error message for details
@desc "List files and validate result"
do
  set $result as googleDrive.listFiles {"q":"mimeType='application/pdf'","pageSize":10}
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Files

Retrieve all items and loop through them.

@desc "List files and iterate results"
do
  google-drive.setCredentials $token
  set $result as googleDrive.listFiles {"q":"mimeType='application/pdf'","pageSize":10}
  each $item in $result
    print $item
  end
enddo

2. Create a new item with createFolder

Create a new resource and capture the result.

@desc "Create folder"
do
  google-drive.setCredentials $token
  set $result as googleDrive.createFolder "My Folder"
  print "Created: " + $result
enddo

3. Check before creating

List existing items and only create if needed.

@desc "List files and create folder"
do
  google-drive.setCredentials $token
  set $existing as googleDrive.listFiles {"q":"mimeType='application/pdf'","pageSize":10}
  if $existing == null
    googleDrive.createFolder "My Folder"
    print "Item created"
  else
    print "Item already exists"
  end
enddo

4. Multi-step Google Drive workflow

Chain multiple google-drive operations together.

@desc "List files, get file, and more"
do
  google-drive.setCredentials $token
  set $r_listFiles as googleDrive.listFiles {"q":"mimeType='application/pdf'","pageSize":10}
  set $r_getFile as googleDrive.getFile "file-id"
  set $r_downloadFile as googleDrive.downloadFile "file-id"
  print "All operations complete"
enddo

5. Safe listFiles with validation

Check results before proceeding.

@desc "List files and validate result"
do
  google-drive.setCredentials $token
  set $result as googleDrive.listFiles {"q":"mimeType='application/pdf'","pageSize":10}
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • s3 -- Amazon S3 module for complementary functionality
  • dropbox -- Dropbox module for complementary functionality
  • box -- Box module for complementary functionality
  • onedrive -- OneDrive module for complementary functionality
  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/google-drive

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size5.8 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Category

devops