Skip to content

Commit

Permalink
rename doc.getInfo to loadInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
theoephraim committed Feb 3, 2020
1 parent 1e63a36 commit 87812c3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
7 changes: 6 additions & 1 deletion docs/classes/google-spreadsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ Param|Type|Required|Description

### Basic info

#### `loadInfo()` (async) :id=fn-loadInfo
> Load basic document props and child sheets
- :sparkles: **Side Effects -** props are populated, sheets are populated

#### `updateProperties(props)` (async) :id=fn-updateProperties
> Update basic document properties
Expand All @@ -92,7 +97,7 @@ See [basic document properties](#basic-document-properties) above for props docu
#### `resetLocalCache()` :id=fn-resetLocalCache
> Clear local cache of properties and sheets
You must call `getInfo()` again to re-load the properties and sheets
You must call `loadInfo()` again to re-load the properties and sheets

- :sparkles: **Side Effects -** basic props and sheets are gone

Expand Down
8 changes: 4 additions & 4 deletions lib/GoogleSpreadsheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class GoogleSpreadsheet {
}

_ensureInfoLoaded() {
if (!this._rawProperties) throw new Error('You must call `sheet.getInfo()` before accessing this property');
if (!this._rawProperties) throw new Error('You must call `sheet.loadInfo()` before accessing this property');
}

_updateRawProperties(newProperties) { this._rawProperties = newProperties; }
Expand Down Expand Up @@ -200,7 +200,7 @@ class GoogleSpreadsheet {
}

// BASIC INFO ////////////////////////////////////////////////////////////////////////////////////
async getInfo(includeCells) {
async loadInfo(includeCells) {
const response = await this.axios.get('/', {
params: {
...includeCells && { includeGridData: true },
Expand All @@ -209,6 +209,7 @@ class GoogleSpreadsheet {
this._rawProperties = response.data.properties;
_.each(response.data.sheets, (s) => this._updateOrCreateSheet(s));
}
async getInfo() { return this.loadInfo(); } // alias to mimic old version

resetLocalCache() {
this._rawProperties = null;
Expand Down Expand Up @@ -248,8 +249,7 @@ class GoogleSpreadsheet {

return newSheet;
}
// just an alias to mimic old version of this module
async addWorksheet(properties) { return this.addSheet(properties); }
async addWorksheet(properties) { return this.addSheet(properties); } // alias to mimic old version

async deleteSheet(sheetId) {
// Request type = `deleteSheet`
Expand Down
2 changes: 1 addition & 1 deletion lib/GoogleSpreadsheetWorksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class GoogleSpreadsheetWorksheet {

_ensureInfoLoaded() {
if (!this._rawProperties) {
throw new Error('You must call `doc.getInfo()` again before accessing this property');
throw new Error('You must call `doc.loadInfo()` again before accessing this property');
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Theo Ephraim <[email protected]> (https://theoephraim.com)",
"name": "google-spreadsheet",
"description": "Google Sheets API (v4) -- simple interface to read/write data and manage sheets",
"version": "3.0.1",
"version": "3.0.2",
"license": "Unlicense",
"keywords": [
"google spreadsheets",
Expand Down
8 changes: 4 additions & 4 deletions test/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function checkDocAccess(docType, spec) {
describe(`Doc type = ${docType}`, () => {
if (spec.canRead) {
it('reading info should succeed', async () => {
await doc.getInfo();
await doc.loadInfo();
expect(doc.title).toBeTruthy();
sheet = doc.sheetsByIndex[0];
});
Expand All @@ -21,7 +21,7 @@ function checkDocAccess(docType, spec) {
});
} else {
it('reading info should fail', async () => {
await expect(doc.getInfo()).rejects.toThrow(spec.readError);
await expect(doc.loadInfo()).rejects.toThrow(spec.readError);
});
}

Expand All @@ -41,8 +41,8 @@ function checkDocAccess(docType, spec) {

describe('Authentication', () => {
describe('without setting auth', () => {
it('getInfo should fail on any doc', async () => {
await expect(docs.public.getInfo()).rejects.toThrow(
it('loadInfo should fail on any doc', async () => {
await expect(docs.public.loadInfo()).rejects.toThrow(
'initialize some kind of auth',
);
});
Expand Down
16 changes: 8 additions & 8 deletions test/manage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Managing doc info and sheets', () => {
});

it('can load the doc info', async () => {
await doc.getInfo();
await doc.loadInfo();
});

it('should include the document title', async () => {
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('Managing doc info and sheets', () => {

// make sure the update actually stuck
doc.resetLocalCache();
await doc.getInfo();
await doc.loadInfo();
expect(doc.title).toBe(newTitle);

// set the title back
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('Managing doc info and sheets', () => {

it('check the sheet is actually there', async () => {
doc.resetLocalCache();
await doc.getInfo(); // re-fetch
await doc.loadInfo(); // re-fetch
const newSheet = doc.sheetsByIndex.pop();
expect(newSheet.title).toBe(sheet.title);
expect(newSheet.rowCount).toBe(sheet.rowCount);
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('Managing doc info and sheets', () => {

// make sure the update actually stuck
sheet.resetLocalCache();
await doc.getInfo();
await doc.loadInfo();
expect(sheet.title).toBe(newTitle);
});

Expand All @@ -128,7 +128,7 @@ describe('Managing doc info and sheets', () => {
await sheet.resize({ rowCount: 77, columnCount: 44 });
expect(sheet.rowCount).toBe(77);
sheet.resetLocalCache();
await doc.getInfo();
await doc.loadInfo();
expect(sheet.rowCount).toBe(77);
});

Expand All @@ -147,7 +147,7 @@ describe('Managing doc info and sheets', () => {
let numSheets;

it('can remove a sheet', async () => {
await doc.getInfo();
await doc.loadInfo();
numSheets = doc.sheetsByIndex.length;

sheet = await doc.addWorksheet({
Expand All @@ -161,7 +161,7 @@ describe('Managing doc info and sheets', () => {

it('check the sheet is really gone', async () => {
doc.resetLocalCache();
await doc.getInfo();
await doc.loadInfo();
expect(doc.sheetsByIndex.length).toBe(numSheets);
});
});
Expand All @@ -188,7 +188,7 @@ describe('Managing doc info and sheets', () => {
await sheet.copyToSpreadsheet(docs.public.spreadsheetId);

await docs.public.useServiceAccountAuth(creds);
await docs.public.getInfo();
await docs.public.loadInfo();

// check title and content (header row)
const copiedSheet = docs.public.sheetsByIndex.splice(-1)[0];
Expand Down

0 comments on commit 87812c3

Please sign in to comment.