Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
lua-basic-google-drive/lua-basic-google-drive/example.lua
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (36 sloc)
1.25 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local JSON = require 'json' | |
| local GDRIVE = require 'lua-basic-google-drive' | |
| local root = '/tmp/' | |
| local gdrive = GDRIVE.new{creds_file = root..'/creds.json', tokens_file = root..'/tokens.json'} | |
| work = function() | |
| print('-- initializing') | |
| gdrive:init() | |
| print('-- folder insertion') | |
| local file = {title = 'test', mimeType = gdrive.mimeType.folder} | |
| local folder = gdrive:insert({}, file) | |
| print(JSON.encode(folder)) | |
| print('-- file upload') | |
| local file = {title = 'test', mimeType = "text/plain", parents = {{id = folder.id}}} | |
| local ret = gdrive:upload({}, file, string.format('os.time() = %d', os.time())) | |
| print(JSON.encode(ret)) | |
| print('-- file listing') | |
| local ret = gdrive:list{ | |
| maxResults = 1, | |
| q = string.format("mimeType = '%s' and title = '%s' and '%s' in parents", 'text/plain', 'test', folder.id), | |
| } | |
| print(JSON.encode(ret)) | |
| print('-- file retrieval') | |
| local content, meta = gdrive:get({}, ret.items[1].id) | |
| print('File content: ' .. content) | |
| print('File metadata: ' .. JSON.encode(meta)) | |
| print('-- file deletion') | |
| gdrive:delete({}, ret.items[1].id) | |
| print('-- folder deletion') | |
| gdrive:delete({}, folder.id) | |
| end | |
| local status, err = pcall(work) | |
| if status then | |
| print('Operations completed successfully.') | |
| else | |
| print('Failure occurred: ' .. err) | |
| end |