Skip to content

Commit

Permalink
improve docs; test that drive API still works by comparing drive.x.ab…
Browse files Browse the repository at this point in the history
…outMe with drive.about.get
  • Loading branch information
DrPaulBrewer committed Oct 13, 2017
1 parent 582a652 commit 26c4ca7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ is deleted when a user uninstalls or deletes your app.

### Store a string in the appDataFolder

Once initialized, this snippet will store a string in the file `myaccount` in the `appDataFolder`
Once initialized, this snippet will store a string in the file `myaccount` in the `appDataFolder`.

const str = require('string-to-stream');
const secrets = 'some-encrypted-string-of-secrets';

Expand All @@ -77,7 +77,16 @@ Once initialized, this snippet will store a string in the file `myaccount` in th
createPath: false,
clobber: true
}).then((newFileMetadata)=>{...}).catch((e)=>{...})

upload2 uses a resumable upload.

A [media upload](https://developers.google.com/drive/v3/web/manage-uploads) using `drive.files.create` directly from the unextended drive googleapi might be quicker for short files up to 5MB.

`drive.files.create` media upload requires having the `folder.Id` of the `parent` folder for the new file, here it is simply `appDataFolder`. Also setting `spaces` to `appDataFolder` is required.

In `drive.x.appDataFolder.upload2` these steps are included but are used in a 2-step procedure to first request an upload URL, and then do an upload.


### upload a file to the user's Drive via resumable upload

To upload a local file, a stream is required, so call node's `fs.createReadStream('/path/to/local/files')`.
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"string-to-stream": "^1.1.0"
},
"dependencies": {
"boom": "^6.0.0",
"p-reduce": "^1.0.0",
"pify": "^3.0.0"
"boom": "^6.0.0",
"pify": "^3.0.0",
"p-reduce": "^1.0.0"
}
}
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const request = require('request');
const fs = require('fs');
const str = require('string-to-stream');
const Boom = require('boom');
const pify = require('pify');

const keys = {
key: process.env.GOOGLE_DRIVE_CLIENT_ID,
Expand Down Expand Up @@ -51,6 +52,14 @@ describe('decorated-google-drive:', function(){
quota.should.have.properties('limit','usage');
});
});
it('drive.about.get still works, as well, and the outputs match', function(){
return Promise.all([
drive.x.aboutMe(),
pify(drive.about.get)({fields: 'user, storageQuota'})
]).then(([A,B])=>{
A.should.deepEqual(B);
});
});
});
describe(' drive.x.appDataFolder.upload2: upload a string to appDataFolder ', function(){
let uploadResult;
Expand Down
23 changes: 12 additions & 11 deletions testResults.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@
initializing
✓ should not throw an error
drive.x.aboutMe
✓ should return the test users email address (583ms)
✓ should return a storageQuota object with properties limit, usage (178ms)
✓ should return the test users email address (416ms)
✓ should return a storageQuota object with properties limit, usage (169ms)
✓ drive.about.get still works, as well, and the outputs match (173ms)
drive.x.appDataFolder.upload2: upload a string to appDataFolder
✓ uploading the string to appDataFolder file myaccount should resolve with expected file metadata
✓ drive.x.appDataFolder.searcher should report there is exactly one myaccount file in the folder and it should match upload file id
✓ drive.x.appDataFolder.contents should resolve to contents Hello-World-Test-1-2-3
drive.x.upload2: upload a file README.md to Drive folder /path/to/test/Files
✓ uploading the README.md file to /path/to/test/Files/README.md should resolve with expected file metadata
after drive.x.upload2
✓ checking existence with drive.x.findPath should yield expected file metadata (1016ms)
✓ checking existence on wrong path should throw Boom.notfound (200ms)
✓ downloading content with drive.x.download should yield contents string including 'License: MIT' (1319ms)
✓ drive.x.upload2 uploading the file again with {clobber:false} will throw Boom.conflict error because file already exists (1026ms)
✓ checking existence with drive.x.findPath should yield expected file metadata (1127ms)
✓ checking existence on wrong path should throw Boom.notfound (187ms)
✓ downloading content with drive.x.download should yield contents string including 'License: MIT' (1285ms)
✓ drive.x.upload2 uploading the file again with {clobber:false} will throw Boom.conflict error because file already exists (1123ms)
cleanup via drive.x.janitor
✓ janitor hopefully deletes the README.md file(s) OK and resolves correctly (1457ms)
✓ drive.x.findPath will throw Boom.notFound if the file was successfully deleted (1087ms)
✓ janitor will throw an error if told to delete an invalid file (147ms)
✓ janitor hopefully deletes the README.md file(s) OK and resolves correctly (1445ms)
✓ drive.x.findPath will throw Boom.notFound if the file was successfully deleted (1145ms)
✓ janitor will throw an error if told to delete an invalid file (146ms)
✓ janitor should not throw an error if given an empty filelist
✓ final cleanup: delete the path folder and check non-existence (974ms)
✓ final cleanup: delete the path folder and check non-existence (1227ms)


16 passing (14s)
17 passing (14s)

0 comments on commit 26c4ca7

Please sign in to comment.